Skip to content

Commit

Permalink
Merge pull request #84 from scc-digitalhub/entity-owners
Browse files Browse the repository at this point in the history
Entity owners
  • Loading branch information
matteo-s authored Apr 9, 2024
2 parents 5dabf59 + 92eaac9 commit 705cb64
Show file tree
Hide file tree
Showing 110 changed files with 545 additions and 812 deletions.
3 changes: 1 addition & 2 deletions application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
Expand Down Expand Up @@ -268,7 +267,7 @@
<layers>
<enabled>true</enabled>
<configuration>${project.basedir}/src/main/layers.xml</configuration>
</layers>
</layers>
<mainClass>it.smartcommunitylabdhub.core.CoreApplication</mainClass>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication(scanBasePackages = { "it.smartcommunitylabdhub" })
@EnableJpaAuditing
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
@ComponentScan(basePackages = { "it.smartcommunitylabdhub" })
public class CoreApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import it.smartcommunitylabdhub.commons.services.entities.RunService;
import it.smartcommunitylabdhub.commons.utils.MapUtils;
import it.smartcommunitylabdhub.core.components.infrastructure.factories.runtimes.RuntimeFactory;
import it.smartcommunitylabdhub.core.models.entities.function.FunctionEntity;
import it.smartcommunitylabdhub.core.models.entities.run.RunEntity;
import it.smartcommunitylabdhub.core.models.entities.task.TaskEntity;
import it.smartcommunitylabdhub.core.models.entities.FunctionEntity;
import it.smartcommunitylabdhub.core.models.entities.RunEntity;
import it.smartcommunitylabdhub.core.models.entities.TaskEntity;
import it.smartcommunitylabdhub.core.models.queries.specifications.CommonSpecification;
import it.smartcommunitylabdhub.core.services.EntityService;
import it.smartcommunitylabdhub.fsm.Fsm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package it.smartcommunitylabdhub.core.components.solr;

import java.util.Date;

import org.apache.solr.common.SolrInputDocument;

import it.smartcommunitylabdhub.commons.models.entities.artifact.Artifact;
import it.smartcommunitylabdhub.commons.models.entities.artifact.ArtifactMetadata;
import it.smartcommunitylabdhub.commons.models.entities.dataitem.DataItem;
import it.smartcommunitylabdhub.commons.models.entities.dataitem.DataItemMetadata;
import it.smartcommunitylabdhub.commons.models.entities.function.Function;
import it.smartcommunitylabdhub.commons.models.entities.function.FunctionMetadata;
import it.smartcommunitylabdhub.commons.models.enums.EntityName;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import org.apache.solr.common.SolrInputDocument;

@Slf4j
public class SolrBaseEntityParser {

public static String getKeyGroup(String kind, String project, String name) {
return kind + "_" + project + "_" + name;
}
Expand All @@ -38,10 +36,10 @@ public static SolrInputDocument parser(DataItem item, DataItemMetadata metadata)
doc.addField("metadata.labels", metadata.getLabels());
try {
doc.addField("metadata.created", Date.from(metadata.getCreated().toInstant()));
doc.addField("metadata.updated", Date.from(metadata.getUpdated().toInstant()));
} catch (Exception e) {
SolrBaseEntityParser.log.warn("parser DataItem:" + e.getMessage());
}
doc.addField("metadata.updated", Date.from(metadata.getUpdated().toInstant()));
} catch (Exception e) {
SolrBaseEntityParser.log.warn("parser DataItem:" + e.getMessage());
}

return doc;
}
Expand All @@ -64,10 +62,10 @@ public static SolrInputDocument parser(Function item, FunctionMetadata metadata)
doc.addField("metadata.labels", metadata.getLabels());
try {
doc.addField("metadata.created", Date.from(metadata.getCreated().toInstant()));
doc.addField("metadata.updated", Date.from(metadata.getUpdated().toInstant()));
} catch (Exception e) {
SolrBaseEntityParser.log.warn("parser Function:" + e.getMessage());
}
doc.addField("metadata.updated", Date.from(metadata.getUpdated().toInstant()));
} catch (Exception e) {
SolrBaseEntityParser.log.warn("parser Function:" + e.getMessage());
}

return doc;
}
Expand All @@ -90,10 +88,10 @@ public static SolrInputDocument parser(Artifact item, ArtifactMetadata metadata)
doc.addField("metadata.labels", metadata.getLabels());
try {
doc.addField("metadata.created", Date.from(metadata.getCreated().toInstant()));
doc.addField("metadata.updated", Date.from(metadata.getUpdated().toInstant()));
} catch (Exception e) {
SolrBaseEntityParser.log.warn("parser Artifact:" + e.getMessage());
}
doc.addField("metadata.updated", Date.from(metadata.getUpdated().toInstant()));
} catch (Exception e) {
SolrBaseEntityParser.log.warn("parser Artifact:" + e.getMessage());
}

