Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade/upgrade to java 17 #48

Merged
merged 8 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
CMD ["java", "-jar", "/fta-fmea.jar"]
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -19,8 +19,8 @@ group = 'cz.cvut.kbss.analysis'
version = '0.0.1-SNAPSHOT'

compileJava {
sourceCompatibility = '11'
targetCompatibility = '11'
sourceCompatibility = '17'
targetCompatibility = '17'
}

repositories {
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion ontology-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!-- Generate entity classes from OWL integrity constraints -->
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-maven-plugin</artifactId>
<version>0.14.7</version>
<version>1.1.4</version>
<configuration>
<package>cz.cvut.kbss.analysis.util</package>
<!--Generate Vocabulary into Gradle project dirs-->
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/config/JacksonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
52 changes: 30 additions & 22 deletions src/main/java/cz/cvut/kbss/analysis/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
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;

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;
Expand All @@ -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();
Expand All @@ -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())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be something like authenticationManager(buildAuthenticationManager(http)). But, my changes in the PR affect this anyway, so it doesn't really matter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For it works without callingauthenticationManager(buildAuthenticationManager(http)) on the filter chain. It seams that the authentication provider bean is automatically set up in the filter chain.

Also, I removed the line with the unused authManager variable :
final AuthenticationManager authManager = buildAuthenticationManager(http);

.apply(new JwtConfigurer(jwtTokenProvider, securityUtils));
return http.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cz/cvut/kbss/analysis/model/Behavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cz/cvut/kbss/analysis/model/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<FailureModesRow> rows = new HashSet<>();

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cz/cvut/kbss/analysis/model/FaultTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cz/cvut/kbss/analysis/model/Mitigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cz/cvut/kbss/analysis/model/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cz/cvut/kbss/analysis/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
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;
import org.springframework.context.annotation.Bean;
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;

Expand Down Expand Up @@ -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());
blcham marked this conversation as resolved.
Show resolved Hide resolved

if(repositoryConf.getUsername() != null && repositoryConf.getPassword() != null) {
properties.put(DATA_SOURCE_USERNAME, repositoryConf.getUsername());
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/cz/cvut/kbss/analysis/security/JwtTokenFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Loading