From e7a6bf9a06b6895ad32c60e0f61f9e818ff3722f Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Fri, 22 Dec 2023 11:57:10 +0100 Subject: [PATCH 1/8] [Upgrade] Upgrade to java 17 --- build.gradle | 12 +++-- .../kbss/analysis/config/JacksonConfig.java | 2 + .../kbss/analysis/config/SecurityConfig.java | 52 +++++++++++-------- .../FailureModesTableController.java | 2 +- .../controller/util/RestExceptionHandler.java | 4 +- .../cz/cvut/kbss/analysis/model/Behavior.java | 2 +- .../cvut/kbss/analysis/model/Component.java | 2 +- .../kbss/analysis/model/FailureModesRow.java | 2 +- .../cvut/kbss/analysis/model/FaultTree.java | 4 +- .../cvut/kbss/analysis/model/Mitigation.java | 2 +- .../analysis/model/RiskPriorityNumber.java | 4 +- .../cz/cvut/kbss/analysis/model/System.java | 2 +- .../cz/cvut/kbss/analysis/model/User.java | 2 +- .../persistence/MainPersistenceFactory.java | 7 +-- .../analysis/security/JwtTokenFilter.java | 12 ++--- .../analysis/service/JwtTokenProvider.java | 2 +- 16 files changed, 62 insertions(+), 51 deletions(-) diff --git a/build.gradle b/build.gradle index 5d2e8d35..7d187978 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { } plugins { - id 'org.springframework.boot' version '2.7.17' + id 'org.springframework.boot' version '3.1.5' id 'io.spring.dependency-management' version '1.1.3' id 'io.freefair.aspectj.post-compile-weaving' version '8.4' id 'java' @@ -19,8 +19,8 @@ group = 'cz.cvut.kbss.analysis' version = '0.0.1-SNAPSHOT' compileJava { - sourceCompatibility = '11' - targetCompatibility = '11' + sourceCompatibility = '17' + targetCompatibility = '17' } repositories { @@ -49,10 +49,12 @@ dependencies { implementation 'com.fasterxml:classmate:1.5.0' implementation 'com.opencsv:opencsv:5.3' - implementation 'org.projectlombok:lombok:1.18.12' - annotationProcessor 'org.projectlombok:lombok:1.18.12' + implementation 'org.projectlombok:lombok:1.18.30' + annotationProcessor 'org.projectlombok:lombok:1.18.30' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' + providedRuntime 'jakarta.servlet:jakarta.servlet-api' + implementation 'javax.xml.bind:jaxb-api:2.3.1' // needed for java 17 aspect 'cz.cvut.kbss.jopa:jopa-impl:1.1.4' diff --git a/src/main/java/cz/cvut/kbss/analysis/config/JacksonConfig.java b/src/main/java/cz/cvut/kbss/analysis/config/JacksonConfig.java index 0d56ec6d..1590704e 100755 --- a/src/main/java/cz/cvut/kbss/analysis/config/JacksonConfig.java +++ b/src/main/java/cz/cvut/kbss/analysis/config/JacksonConfig.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import cz.cvut.kbss.jsonld.ConfigParam; import cz.cvut.kbss.jsonld.jackson.JsonLdModule; +import cz.cvut.kbss.jsonld.jackson.serialization.SerializationConstants; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,6 +17,7 @@ public ObjectMapper objectMapper() { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonLdModule m = new JsonLdModule(); m.configure(ConfigParam.SCAN_PACKAGE, "cz.cvut.kbss.analysis"); + m.configure(SerializationConstants.FORM, SerializationConstants.FORM_COMPACT_WITH_CONTEXT); mapper.registerModule(m); return mapper; } diff --git a/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java b/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java index a2d52fb3..8f45670d 100755 --- a/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java +++ b/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java @@ -3,14 +3,18 @@ import cz.cvut.kbss.analysis.security.JwtConfigurer; import cz.cvut.kbss.analysis.service.JwtTokenProvider; import cz.cvut.kbss.analysis.service.security.SecurityUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; @@ -18,8 +22,10 @@ import java.util.Arrays; @Configuration -@EnableGlobalMethodSecurity(prePostEnabled = true) -public class SecurityConfig extends WebSecurityConfigurerAdapter { +@EnableWebSecurity +@Slf4j +@EnableMethodSecurity(prePostEnabled = true) +public class SecurityConfig { private final JwtTokenProvider jwtTokenProvider; private final SecurityUtils securityUtils; @@ -31,13 +37,13 @@ public SecurityConfig(JwtTokenProvider jwtTokenProvider, SecurityUtils securityU } @Bean - @Override - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); + public AuthenticationManager buildAuthenticationManager(HttpSecurity http) throws Exception { + final AuthenticationManagerBuilder ab = http.getSharedObject(AuthenticationManagerBuilder.class); + return ab.build(); } - @Bean - CorsConfigurationSource corsConfigurationSource() { + protected CorsConfigurationSource corsConfigurationSource() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration corsConfiguration = new CorsConfiguration(); @@ -49,20 +55,22 @@ CorsConfigurationSource corsConfigurationSource() { return source; } - @Override - protected void configure(HttpSecurity http) throws Exception { + + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + log.debug("Using internal security mechanisms."); + final AuthenticationManager authManager = buildAuthenticationManager(http); http - .cors() - .and() - .httpBasic().disable() - .csrf().disable() - .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .authorizeRequests() - .antMatchers("/auth/register").permitAll() - .antMatchers("/auth/signin").permitAll() - .anyRequest().authenticated() - .and() +// .requestMatcher(r -> false) + .cors(auth -> auth.configurationSource(corsConfigurationSource())) + .httpBasic(basic -> basic.disable()) + .csrf(csrf -> csrf.disable()) + .sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .authorizeHttpRequests(auth -> auth + .requestMatchers(AntPathRequestMatcher.antMatcher("/auth/register")).permitAll() + .requestMatchers(AntPathRequestMatcher.antMatcher("/auth/signin")).permitAll() + .anyRequest().authenticated()) .apply(new JwtConfigurer(jwtTokenProvider, securityUtils)); + return http.build(); } } \ No newline at end of file diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/FailureModesTableController.java b/src/main/java/cz/cvut/kbss/analysis/controller/FailureModesTableController.java index 6b9da4cb..d76ba5a2 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/FailureModesTableController.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/FailureModesTableController.java @@ -14,7 +14,7 @@ import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.net.URI; import java.util.List; diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java b/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java index ae338f05..9b5243cc 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java @@ -4,6 +4,7 @@ import cz.cvut.kbss.analysis.exception.EntityNotFoundException; import cz.cvut.kbss.analysis.exception.LogicViolationException; import cz.cvut.kbss.analysis.exception.ValidationException; +import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.http.HttpStatus; @@ -12,9 +13,6 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; -import javax.servlet.http.HttpServletRequest; -import javax.validation.ConstraintViolation; -import javax.validation.ConstraintViolationException; import java.util.stream.Collectors; @RestControllerAdvice diff --git a/src/main/java/cz/cvut/kbss/analysis/model/Behavior.java b/src/main/java/cz/cvut/kbss/analysis/model/Behavior.java index c69ddf58..94c3f892 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/Behavior.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/Behavior.java @@ -6,7 +6,7 @@ import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/cz/cvut/kbss/analysis/model/Component.java b/src/main/java/cz/cvut/kbss/analysis/model/Component.java index f60e8329..eb0b712a 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/Component.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/Component.java @@ -5,7 +5,7 @@ import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; import java.net.URI; import java.util.HashSet; import java.util.Objects; diff --git a/src/main/java/cz/cvut/kbss/analysis/model/FailureModesRow.java b/src/main/java/cz/cvut/kbss/analysis/model/FailureModesRow.java index 3d01ff35..7298bafb 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/FailureModesRow.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/FailureModesRow.java @@ -6,7 +6,7 @@ import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import java.net.URI; import java.util.Objects; import java.util.Set; diff --git a/src/main/java/cz/cvut/kbss/analysis/model/FaultTree.java b/src/main/java/cz/cvut/kbss/analysis/model/FaultTree.java index 35b6c7a5..2b619198 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/FaultTree.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/FaultTree.java @@ -6,8 +6,8 @@ import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import java.util.HashSet; import java.util.Objects; import java.util.Set; diff --git a/src/main/java/cz/cvut/kbss/analysis/model/Mitigation.java b/src/main/java/cz/cvut/kbss/analysis/model/Mitigation.java index 35914338..2f4c1c0d 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/Mitigation.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/Mitigation.java @@ -9,7 +9,7 @@ import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; import java.util.Objects; @OWLClass(iri = Vocabulary.s_c_Mitigation) diff --git a/src/main/java/cz/cvut/kbss/analysis/model/RiskPriorityNumber.java b/src/main/java/cz/cvut/kbss/analysis/model/RiskPriorityNumber.java index 9ca6bcb6..a5c97e0e 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/RiskPriorityNumber.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/RiskPriorityNumber.java @@ -8,8 +8,8 @@ import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Objects; diff --git a/src/main/java/cz/cvut/kbss/analysis/model/System.java b/src/main/java/cz/cvut/kbss/analysis/model/System.java index 183e4132..d61f9053 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/System.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/System.java @@ -5,7 +5,7 @@ import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; import java.util.HashSet; import java.util.Objects; import java.util.Set; diff --git a/src/main/java/cz/cvut/kbss/analysis/model/User.java b/src/main/java/cz/cvut/kbss/analysis/model/User.java index a9c4bb85..962a2aa1 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/User.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/User.java @@ -11,7 +11,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; import java.util.*; import static java.util.stream.Collectors.toList; diff --git a/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java b/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java index d3e6c329..981b424a 100755 --- a/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java +++ b/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java @@ -4,6 +4,7 @@ import cz.cvut.kbss.analysis.config.conf.RepositoryConf; import cz.cvut.kbss.jopa.Persistence; import cz.cvut.kbss.jopa.model.EntityManagerFactory; +import cz.cvut.kbss.jopa.model.JOPAPersistenceProperties; import cz.cvut.kbss.jopa.model.JOPAPersistenceProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -11,8 +12,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import java.util.HashMap; import java.util.Map; @@ -66,7 +67,7 @@ private void init() { properties.put(ONTOLOGY_PHYSICAL_URI_KEY, repositoryConf.getUrl()); properties.put(DATA_SOURCE_CLASS, persistenceConf.getDriver()); properties.put(LANG, persistenceConf.getLanguage()); - properties.put(CACHE_ENABLED, "false"); +// properties.put(CACHE_ENABLED, Boolean.FALSE.toString()); if(repositoryConf.getUsername() != null && repositoryConf.getPassword() != null) { properties.put(DATA_SOURCE_USERNAME, repositoryConf.getUsername()); diff --git a/src/main/java/cz/cvut/kbss/analysis/security/JwtTokenFilter.java b/src/main/java/cz/cvut/kbss/analysis/security/JwtTokenFilter.java index 17e32feb..cc4b3cf3 100755 --- a/src/main/java/cz/cvut/kbss/analysis/security/JwtTokenFilter.java +++ b/src/main/java/cz/cvut/kbss/analysis/security/JwtTokenFilter.java @@ -10,12 +10,12 @@ import org.springframework.security.web.header.HeaderWriterFilter; import org.springframework.web.filter.GenericFilterBean; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; @Slf4j diff --git a/src/main/java/cz/cvut/kbss/analysis/service/JwtTokenProvider.java b/src/main/java/cz/cvut/kbss/analysis/service/JwtTokenProvider.java index 6293ec91..79581121 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/JwtTokenProvider.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/JwtTokenProvider.java @@ -12,7 +12,7 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.stereotype.Component; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import java.util.Date; import java.util.List; From 89238939dae1ad8bf8d9d73af15784e5c7667b52 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Fri, 22 Dec 2023 12:01:09 +0100 Subject: [PATCH 2/8] [Upgrade] Upgrade tests to java 17 --- .../kbss/analysis/environment/TestPersistenceFactory.java | 4 ++-- .../analysis/service/validation/FaultEventValidatorTest.java | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/test/java/cz/cvut/kbss/analysis/environment/TestPersistenceFactory.java b/src/test/java/cz/cvut/kbss/analysis/environment/TestPersistenceFactory.java index 4f051436..99686224 100755 --- a/src/test/java/cz/cvut/kbss/analysis/environment/TestPersistenceFactory.java +++ b/src/test/java/cz/cvut/kbss/analysis/environment/TestPersistenceFactory.java @@ -14,8 +14,8 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import java.util.HashMap; import java.util.Map; diff --git a/src/test/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidatorTest.java b/src/test/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidatorTest.java index ee201ecd..89baac7a 100755 --- a/src/test/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidatorTest.java +++ b/src/test/java/cz/cvut/kbss/analysis/service/validation/FaultEventValidatorTest.java @@ -17,9 +17,6 @@ import org.springframework.validation.BindingResult; import org.springframework.validation.beanvalidation.SpringValidatorAdapter; -import javax.xml.validation.Validator; - -import static org.junit.jupiter.api.Assertions.assertThrows; class FaultEventValidatorTest { From f3498889e9c3ccb3d4c6be4e714073da72bed164 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Fri, 22 Dec 2023 13:16:22 +0100 Subject: [PATCH 3/8] [Upgrade] Refactor remaining javax packages to jakarta --- .../java/cz/cvut/kbss/analysis/model/FailureModesTable.java | 6 +++--- src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/model/FailureModesTable.java b/src/main/java/cz/cvut/kbss/analysis/model/FailureModesTable.java index b8ebf6bf..df3e0dab 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/FailureModesTable.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/FailureModesTable.java @@ -6,7 +6,7 @@ import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotEmpty; import java.util.HashSet; import java.util.Objects; import java.util.Set; @@ -21,10 +21,10 @@ public class FailureModesTable extends AbstractEntity { @OWLDataProperty(iri = Vocabulary.s_p_hasName) private String name; - @OWLObjectProperty(iri = Vocabulary.s_p_isDerivedFrom, fetch = FetchType.EAGER) + @OWLObjectProperty(iri = Vocabulary.s_p_isDerivedFrom, fetch = FetchType.LAZY) private FaultTree faultTree; - @OWLObjectProperty(iri = Vocabulary.s_p_hasRow, cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @OWLObjectProperty(iri = Vocabulary.s_p_hasRow, cascade = CascadeType.ALL, fetch = FetchType.LAZY) private Set rows = new HashSet<>(); @Override diff --git a/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java b/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java index 0f120c64..1efaa7fe 100755 --- a/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java @@ -6,8 +6,8 @@ import cz.cvut.kbss.jopa.model.annotations.*; import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import java.net.URI; import java.util.*; From 71038d8bde0803047d3f393e7f3a936bf2f5ebba Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 2 Jan 2024 14:55:06 +0100 Subject: [PATCH 4/8] [Update] Update Jopa version to 1.1.4 in ontology-generator --- ontology-generator/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ontology-generator/pom.xml b/ontology-generator/pom.xml index 74c11f5a..92343a3c 100644 --- a/ontology-generator/pom.xml +++ b/ontology-generator/pom.xml @@ -20,7 +20,7 @@ cz.cvut.kbss.jopa jopa-maven-plugin - 0.14.7 + 1.1.4 cz.cvut.kbss.analysis.util From eb91ec1cf6c737d639651886c2143c8bc731f1fc Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 2 Jan 2024 14:58:40 +0100 Subject: [PATCH 5/8] [Upgrade] In Dockerfile upgrade to java 17, maven 3.9.6 and gradle 8.4 - run jar instead of war --- Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3548cc1a..a76a5257 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ -FROM maven:3.6.1-jdk-11 as MAVEN +FROM maven:3.9.6-eclipse-temurin-17-alpine as MAVEN COPY . /fta-fmea WORKDIR /fta-fmea/ontology-generator RUN mvn clean install -FROM gradle:6.4-jdk11 as GRADLE +FROM gradle:8.4-jdk17-alpine as GRADLE COPY . /fta-fmea WORKDIR /fta-fmea COPY --from=MAVEN /fta-fmea/src/main/generated/cz/cvut/kbss/analysis/util/Vocabulary.java \ ./src/main/generated/cz/cvut/kbss/analysis/util/Vocabulary.java -RUN ./gradlew clean war +RUN ./gradlew clean bootJar -FROM tomcat:8-jdk11 +FROM eclipse-temurin:17-jdk-alpine as runtime -COPY --from=GRADLE /fta-fmea/build/libs/fta-fmea-*.war /usr/local/tomcat/webapps/fta-fmea.war +COPY --from=GRADLE /fta-fmea/build/libs/fta-fmea-*.jar /fta-fmea.jar EXPOSE 8080 -CMD ["catalina.sh", "run"] \ No newline at end of file +CMD ["java", "-jar", "/fta-fmea.jar"] \ No newline at end of file From f3675c0fb6d1571e5975e5b009e206d857847917 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 3 Jan 2024 11:56:35 +0100 Subject: [PATCH 6/8] [Fix] Revert unwanted change --- .../cvut/kbss/analysis/persistence/MainPersistenceFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java b/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java index 981b424a..e6be7ee9 100755 --- a/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java +++ b/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java @@ -67,7 +67,7 @@ private void init() { properties.put(ONTOLOGY_PHYSICAL_URI_KEY, repositoryConf.getUrl()); properties.put(DATA_SOURCE_CLASS, persistenceConf.getDriver()); properties.put(LANG, persistenceConf.getLanguage()); -// properties.put(CACHE_ENABLED, Boolean.FALSE.toString()); + properties.put(CACHE_ENABLED, Boolean.FALSE.toString()); if(repositoryConf.getUsername() != null && repositoryConf.getPassword() != null) { properties.put(DATA_SOURCE_USERNAME, repositoryConf.getUsername()); From 5847c56a50aac7c2d917c6d12b458de516963bf2 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 3 Jan 2024 12:12:32 +0100 Subject: [PATCH 7/8] [Fix] Clean security config --- src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java b/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java index 8f45670d..b54278b1 100755 --- a/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java +++ b/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java @@ -59,9 +59,7 @@ protected CorsConfigurationSource corsConfigurationSource() { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { log.debug("Using internal security mechanisms."); - final AuthenticationManager authManager = buildAuthenticationManager(http); http -// .requestMatcher(r -> false) .cors(auth -> auth.configurationSource(corsConfigurationSource())) .httpBasic(basic -> basic.disable()) .csrf(csrf -> csrf.disable()) From 1d9a884d17a64e939747d1db3d2c7687dd877a7a Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 3 Jan 2024 12:14:43 +0100 Subject: [PATCH 8/8] [Fix] Minor clean up and refactoring --- .../java/cz/cvut/kbss/analysis/config/SecurityConfig.java | 7 ++++--- .../kbss/analysis/persistence/MainPersistenceFactory.java | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java b/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java index b54278b1..cfd500db 100755 --- a/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java +++ b/src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java @@ -12,6 +12,7 @@ import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @@ -24,7 +25,7 @@ @Configuration @EnableWebSecurity @Slf4j -@EnableMethodSecurity(prePostEnabled = true) +@EnableMethodSecurity public class SecurityConfig { private final JwtTokenProvider jwtTokenProvider; @@ -61,8 +62,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { log.debug("Using internal security mechanisms."); http .cors(auth -> auth.configurationSource(corsConfigurationSource())) - .httpBasic(basic -> basic.disable()) - .csrf(csrf -> csrf.disable()) + .httpBasic(AbstractHttpConfigurer::disable) + .csrf(AbstractHttpConfigurer::disable) .sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .authorizeHttpRequests(auth -> auth .requestMatchers(AntPathRequestMatcher.antMatcher("/auth/register")).permitAll() diff --git a/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java b/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java index e6be7ee9..b7e9d45a 100755 --- a/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java +++ b/src/main/java/cz/cvut/kbss/analysis/persistence/MainPersistenceFactory.java @@ -4,7 +4,6 @@ import cz.cvut.kbss.analysis.config.conf.RepositoryConf; import cz.cvut.kbss.jopa.Persistence; import cz.cvut.kbss.jopa.model.EntityManagerFactory; -import cz.cvut.kbss.jopa.model.JOPAPersistenceProperties; import cz.cvut.kbss.jopa.model.JOPAPersistenceProvider; import org.springframework.beans.factory.annotation.Autowired;