return doc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import it.smartcommunitylabdhub.commons.models.entities.secret.Secret;
import it.smartcommunitylabdhub.commons.models.entities.task.Task;
import it.smartcommunitylabdhub.commons.models.entities.workflow.Workflow;
import it.smartcommunitylabdhub.core.models.entities.artifact.ArtifactEntity;
import it.smartcommunitylabdhub.core.models.entities.dataitem.DataItemEntity;
import it.smartcommunitylabdhub.core.models.entities.function.FunctionEntity;
import it.smartcommunitylabdhub.core.models.entities.log.LogEntity;
import it.smartcommunitylabdhub.core.models.entities.project.ProjectEntity;
import it.smartcommunitylabdhub.core.models.entities.run.RunEntity;
import it.smartcommunitylabdhub.core.models.entities.secret.SecretEntity;
import it.smartcommunitylabdhub.core.models.entities.task.TaskEntity;
import it.smartcommunitylabdhub.core.models.entities.workflow.WorkflowEntity;
import it.smartcommunitylabdhub.core.models.entities.ArtifactEntity;
import it.smartcommunitylabdhub.core.models.entities.DataItemEntity;
import it.smartcommunitylabdhub.core.models.entities.FunctionEntity;
import it.smartcommunitylabdhub.core.models.entities.LogEntity;
import it.smartcommunitylabdhub.core.models.entities.ProjectEntity;
import it.smartcommunitylabdhub.core.models.entities.RunEntity;
import it.smartcommunitylabdhub.core.models.entities.SecretEntity;
import it.smartcommunitylabdhub.core.models.entities.TaskEntity;
import it.smartcommunitylabdhub.core.models.entities.WorkflowEntity;
import it.smartcommunitylabdhub.core.repositories.ArtifactRepository;
import it.smartcommunitylabdhub.core.repositories.DataItemRepository;
import it.smartcommunitylabdhub.core.repositories.FunctionRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
// @Configuration
public class RequestLoggingConfig {

@Bean
public RequestLoggingFilter requestLoggingFilter() {
return new RequestLoggingFilter();
}
//DISABLED, wraps requests and breaks stuff!
// @Bean
// public RequestLoggingFilter requestLoggingFilter() {
// return new RequestLoggingFilter();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
Expand Down Expand Up @@ -95,9 +98,15 @@ public SecurityFilterChain apiSecurityFilterChain(HttpSecurity http) throws Exce
)
);
}

//disable anonymous
securityChain.anonymous(anon -> anon.disable());
} else {
//assign both USER and ADMIN to anon user to bypass all scoped permission checks
securityChain.anonymous(anon -> anon.authorities("ROLE_USER", "ROLE_ADMIN"));
securityChain.anonymous(anon -> {
anon.authorities("ROLE_USER", "ROLE_ADMIN");
anon.principal("anonymous");
});
}

securityChain.exceptionHandling(handling -> {
Expand Down Expand Up @@ -167,6 +176,22 @@ private JwtAuthenticationConverter jwtAuthenticationConverter() {
return converter;
}

@Bean("h2SecurityFilterChain")
public SecurityFilterChain h2SecurityFilterChain(HttpSecurity http) throws Exception {
return http
.securityMatcher(new AntPathRequestMatcher("/h2-console/**"))
.authorizeHttpRequests(auth -> {
auth.anyRequest().permitAll();
})
//disable csrf
.csrf(csrf -> csrf.disable())
// we don't want a session for these endpoints, each request should be evaluated
.sessionManagement(management -> management.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
// enable frame options
.headers(headers -> headers.frameOptions(frame -> frame.sameOrigin()))
.build();
}

@Bean("coreSecurityFilterChain")
public SecurityFilterChain coreSecurityFilterChain(HttpSecurity http) throws Exception {
return http
Expand Down Expand Up @@ -209,4 +234,9 @@ private CorsConfigurationSource corsConfigurationSource(String origins) {
source.registerCorsConfiguration("/**", configuration);
return source;
}

@Bean
AuditorAware<String> auditorProvider() {
return () -> Optional.of(SecurityContextHolder.getContext().getAuthentication().getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.smartcommunitylabdhub.commons.models.queries.SearchFilter;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.artifact.ArtifactEntity;
import it.smartcommunitylabdhub.core.models.entities.ArtifactEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.ArtifactEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableArtifactService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.smartcommunitylabdhub.commons.models.queries.SearchFilter;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.dataitem.DataItemEntity;
import it.smartcommunitylabdhub.core.models.entities.DataItemEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.DataItemEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableDataItemService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.smartcommunitylabdhub.commons.models.queries.SearchFilter;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.function.FunctionEntity;
import it.smartcommunitylabdhub.core.models.entities.FunctionEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.FunctionEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableFunctionService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.smartcommunitylabdhub.commons.models.queries.SearchFilter;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.project.ProjectEntity;
import it.smartcommunitylabdhub.core.models.entities.ProjectEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.ProjectEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableProjectService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.components.run.RunManager;
import it.smartcommunitylabdhub.core.models.entities.run.RunEntity;
import it.smartcommunitylabdhub.core.models.entities.RunEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.RunEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableRunService;
import it.smartcommunitylabdhub.fsm.exceptions.InvalidTransactionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import it.smartcommunitylabdhub.core.models.builders.artifact.ArtifactDTOBuilder;
import it.smartcommunitylabdhub.core.models.builders.dataitem.DataItemDTOBuilder;
import it.smartcommunitylabdhub.core.models.builders.function.FunctionDTOBuilder;
import it.smartcommunitylabdhub.core.models.entities.artifact.ArtifactEntity;
import it.smartcommunitylabdhub.core.models.entities.dataitem.DataItemEntity;
import it.smartcommunitylabdhub.core.models.entities.function.FunctionEntity;
import it.smartcommunitylabdhub.core.models.entities.ArtifactEntity;
import it.smartcommunitylabdhub.core.models.entities.DataItemEntity;
import it.smartcommunitylabdhub.core.models.entities.FunctionEntity;
import it.smartcommunitylabdhub.core.repositories.ArtifactRepository;
import it.smartcommunitylabdhub.core.repositories.DataItemRepository;
import it.smartcommunitylabdhub.core.repositories.FunctionRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.smartcommunitylabdhub.commons.models.queries.SearchFilter;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.task.TaskEntity;
import it.smartcommunitylabdhub.core.models.entities.TaskEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.TaskEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableTaskService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.smartcommunitylabdhub.commons.models.queries.SearchFilter;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.workflow.WorkflowEntity;
import it.smartcommunitylabdhub.core.models.entities.WorkflowEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.WorkflowEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableWorkflowService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.smartcommunitylabdhub.commons.models.queries.SearchFilter;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.artifact.ArtifactEntity;
import it.smartcommunitylabdhub.core.models.entities.ArtifactEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.ArtifactEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableArtifactService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.smartcommunitylabdhub.commons.models.queries.SearchFilter;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.dataitem.DataItemEntity;
import it.smartcommunitylabdhub.core.models.entities.DataItemEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.DataItemEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableDataItemService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import it.smartcommunitylabdhub.commons.services.entities.TaskService;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.function.FunctionEntity;
import it.smartcommunitylabdhub.core.models.entities.FunctionEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.FunctionEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableFunctionService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.components.run.RunManager;
import it.smartcommunitylabdhub.core.models.entities.run.RunEntity;
import it.smartcommunitylabdhub.core.models.entities.RunEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.RunEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableRunService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import it.smartcommunitylabdhub.commons.services.entities.RunService;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.task.TaskEntity;
import it.smartcommunitylabdhub.core.models.entities.TaskEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.TaskEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableTaskService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.smartcommunitylabdhub.commons.models.queries.SearchFilter;
import it.smartcommunitylabdhub.core.ApplicationKeys;
import it.smartcommunitylabdhub.core.annotations.ApiVersion;
import it.smartcommunitylabdhub.core.models.entities.workflow.WorkflowEntity;
import it.smartcommunitylabdhub.core.models.entities.WorkflowEntity;
import it.smartcommunitylabdhub.core.models.queries.filters.entities.WorkflowEntityFilter;
import it.smartcommunitylabdhub.core.models.queries.services.SearchableWorkflowService;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public interface BaseEntity extends Serializable {

void setStatus(byte[] status);

byte[] getExtra();

void setExtra(byte[] extra);

State getState();

void setState(State state);

Date getCreated();

Date getUpdated();

String getCreatedBy();

String getUpdatedBy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import it.smartcommunitylabdhub.commons.models.entities.artifact.Artifact;
import it.smartcommunitylabdhub.commons.models.entities.artifact.ArtifactMetadata;
import it.smartcommunitylabdhub.commons.utils.MapUtils;
import it.smartcommunitylabdhub.core.models.entities.artifact.ArtifactEntity;
import it.smartcommunitylabdhub.core.models.entities.ArtifactEntity;
import jakarta.persistence.AttributeConverter;
import java.io.Serializable;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -58,9 +58,9 @@ public Artifact build(ArtifactEntity entity) {
.name(entity.getName())
.kind(entity.getKind())
.project(entity.getProject())
.user(entity.getCreatedBy())
.metadata(MapUtils.mergeMultipleMaps(meta, metadata.toMap()))
.spec(converter.convertToEntityAttribute(entity.getSpec()))
.extra(converter.convertToEntityAttribute(entity.getExtra()))
.status(
MapUtils.mergeMultipleMaps(
converter.convertToEntityAttribute(entity.getStatus()),
Expand Down
Loading

0 comments on commit 705cb64

Please sign in to comment.