From e6e30df6e6b9a31f07e4d15917a799bd7ef3fb92 Mon Sep 17 00:00:00 2001 From: Damien Trouillet <4112390+dtrouillet@users.noreply.github.com> Date: Wed, 31 Jul 2024 23:41:40 +0200 Subject: [PATCH 1/6] Feature/spring boot 3 (#347) * feat(spring): upgrade * feat(spring): delete javax * build(jdk): remove jdk under 17 * build(jdk): remove jdk under 17 * feat(spring): migrate authenticationManager * feat(spring): migrate oauth2 - in progress * feat(oauth): enable new oauth * feat(readme): add keycloak info * build(ut): fix some ut * fix(auth): add workaround to get csrf on cookie * fix(auth): add oauth2 converter * fix(LocalDate): Change Jsr310JpaConverters.LocalDateConverter.class for Jsr310JpaConverters.LocalDateTimeConverter.class * fix(jobrunr): change default poll interval to 10s --- .github/workflows/maven.yml | 2 +- README.md | 6 + pom.xml | 41 +++--- settings.xml | 8 +- .../java/fr/icdc/ebad/EbadApplication.java | 7 +- .../ebad/config/JobRunrConfiguration.java | 40 ++++++ .../java/fr/icdc/ebad/config/MailConfig.java | 2 +- .../ebad/config/apikey/ApiSecurityConfig.java | 11 +- .../ebad/config/jwt/JwtConfiguration.java | 107 +++++++++------- .../CustomJwtAuthenticationConverter.java | 102 +++++++++++++++ .../oauth/EbadAuthoritiesExtractor.java | 32 ----- .../config/oauth/EbadPrincipalExtractor.java | 72 ----------- .../config/oauth/Oauth2Configuration.java | 118 ++++++++++-------- .../config/properties/EbadProperties.java | 5 +- .../config/websocket/WebsocketConfig.java | 12 +- .../ebad/domain/AbstractAuditingEntity.java | 8 +- .../ebad/domain/AccreditationRequest.java | 23 ++-- .../java/fr/icdc/ebad/domain/Actualite.java | 17 ++- .../java/fr/icdc/ebad/domain/ApiToken.java | 15 ++- .../java/fr/icdc/ebad/domain/Application.java | 24 ++-- .../java/fr/icdc/ebad/domain/Authority.java | 18 +-- src/main/java/fr/icdc/ebad/domain/Batch.java | 30 ++--- src/main/java/fr/icdc/ebad/domain/Chaine.java | 26 ++-- .../icdc/ebad/domain/ChaineAssociation.java | 17 ++- .../icdc/ebad/domain/ChaineAssociationId.java | 3 +- .../java/fr/icdc/ebad/domain/Directory.java | 21 ++-- .../fr/icdc/ebad/domain/Environnement.java | 36 ++++-- .../fr/icdc/ebad/domain/GlobalSetting.java | 9 +- .../java/fr/icdc/ebad/domain/Identity.java | 21 +++- .../java/fr/icdc/ebad/domain/LogBatch.java | 15 ++- src/main/java/fr/icdc/ebad/domain/Norme.java | 17 ++- .../fr/icdc/ebad/domain/Notification.java | 23 ++-- .../java/fr/icdc/ebad/domain/Scheduling.java | 19 ++- .../java/fr/icdc/ebad/domain/Terminal.java | 18 +-- .../java/fr/icdc/ebad/domain/TypeFichier.java | 21 ++-- .../fr/icdc/ebad/domain/UsageApplication.java | 15 ++- .../icdc/ebad/domain/UsageApplicationId.java | 4 +- src/main/java/fr/icdc/ebad/domain/User.java | 32 ++--- .../icdc/ebad/repository/UserRepository.java | 4 +- .../fr/icdc/ebad/security/SecurityUtils.java | 4 + .../fr/icdc/ebad/security/jwt/JWTFilter.java | 10 +- .../icdc/ebad/security/jwt/TokenProvider.java | 2 +- .../service/AccreditationRequestService.java | 8 +- .../fr/icdc/ebad/service/ChaineService.java | 3 +- .../ebad/service/EnvironnementService.java | 4 +- .../fr/icdc/ebad/service/MailService.java | 6 +- .../ebad/service/NotificationService.java | 4 +- .../fr/icdc/ebad/service/PluginService.java | 3 +- .../fr/icdc/ebad/service/UserService.java | 7 +- .../java/fr/icdc/ebad/web/ResponseUtil.java | 1 - .../web/filter/CachingHttpHeadersFilter.java | 16 +-- .../icdc/ebad/web/rest/AccountResource.java | 1 - .../rest/AccreditationRequestResource.java | 12 +- .../icdc/ebad/web/rest/ApiTokenResource.java | 13 +- .../fr/icdc/ebad/web/rest/BatchResource.java | 12 +- .../icdc/ebad/web/rest/DirectoryResource.java | 14 ++- .../icdc/ebad/web/rest/IdentityResource.java | 13 +- .../fr/icdc/ebad/web/rest/NormResource.java | 13 +- .../ebad/web/rest/SchedulingResource.java | 12 +- .../icdc/ebad/web/rest/UserJWTController.java | 3 +- .../fr/icdc/ebad/web/rest/UserResource.java | 2 +- .../web/rest/dto/AccreditationRequestDto.java | 4 +- .../icdc/ebad/web/rest/dto/ApiTokenDto.java | 3 +- .../fr/icdc/ebad/web/rest/dto/BatchDto.java | 6 +- .../web/rest/dto/CompleteIdentityDto.java | 3 +- .../dto/CreationAccreditationRequestDto.java | 3 +- .../web/rest/dto/CreationSchedulingDto.java | 5 +- .../fr/icdc/ebad/web/rest/dto/LoginDto.java | 5 +- .../ebad/web/rest/dto/ManagedUserDto.java | 3 +- .../fr/icdc/ebad/web/rest/dto/NormeDto.java | 3 +- .../ebad/web/rest/dto/NotificationDto.java | 5 +- .../ebad/web/rest/dto/PublicIdentityDto.java | 3 +- .../dto/ResponseAccreditationRequestDto.java | 3 +- .../ebad/web/rest/dto/UserAccountDto.java | 8 +- .../icdc/ebad/web/rest/errors/ApiError.java | 3 +- .../web/rest/errors/ExceptionTranslator.java | 33 +++-- .../AccreditationRequestValidator.java | 5 +- .../validator/AccreditationValidator.java | 7 +- .../resources/config/application-local.yml | 2 +- .../resources/config/application-oauth.yaml | 6 + src/main/resources/config/application.yml | 8 +- .../permission/PermissionIdentityTest.java | 8 +- .../AccreditationRequestServiceTest.java | 14 +-- .../icdc/ebad/service/ChaineServiceTest.java | 2 +- .../ebad/service/DirectoryServiceTest.java | 5 +- .../service/EnvironnementServiceTest.java | 17 ++- .../fr/icdc/ebad/service/MailServiceTest.java | 23 ++-- .../ebad/service/jpa/BatchServiceJpaTest.java | 14 ++- .../web/rest/ExceptionTranslatorTest.java | 15 +-- .../web/rest/NotificationResourceTest.java | 10 +- .../fr/icdc/ebad/web/rest/WebsocketTest.java | 15 --- .../resources/config/application-test.yml | 1 + 92 files changed, 799 insertions(+), 607 deletions(-) create mode 100644 src/main/java/fr/icdc/ebad/config/JobRunrConfiguration.java create mode 100644 src/main/java/fr/icdc/ebad/config/oauth/CustomJwtAuthenticationConverter.java delete mode 100644 src/main/java/fr/icdc/ebad/config/oauth/EbadAuthoritiesExtractor.java delete mode 100644 src/main/java/fr/icdc/ebad/config/oauth/EbadPrincipalExtractor.java create mode 100644 src/main/resources/config/application-oauth.yaml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index de4b6159..035a0053 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [15, 16, 17 ] + java: [ 17, 19 ] steps: - uses: actions/checkout@v1 - name: Cache Maven Repo diff --git a/README.md b/README.md index 8330298e..79f44a26 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,12 @@ We use cypress for end to end tests with other ebad-front project Add additional notes about how to deploy this on a live system +### Keycloak +helm install keycloak -f values.yaml oci://registry-1.docker.io/bitnamicharts/keycloak +ingress: + enabled: true + hostname: idp.local + ## Built With diff --git a/pom.xml b/pom.xml index 0b90608e..5fccf74c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ spring-boot-starter-parent org.springframework.boot - 2.7.5 + 3.0.0 @@ -61,8 +61,8 @@ 7.0.0.CR1 ${project.build.directory}/test-results 0.8.0 + 5.3.1 3.9.0 - 4.0.10 @@ -71,7 +71,12 @@ org.bouncycastle - bcprov-jdk15on + bcprov-jdk15to18 + 1.73 + + + org.bouncycastle + bcpkix-jdk15on 1.70 @@ -131,11 +136,6 @@ com.fasterxml.jackson.datatype jackson-datatype-json-org - - com.fasterxml.jackson.datatype - jackson-datatype-joda - 2.15.3 - com.google.code.findbugs jsr305 @@ -217,26 +217,32 @@ org.ehcache ehcache + 3.10.6 - org.hibernate + org.hibernate.orm hibernate-jcache + 6.1.5.Final org.ehcache ehcache-transactions + 3.10.6 - org.hibernate + org.hibernate.orm hibernate-envers + 6.1.5.Final org.hibernate.validator hibernate-validator + 8.0.0.Final org.hibernate hibernate-entitymanager + 5.6.12.Final @@ -311,11 +317,12 @@ spring-security-messaging - org.springframework.security.oauth.boot - spring-security-oauth2-autoconfigure - 2.6.8 + org.springframework.boot + spring-boot-starter-oauth2-resource-server + 3.0.6 + org.springframework.security spring-security-core @@ -383,17 +390,20 @@ com.querydsl querydsl-apt + jakarta 5.0.0 com.querydsl querydsl-jpa + jakarta 5.0.0 + org.springframework.data spring-data-commons - 2.7.5 + 3.0.0 org.springdoc @@ -468,7 +478,7 @@ org.liquibase liquibase-core - 4.12.0 + 4.17.2 @@ -485,6 +495,7 @@ mapstruct 1.5.5.Final + diff --git a/settings.xml b/settings.xml index b4358e63..c6447689 100644 --- a/settings.xml +++ b/settings.xml @@ -21,13 +21,13 @@ github-public - ${env.USERNAME} - ${env.PASSWORD} + ${env.GITHUB_USERNAME} + ${env.GITHUB_pASSWORD} github - ${env.USERNAME} - ${env.PASSWORD} + ${env.GITHUB_USERNAME} + ${env.GITHUB_PASSWORD} diff --git a/src/main/java/fr/icdc/ebad/EbadApplication.java b/src/main/java/fr/icdc/ebad/EbadApplication.java index 17460d0c..30989da9 100644 --- a/src/main/java/fr/icdc/ebad/EbadApplication.java +++ b/src/main/java/fr/icdc/ebad/EbadApplication.java @@ -2,6 +2,7 @@ import fr.icdc.ebad.config.properties.EbadProperties; import fr.icdc.ebad.domain.Application; +import jakarta.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springdoc.data.rest.SpringDocDataRestConfiguration; @@ -9,16 +10,18 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; import org.springframework.core.env.Environment; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; -import javax.annotation.PostConstruct; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; -@SpringBootApplication(exclude = SpringDocDataRestConfiguration.class) +@SpringBootApplication +@ComponentScan(excludeFilters={@ComponentScan.Filter(type= FilterType.ASSIGNABLE_TYPE, value=SpringDocDataRestConfiguration.class)}) @EnableConfigurationProperties(EbadProperties.class) @EnableAsync @EnableScheduling diff --git a/src/main/java/fr/icdc/ebad/config/JobRunrConfiguration.java b/src/main/java/fr/icdc/ebad/config/JobRunrConfiguration.java new file mode 100644 index 00000000..d8f7e50c --- /dev/null +++ b/src/main/java/fr/icdc/ebad/config/JobRunrConfiguration.java @@ -0,0 +1,40 @@ +package fr.icdc.ebad.config; + +import org.jobrunr.jobs.mappers.JobMapper; +import org.jobrunr.spring.autoconfigure.JobRunrAutoConfiguration; +import org.jobrunr.spring.autoconfigure.storage.JobRunrSqlStorageAutoConfiguration; +import org.jobrunr.storage.StorageProvider; +import org.jobrunr.storage.StorageProviderUtils; +import org.jobrunr.storage.sql.common.DefaultSqlStorageProvider; +import org.jobrunr.storage.sql.h2.H2StorageProvider; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +import javax.sql.DataSource; + +@Configuration +@Import({JobRunrSqlStorageAutoConfiguration.class, JobRunrAutoConfiguration.class}) +public class JobRunrConfiguration { + + private final DataSource dataSource; + + public JobRunrConfiguration(DataSource dataSource) { + this.dataSource = dataSource; + } +// @Bean +// public StorageProvider storageProvider(JobMapper jobMapper) { +// +// DefaultSqlStorageProvider storageProvider = new DefaultSqlStorageProvider(dataSource, new AnsiDialect(), StorageProviderUtils.DatabaseOptions.CREATE); +// storageProvider.setJobMapper(jobMapper); +// return storageProvider; +// } + + @Bean + public StorageProvider storageProvider2(JobMapper jobMapper) { + + DefaultSqlStorageProvider storageProvider = new H2StorageProvider(dataSource, StorageProviderUtils.DatabaseOptions.CREATE); + storageProvider.setJobMapper(jobMapper); + return storageProvider; + } +} diff --git a/src/main/java/fr/icdc/ebad/config/MailConfig.java b/src/main/java/fr/icdc/ebad/config/MailConfig.java index e2883536..0c58bb87 100644 --- a/src/main/java/fr/icdc/ebad/config/MailConfig.java +++ b/src/main/java/fr/icdc/ebad/config/MailConfig.java @@ -3,7 +3,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.ResourceBundleMessageSource; -import org.thymeleaf.spring5.SpringTemplateEngine; +import org.thymeleaf.spring6.SpringTemplateEngine; import org.thymeleaf.templateresolver.ITemplateResolver; @Configuration diff --git a/src/main/java/fr/icdc/ebad/config/apikey/ApiSecurityConfig.java b/src/main/java/fr/icdc/ebad/config/apikey/ApiSecurityConfig.java index c614fd6c..492d8f5a 100644 --- a/src/main/java/fr/icdc/ebad/config/apikey/ApiSecurityConfig.java +++ b/src/main/java/fr/icdc/ebad/config/apikey/ApiSecurityConfig.java @@ -7,14 +7,14 @@ import org.springframework.core.annotation.Order; 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.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter; @Configuration @EnableWebSecurity @Order(2) -public class ApiSecurityConfig extends WebSecurityConfigurerAdapter { +public class ApiSecurityConfig { private final ApiKeyAuthenticationManager apiKeyAuthenticationManager; private final EbadProperties ebadProperties; @@ -35,11 +35,11 @@ public RequestHeaderAuthenticationFilter requestHeaderAuthenticationFilter() { return requestHeaderAuthenticationFilter; } - @Override - protected void configure(HttpSecurity http) throws Exception { + @Bean + public SecurityFilterChain configure(HttpSecurity http) throws Exception { // @formatter:off http - .requestMatcher(request -> { + .securityMatcher(request -> { String auth = request.getHeader(ebadProperties.getSecurity().getApiKeyHeaderName()); return (auth != null); }) @@ -51,5 +51,6 @@ protected void configure(HttpSecurity http) throws Exception { .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS); // @formatter:on + return http.build(); } } diff --git a/src/main/java/fr/icdc/ebad/config/jwt/JwtConfiguration.java b/src/main/java/fr/icdc/ebad/config/jwt/JwtConfiguration.java index 42dda381..27f723d6 100644 --- a/src/main/java/fr/icdc/ebad/config/jwt/JwtConfiguration.java +++ b/src/main/java/fr/icdc/ebad/config/jwt/JwtConfiguration.java @@ -4,116 +4,135 @@ import fr.icdc.ebad.security.jwt.JWTConfigurer; import fr.icdc.ebad.security.jwt.TokenProvider; import org.apache.commons.compress.utils.Lists; -import org.springframework.beans.factory.BeanInitializationException; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Profile; import org.springframework.core.annotation.Order; import org.springframework.core.env.Environment; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +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.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.csrf.CookieCsrfTokenRepository; +import org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.zalando.problem.spring.web.advice.security.SecurityProblemSupport; -import javax.annotation.PostConstruct; import java.util.Arrays; + @Profile(Constants.SPRING_PROFILE_JWT) @Configuration -@Import(SecurityProblemSupport.class) +//@Import(SecurityProblemSupport.class) @EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) +@EnableMethodSecurity(prePostEnabled = true, securedEnabled = true) @Order(3) -public class JwtConfiguration extends WebSecurityConfigurerAdapter { +public class JwtConfiguration { private final AuthenticationManagerBuilder authenticationManagerBuilder; private final UserDetailsService userDetailsService; private final TokenProvider tokenProvider; - private final SecurityProblemSupport problemSupport; +// private final SecurityProblemSupport problemSupport; private final Environment environment; private final PasswordEncoder passwordEncoder; - public JwtConfiguration(AuthenticationManagerBuilder authenticationManagerBuilder, UserDetailsService userDetailsService, TokenProvider tokenProvider, SecurityProblemSupport problemSupport, Environment environment, PasswordEncoder passwordEncoder) { + public JwtConfiguration(AuthenticationManagerBuilder authenticationManagerBuilder, UserDetailsService userDetailsService, TokenProvider tokenProvider, +// SecurityProblemSupport problemSupport, + Environment environment, PasswordEncoder passwordEncoder) { this.authenticationManagerBuilder = authenticationManagerBuilder; this.userDetailsService = userDetailsService; this.tokenProvider = tokenProvider; - this.problemSupport = problemSupport; +// this.problemSupport = problemSupport; this.environment = environment; this.passwordEncoder = passwordEncoder; } - @PostConstruct - public void init() { - try { - authenticationManagerBuilder - .userDetailsService(userDetailsService) - .passwordEncoder(passwordEncoder); - } catch (Exception e) { - throw new BeanInitializationException("Security configuration failed", e); - } - } +// @PostConstruct +// public void init() { +// try { +// authenticationManagerBuilder +// .userDetailsService(userDetailsService) +// .passwordEncoder(passwordEncoder); +// } catch (Exception e) { +// throw new BeanInitializationException("Security configuration failed", e); +// } +// } + +// @Bean +// public AuthenticationManager customAuthenticationManager() throws Exception { +// return new AuthenticationManager(); +// } @Bean - public AuthenticationManager customAuthenticationManager() throws Exception { - return authenticationManager(); + public AuthenticationManager customAuthenticationManager(HttpSecurity http) throws Exception { + // Configure AuthenticationManagerBuilder + AuthenticationManagerBuilder authenticationManagerBuilder = http.getSharedObject(AuthenticationManagerBuilder.class); + authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder); + // Get AuthenticationManager + return authenticationManagerBuilder.build(); } - @Override - protected void configure(HttpSecurity http) throws Exception { + @Bean + public SecurityFilterChain configure(HttpSecurity http) throws Exception { CookieCsrfTokenRepository cookieCsrfTokenRepository = CookieCsrfTokenRepository.withHttpOnlyFalse(); cookieCsrfTokenRepository.setCookiePath("/"); cookieCsrfTokenRepository.setHeaderName("X-XSRF-TOKEN"); cookieCsrfTokenRepository.setCookieName("XSRF-TOKEN"); cookieCsrfTokenRepository.setCookieHttpOnly(false); + CsrfTokenRequestAttributeHandler requestHandler = new CsrfTokenRequestAttributeHandler(); + requestHandler.setCsrfRequestAttributeName(null); + + http .exceptionHandling() - .authenticationEntryPoint(problemSupport) - .accessDeniedHandler(problemSupport) +// .authenticationEntryPoint(problemSupport) +// .accessDeniedHandler(problemSupport) .and() - .csrf().csrfTokenRepository(cookieCsrfTokenRepository) + .csrf() + .csrfTokenRepository(cookieCsrfTokenRepository) + .csrfTokenRequestHandler(requestHandler) .and() .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() - .authorizeRequests() - .antMatchers("/register").permitAll() - .antMatchers("/ws").permitAll() - .antMatchers("/news/public").permitAll() - .antMatchers("/activate").permitAll() - .antMatchers("/authenticate").permitAll() - .antMatchers("/account/reset-password/init").permitAll() - .antMatchers("/account/reset-password/finish").permitAll() - .antMatchers("/csrf").permitAll() - .antMatchers("/actuator/**").permitAll() - .antMatchers("/swagger-ui.html").permitAll() - .antMatchers("/v3/api-docs/**").permitAll() - .antMatchers("/v3/api-docs**").permitAll() - .antMatchers("/swagger-resources/configuration/ui").permitAll() - .antMatchers("/swagger-ui/**").permitAll() + .authorizeHttpRequests() + .requestMatchers("/register").permitAll() + .requestMatchers("/ws").permitAll() + .requestMatchers("/news/public").permitAll() + .requestMatchers("/activate").permitAll() + .requestMatchers("/authenticate").permitAll() + .requestMatchers("/account/reset-password/init").permitAll() + .requestMatchers("/account/reset-password/finish").permitAll() + .requestMatchers("/csrf").permitAll() + .requestMatchers("/actuator/**").permitAll() + .requestMatchers("/swagger-ui.html").permitAll() + .requestMatchers("/v3/api-docs/**").permitAll() + .requestMatchers("/v3/api-docs**").permitAll() + .requestMatchers("/swagger-resources/configuration/ui").permitAll() + .requestMatchers("/swagger-ui/**").permitAll() .anyRequest().authenticated() .and() .cors() .and() +// .addFilter(new AuthorizationFilter(authenticationManager, userRepository)) + .authenticationManager(customAuthenticationManager(http)) .apply(securityConfigurerAdapter()); if(Arrays.stream(environment.getActiveProfiles()).anyMatch("disable-csrf"::equalsIgnoreCase)){ http.csrf().disable(); } + + return http.build(); } diff --git a/src/main/java/fr/icdc/ebad/config/oauth/CustomJwtAuthenticationConverter.java b/src/main/java/fr/icdc/ebad/config/oauth/CustomJwtAuthenticationConverter.java new file mode 100644 index 00000000..7ddff2fb --- /dev/null +++ b/src/main/java/fr/icdc/ebad/config/oauth/CustomJwtAuthenticationConverter.java @@ -0,0 +1,102 @@ +package fr.icdc.ebad.config.oauth; + +import fr.icdc.ebad.config.properties.EbadProperties; +import fr.icdc.ebad.domain.Authority; +import fr.icdc.ebad.domain.User; +import fr.icdc.ebad.repository.AuthorityRepository; +import fr.icdc.ebad.repository.UserRepository; +import fr.icdc.ebad.security.EbadUserDetailsService; +import org.springframework.core.convert.converter.Converter; +import org.springframework.security.authentication.AbstractAuthenticationToken; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; +import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter; + +import java.util.*; +import java.util.stream.Collectors; + +public class CustomJwtAuthenticationConverter implements Converter { + + private final JwtGrantedAuthoritiesConverter grantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter(); + private final EbadUserDetailsService userDetailsService; + private final UserRepository userRepository; + private final AuthorityRepository authorityRepository; + private final EbadProperties ebadProperties; + + public CustomJwtAuthenticationConverter(EbadUserDetailsService userDetailsService, UserRepository userRepository, AuthorityRepository authorityRepository, EbadProperties ebadProperties) { + this.userDetailsService = userDetailsService; + this.userRepository = userRepository; + this.authorityRepository = authorityRepository; + this.ebadProperties = ebadProperties; + } + + + @Override + public AbstractAuthenticationToken convert(Jwt jwt) { + Collection authorities = extractAuthorities(jwt); + String principalClaimName = "preferred_username"; // Changez selon vos besoins + String principal = jwt.getClaimAsString(principalClaimName); + +// String authoritiesString = jwt.getClaim(ebadProperties.getSecurity().getMappingUser().getAuthorities()); + String login = jwt.getClaim(ebadProperties.getSecurity().getMappingUser().getLogin()); + String firstname = jwt.getClaim(ebadProperties.getSecurity().getMappingUser().getFirstname()); + String lastname = jwt.getClaim(ebadProperties.getSecurity().getMappingUser().getLastname()); + String email = jwt.getClaim(ebadProperties.getSecurity().getMappingUser().getEmail()); + Optional userOptional = userRepository.findOneByLogin(login); + + Set authoritiesSet = new HashSet<>(); + + for (GrantedAuthority authority : authorities) { + Optional authority1 = authorityRepository.findById(authority.getAuthority()); + authority1.ifPresent(authoritiesSet::add); + } + + + if (userOptional.isPresent()) { + User user = userOptional.get(); + user.setAuthorities(authoritiesSet); + user.setFirstName(firstname); + user.setLastName(lastname); + user.setEmail(email); + userRepository.save(user); + } else { + User newUser = new User(); + newUser.setAuthorities(authoritiesSet); + newUser.setLogin(login); + newUser.setPassword("NOPASSWORD"); + newUser.setFirstName(firstname); + newUser.setLastName(lastname); + newUser.setEmail(email); + newUser.setLangKey("FR_fr"); + newUser.setActivated(true); + newUser.setCreatedBy("OAUTH2"); + userRepository.save(newUser); + } + +// userDetailsService.loadUserByUsername(login); + // Créez un principal personnalisé si nécessaire + UserDetails customUserPrincipal = userDetailsService.loadUserByUsername(login); + +// return new JwtAuthenticationToken(jwt, authorities, customUserPrincipal.getUsername()); + return new UsernamePasswordAuthenticationToken(customUserPrincipal, jwt, authorities); + } + + private Collection extractAuthorities(Jwt jwt) { + Collection authorities = grantedAuthoritiesConverter.convert(jwt); + + List grantedAuthorities = new ArrayList<>(); + List authoritiesList = jwt.getClaim(ebadProperties.getSecurity().getMappingUser().getAuthorities()); + + for (String authority : authoritiesList) { + grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + authority)); + } + authorities.addAll(grantedAuthorities); + + + return authorities; + } +} diff --git a/src/main/java/fr/icdc/ebad/config/oauth/EbadAuthoritiesExtractor.java b/src/main/java/fr/icdc/ebad/config/oauth/EbadAuthoritiesExtractor.java deleted file mode 100644 index 057de582..00000000 --- a/src/main/java/fr/icdc/ebad/config/oauth/EbadAuthoritiesExtractor.java +++ /dev/null @@ -1,32 +0,0 @@ -package fr.icdc.ebad.config.oauth; - -import fr.icdc.ebad.config.properties.EbadProperties; -import org.springframework.boot.autoconfigure.security.oauth2.resource.AuthoritiesExtractor; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class EbadAuthoritiesExtractor implements AuthoritiesExtractor { - private final EbadProperties ebadProperties; - - public EbadAuthoritiesExtractor(EbadProperties ebadProperties) { - this.ebadProperties = ebadProperties; - } - - @Override - public List extractAuthorities(Map map) { - List grantedAuthorities = new ArrayList<>(); - String authoritiesString = (String) map.get(ebadProperties.getSecurity().getMappingUser().getAuthorities()); - authoritiesString = authoritiesString.replaceAll(" ", ""); - authoritiesString = authoritiesString.replace("[", ""); - authoritiesString = authoritiesString.replace("]", ""); - authoritiesString = authoritiesString.replace(ebadProperties.getApplicationIdentifier(), ""); - for (String authority : authoritiesString.split(",")) { - grantedAuthorities.add(new SimpleGrantedAuthority("ROLE" + authority)); - } - return grantedAuthorities; - } -} diff --git a/src/main/java/fr/icdc/ebad/config/oauth/EbadPrincipalExtractor.java b/src/main/java/fr/icdc/ebad/config/oauth/EbadPrincipalExtractor.java deleted file mode 100644 index 321bcf3b..00000000 --- a/src/main/java/fr/icdc/ebad/config/oauth/EbadPrincipalExtractor.java +++ /dev/null @@ -1,72 +0,0 @@ -package fr.icdc.ebad.config.oauth; - -import fr.icdc.ebad.config.properties.EbadProperties; -import fr.icdc.ebad.domain.Authority; -import fr.icdc.ebad.domain.User; -import fr.icdc.ebad.repository.AuthorityRepository; -import fr.icdc.ebad.repository.UserRepository; -import fr.icdc.ebad.security.EbadUserDetailsService; -import org.springframework.boot.autoconfigure.security.oauth2.resource.PrincipalExtractor; -import org.springframework.transaction.annotation.Transactional; - -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -public class EbadPrincipalExtractor implements PrincipalExtractor { - private final EbadUserDetailsService userDetailsService; - private final UserRepository userRepository; - private final AuthorityRepository authorityRepository; - private final EbadProperties ebadProperties; - - public EbadPrincipalExtractor(EbadUserDetailsService userDetailsService, UserRepository userRepository, AuthorityRepository authorityRepository, EbadProperties ebadProperties) { - this.userDetailsService = userDetailsService; - this.userRepository = userRepository; - this.authorityRepository = authorityRepository; - this.ebadProperties = ebadProperties; - } - - @Override - @Transactional - public Object extractPrincipal(Map map) { - String authoritiesString = (String) map.get(ebadProperties.getSecurity().getMappingUser().getAuthorities()); - String login = (String) map.get(ebadProperties.getSecurity().getMappingUser().getLogin()); - String firstname = (String) map.get(ebadProperties.getSecurity().getMappingUser().getFirstname()); - String lastname = (String) map.get(ebadProperties.getSecurity().getMappingUser().getLastname()); - String email = (String) map.get(ebadProperties.getSecurity().getMappingUser().getEmail()); - Optional userOptional = userRepository.findOneByLogin(login); - - Set authorities = new HashSet<>(); - authoritiesString = authoritiesString.replaceAll(" ", ""); - authoritiesString = authoritiesString.replace(ebadProperties.getApplicationIdentifier(), ""); - - for (String authority : authoritiesString.split(",")) { - Optional authority1 = authorityRepository.findById("ROLE" + authority); - authority1.ifPresent(authorities::add); - } - - if (userOptional.isPresent()) { - User user = userOptional.get(); - user.setAuthorities(authorities); - user.setFirstName(firstname); - user.setLastName(lastname); - user.setEmail(email); - userRepository.save(user); - } else { - User newUser = new User(); - newUser.setAuthorities(authorities); - newUser.setLogin(login); - newUser.setPassword("NOPASSWORD"); - newUser.setFirstName(firstname); - newUser.setLastName(lastname); - newUser.setEmail(email); - newUser.setLangKey("FR_fr"); - newUser.setActivated(true); - newUser.setCreatedBy("OAUTH2"); - userRepository.save(newUser); - } - - return userDetailsService.loadUserByUsername(login); - } -} diff --git a/src/main/java/fr/icdc/ebad/config/oauth/Oauth2Configuration.java b/src/main/java/fr/icdc/ebad/config/oauth/Oauth2Configuration.java index 607f72b4..f36c3ed5 100644 --- a/src/main/java/fr/icdc/ebad/config/oauth/Oauth2Configuration.java +++ b/src/main/java/fr/icdc/ebad/config/oauth/Oauth2Configuration.java @@ -4,50 +4,43 @@ import fr.icdc.ebad.repository.AuthorityRepository; import fr.icdc.ebad.repository.UserRepository; import fr.icdc.ebad.security.EbadUserDetailsService; -import org.springframework.boot.autoconfigure.security.oauth2.resource.AuthoritiesExtractor; -import org.springframework.boot.autoconfigure.security.oauth2.resource.PrincipalExtractor; -import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; -import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Profile; import org.springframework.core.annotation.Order; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.core.convert.converter.Converter; +import org.springframework.security.authentication.AbstractAuthenticationToken; +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.http.SessionCreationPolicy; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; -import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; -import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; +import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.csrf.CookieCsrfTokenRepository; -import org.zalando.problem.spring.web.advice.security.SecurityProblemSupport; +import org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler; @Profile("!jwt") @Order(3) @Configuration -@EnableOAuth2Client -@EnableResourceServer -@Import(SecurityProblemSupport.class) +//@EnableOAuth2Client +//@EnableResourceServer +//@Import(SecurityProblemSupport.class) @EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) -public class Oauth2Configuration extends ResourceServerConfigurerAdapter { - private final ResourceServerProperties resourceServerProperties; +@EnableMethodSecurity(prePostEnabled = true, securedEnabled = true) +public class Oauth2Configuration { + +// private final OauthJwtAuthConverter jwtAuthConverter; private final EbadUserDetailsService userDetailsService; private final UserRepository userRepository; - private final SecurityProblemSupport problemSupport; private final AuthorityRepository authorityRepository; private final EbadProperties ebadProperties; - public Oauth2Configuration(ResourceServerProperties resourceServerProperties, UserRepository userRepository, SecurityProblemSupport problemSupport, AuthorityRepository authorityRepository, EbadUserDetailsService userDetailsService, EbadProperties ebadProperties) { - this.resourceServerProperties = resourceServerProperties; + public Oauth2Configuration(EbadUserDetailsService userDetailsService, UserRepository userRepository, AuthorityRepository authorityRepository, EbadProperties ebadProperties) { this.userDetailsService = userDetailsService; this.userRepository = userRepository; - this.problemSupport = problemSupport; this.authorityRepository = authorityRepository; this.ebadProperties = ebadProperties; } @@ -57,13 +50,17 @@ public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } - @Override - public void configure(ResourceServerSecurityConfigurer resources) { - resources.tokenServices(this.resourceServerTokenServices()); - } +// @Override +// public void configure(ResourceServerSecurityConfigurer resources) { +// resources.tokenServices(this.resourceServerTokenServices()); +// } + +// @Override + @Bean +public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + CsrfTokenRequestAttributeHandler requestHandler = new CsrfTokenRequestAttributeHandler(); + requestHandler.setCsrfRequestAttributeName(null); - @Override - public void configure(HttpSecurity http) throws Exception { CookieCsrfTokenRepository cookieCsrfTokenRepository = CookieCsrfTokenRepository.withHttpOnlyFalse(); cookieCsrfTokenRepository.setCookiePath("/"); cookieCsrfTokenRepository.setHeaderName("X-XSRF-TOKEN"); @@ -72,45 +69,56 @@ public void configure(HttpSecurity http) throws Exception { http .exceptionHandling() - .authenticationEntryPoint(problemSupport) - .accessDeniedHandler(problemSupport) +// .authenticationEntryPoint(problemSupport) +// .accessDeniedHandler(problemSupport) .and().csrf().csrfTokenRepository(cookieCsrfTokenRepository) + .csrfTokenRequestHandler(requestHandler) .and() .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() - .authorizeRequests() - .antMatchers("/csrf").permitAll() - .antMatchers("/news/public").permitAll() - .antMatchers("/ws").permitAll() - .antMatchers("/actuator/**").permitAll() - .antMatchers("/swagger-ui.html").permitAll() - .antMatchers("/v3/api-docs/**").permitAll() - .antMatchers("/v3/api-docs**").permitAll() - .antMatchers("/swagger-resources/configuration/ui").permitAll() - .antMatchers("/swagger-ui/**").permitAll() - .anyRequest().authenticated() - .and() + .authorizeHttpRequests((authorize) -> authorize + .requestMatchers("/csrf").permitAll() + .requestMatchers("/news/public").permitAll() + .requestMatchers("/ws").permitAll() + .requestMatchers("/actuator/**").permitAll() + .requestMatchers("/swagger-ui.html").permitAll() + .requestMatchers("/v3/api-docs/**").permitAll() + .requestMatchers("/v3/api-docs**").permitAll() + .requestMatchers("/swagger-resources/configuration/ui").permitAll() + .requestMatchers("/swagger-ui/**").permitAll() + .anyRequest().authenticated() + ) + .oauth2ResourceServer(oauth2 -> oauth2.jwt().jwtAuthenticationConverter(jwtAuthenticationConverter())) .cors(); + return http.build(); } - @Bean - public PrincipalExtractor ebadPrincipalExtractor() { - return new EbadPrincipalExtractor(userDetailsService, userRepository, authorityRepository, ebadProperties); - } - @Bean - public AuthoritiesExtractor ebadAuthoritiesExtractor() { - return new EbadAuthoritiesExtractor(ebadProperties); - } + + +// @Bean +// public PrincipalExtractor ebadPrincipalExtractor() { +// return new EbadPrincipalExtractor(userDetailsService, userRepository, authorityRepository, ebadProperties); +// } +// +// @Bean +// public AuthoritiesExtractor ebadAuthoritiesExtractor() { +// return new EbadAuthoritiesExtractor(ebadProperties); +// } +// +// @Bean +// ResourceServerTokenServices resourceServerTokenServices() { +// UserInfoTokenServices userInfoTokenServices = new UserInfoTokenServices(resourceServerProperties.getUserInfoUri(), resourceServerProperties.getClientId()); +// userInfoTokenServices.setAuthoritiesExtractor(ebadAuthoritiesExtractor()); +// userInfoTokenServices.setPrincipalExtractor(ebadPrincipalExtractor()); +// return userInfoTokenServices; +// } @Bean - ResourceServerTokenServices resourceServerTokenServices() { - UserInfoTokenServices userInfoTokenServices = new UserInfoTokenServices(resourceServerProperties.getUserInfoUri(), resourceServerProperties.getClientId()); - userInfoTokenServices.setAuthoritiesExtractor(ebadAuthoritiesExtractor()); - userInfoTokenServices.setPrincipalExtractor(ebadPrincipalExtractor()); - return userInfoTokenServices; + public Converter jwtAuthenticationConverter() { + return new CustomJwtAuthenticationConverter(userDetailsService, userRepository, authorityRepository, ebadProperties); } diff --git a/src/main/java/fr/icdc/ebad/config/properties/EbadProperties.java b/src/main/java/fr/icdc/ebad/config/properties/EbadProperties.java index 29271ab3..ebef7916 100644 --- a/src/main/java/fr/icdc/ebad/config/properties/EbadProperties.java +++ b/src/main/java/fr/icdc/ebad/config/properties/EbadProperties.java @@ -1,11 +1,10 @@ package fr.icdc.ebad.config.properties; -import lombok.Getter; -import lombok.Setter; +import jakarta.validation.constraints.NotNull; +import lombok.*; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; -import javax.validation.constraints.NotNull; import java.time.Duration; @Getter diff --git a/src/main/java/fr/icdc/ebad/config/websocket/WebsocketConfig.java b/src/main/java/fr/icdc/ebad/config/websocket/WebsocketConfig.java index 9a5891c9..b4a72c15 100644 --- a/src/main/java/fr/icdc/ebad/config/websocket/WebsocketConfig.java +++ b/src/main/java/fr/icdc/ebad/config/websocket/WebsocketConfig.java @@ -10,11 +10,9 @@ import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.messaging.support.MessageHeaderAccessor; import org.springframework.security.core.Authentication; -import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; -import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; @@ -22,12 +20,10 @@ @EnableWebSocketMessageBroker public class WebsocketConfig implements WebSocketMessageBrokerConfigurer { private final TokenProvider tokenProvider; - private final ResourceServerTokenServices resourceServerTokenServices; private final Environment environment; - public WebsocketConfig(TokenProvider tokenProvider, @Nullable ResourceServerTokenServices resourceServerTokenServices, Environment environment) { + public WebsocketConfig(TokenProvider tokenProvider, Environment environment) { this.tokenProvider = tokenProvider; - this.resourceServerTokenServices = resourceServerTokenServices; this.environment = environment; } @@ -55,9 +51,11 @@ public org.springframework.messaging.Message preSend(org.springframework.mess Authentication authentication = null; if (Arrays.stream(environment.getActiveProfiles()).anyMatch(env -> (env.equalsIgnoreCase("jwt")))) { authentication = tokenProvider.getAuthentication(token); - } else if (resourceServerTokenServices != null) { - authentication = resourceServerTokenServices.loadAuthentication(token); } + //FIXME DTROUILLET +// else if (resourceServerTokenServices != null) { +// authentication = resourceServerTokenServices.loadAuthentication(token); +// } accessor.setUser(authentication); return message; } diff --git a/src/main/java/fr/icdc/ebad/domain/AbstractAuditingEntity.java b/src/main/java/fr/icdc/ebad/domain/AbstractAuditingEntity.java index debcc20c..46efe2c0 100644 --- a/src/main/java/fr/icdc/ebad/domain/AbstractAuditingEntity.java +++ b/src/main/java/fr/icdc/ebad/domain/AbstractAuditingEntity.java @@ -1,5 +1,9 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import jakarta.validation.constraints.NotNull; import org.hibernate.envers.Audited; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; @@ -7,10 +11,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import javax.persistence.Column; -import javax.persistence.EntityListeners; -import javax.persistence.MappedSuperclass; -import javax.validation.constraints.NotNull; import java.time.LocalDateTime; /** diff --git a/src/main/java/fr/icdc/ebad/domain/AccreditationRequest.java b/src/main/java/fr/icdc/ebad/domain/AccreditationRequest.java index cc509e38..2776769a 100644 --- a/src/main/java/fr/icdc/ebad/domain/AccreditationRequest.java +++ b/src/main/java/fr/icdc/ebad/domain/AccreditationRequest.java @@ -1,23 +1,22 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; - @Data @EqualsAndHashCode(callSuper = false) @Entity diff --git a/src/main/java/fr/icdc/ebad/domain/Actualite.java b/src/main/java/fr/icdc/ebad/domain/Actualite.java index f21e1220..7177af3b 100644 --- a/src/main/java/fr/icdc/ebad/domain/Actualite.java +++ b/src/main/java/fr/icdc/ebad/domain/Actualite.java @@ -1,5 +1,13 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -8,15 +16,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - /** * Entite des actualites permettant d'enregistrer des actualites a afficher sur * la page d'accueil diff --git a/src/main/java/fr/icdc/ebad/domain/ApiToken.java b/src/main/java/fr/icdc/ebad/domain/ApiToken.java index 7ef075cb..e56052ba 100644 --- a/src/main/java/fr/icdc/ebad/domain/ApiToken.java +++ b/src/main/java/fr/icdc/ebad/domain/ApiToken.java @@ -1,5 +1,16 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -7,10 +18,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.*; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - @Entity @Data @Builder diff --git a/src/main/java/fr/icdc/ebad/domain/Application.java b/src/main/java/fr/icdc/ebad/domain/Application.java index 2ce9bb2b..f445839c 100644 --- a/src/main/java/fr/icdc/ebad/domain/Application.java +++ b/src/main/java/fr/icdc/ebad/domain/Application.java @@ -2,6 +2,18 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonManagedReference; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderBy; +import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -11,18 +23,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.OrderBy; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/fr/icdc/ebad/domain/Authority.java b/src/main/java/fr/icdc/ebad/domain/Authority.java index 96a91d54..e72999c3 100644 --- a/src/main/java/fr/icdc/ebad/domain/Authority.java +++ b/src/main/java/fr/icdc/ebad/domain/Authority.java @@ -1,6 +1,15 @@ package fr.icdc.ebad.domain; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -9,15 +18,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/fr/icdc/ebad/domain/Batch.java b/src/main/java/fr/icdc/ebad/domain/Batch.java index b12e0412..4a579eea 100644 --- a/src/main/java/fr/icdc/ebad/domain/Batch.java +++ b/src/main/java/fr/icdc/ebad/domain/Batch.java @@ -1,6 +1,21 @@ package fr.icdc.ebad.domain; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.annotation.Nullable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -10,21 +25,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.annotation.Nullable; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Transient; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import java.util.ArrayList; import java.util.HashSet; import java.util.List; diff --git a/src/main/java/fr/icdc/ebad/domain/Chaine.java b/src/main/java/fr/icdc/ebad/domain/Chaine.java index 8ee3d734..66ac23cb 100644 --- a/src/main/java/fr/icdc/ebad/domain/Chaine.java +++ b/src/main/java/fr/icdc/ebad/domain/Chaine.java @@ -1,5 +1,18 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderBy; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -7,19 +20,6 @@ import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.Cascade; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.OrderBy; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/fr/icdc/ebad/domain/ChaineAssociation.java b/src/main/java/fr/icdc/ebad/domain/ChaineAssociation.java index 823d24a7..77c64a62 100644 --- a/src/main/java/fr/icdc/ebad/domain/ChaineAssociation.java +++ b/src/main/java/fr/icdc/ebad/domain/ChaineAssociation.java @@ -1,17 +1,16 @@ package fr.icdc.ebad.domain; import com.fasterxml.jackson.annotation.JsonBackReference; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Id; +import jakarta.persistence.IdClass; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import lombok.Data; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - /** * Created by dtrouillet on 13/06/2016. */ diff --git a/src/main/java/fr/icdc/ebad/domain/ChaineAssociationId.java b/src/main/java/fr/icdc/ebad/domain/ChaineAssociationId.java index 194b3ca9..537d2b48 100644 --- a/src/main/java/fr/icdc/ebad/domain/ChaineAssociationId.java +++ b/src/main/java/fr/icdc/ebad/domain/ChaineAssociationId.java @@ -2,7 +2,6 @@ import lombok.Data; -import java.io.Serial; import java.io.Serializable; /** @@ -10,7 +9,7 @@ */ @Data public class ChaineAssociationId implements Serializable { - @Serial +// @Serial private static final long serialVersionUID = 1L; private int batchOrder; diff --git a/src/main/java/fr/icdc/ebad/domain/Directory.java b/src/main/java/fr/icdc/ebad/domain/Directory.java index 0b4155e0..af53797e 100644 --- a/src/main/java/fr/icdc/ebad/domain/Directory.java +++ b/src/main/java/fr/icdc/ebad/domain/Directory.java @@ -1,5 +1,15 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -8,17 +18,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - /** * Directory */ diff --git a/src/main/java/fr/icdc/ebad/domain/Environnement.java b/src/main/java/fr/icdc/ebad/domain/Environnement.java index 2fe46976..dad0a9b0 100644 --- a/src/main/java/fr/icdc/ebad/domain/Environnement.java +++ b/src/main/java/fr/icdc/ebad/domain/Environnement.java @@ -3,16 +3,34 @@ import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; -import lombok.*; +import jakarta.annotation.Nullable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; import org.hibernate.annotations.Cache; -import org.hibernate.annotations.*; - -import javax.annotation.Nullable; -import javax.persistence.Entity; -import javax.persistence.Table; -import javax.persistence.*; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; + import java.util.Date; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/fr/icdc/ebad/domain/GlobalSetting.java b/src/main/java/fr/icdc/ebad/domain/GlobalSetting.java index 6d584aa1..a0855eb2 100644 --- a/src/main/java/fr/icdc/ebad/domain/GlobalSetting.java +++ b/src/main/java/fr/icdc/ebad/domain/GlobalSetting.java @@ -1,5 +1,9 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -9,11 +13,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - @Entity @Data @Builder diff --git a/src/main/java/fr/icdc/ebad/domain/Identity.java b/src/main/java/fr/icdc/ebad/domain/Identity.java index 6913cc91..6fb4a238 100644 --- a/src/main/java/fr/icdc/ebad/domain/Identity.java +++ b/src/main/java/fr/icdc/ebad/domain/Identity.java @@ -1,14 +1,25 @@ package fr.icdc.ebad.domain; import com.fasterxml.jackson.annotation.JsonBackReference; -import lombok.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.*; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - @Data @EqualsAndHashCode(callSuper = false) @Entity diff --git a/src/main/java/fr/icdc/ebad/domain/LogBatch.java b/src/main/java/fr/icdc/ebad/domain/LogBatch.java index e35cdd2a..e7016528 100644 --- a/src/main/java/fr/icdc/ebad/domain/LogBatch.java +++ b/src/main/java/fr/icdc/ebad/domain/LogBatch.java @@ -2,11 +2,20 @@ import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; +import jakarta.annotation.Nullable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; import lombok.Data; -import javax.annotation.Nullable; -import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.util.Date; /** diff --git a/src/main/java/fr/icdc/ebad/domain/Norme.java b/src/main/java/fr/icdc/ebad/domain/Norme.java index 7f03cadc..539df8bb 100644 --- a/src/main/java/fr/icdc/ebad/domain/Norme.java +++ b/src/main/java/fr/icdc/ebad/domain/Norme.java @@ -1,5 +1,13 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -8,15 +16,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - /** * Entite de normes permettant de rendre parametrable les differentes normes, chemins et interpretteur * de ligne de commande diff --git a/src/main/java/fr/icdc/ebad/domain/Notification.java b/src/main/java/fr/icdc/ebad/domain/Notification.java index 7f7f8834..b76c0e4a 100644 --- a/src/main/java/fr/icdc/ebad/domain/Notification.java +++ b/src/main/java/fr/icdc/ebad/domain/Notification.java @@ -1,15 +1,24 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.Convert; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.annotations.Type; -import org.joda.time.DateTime; + import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters; -import javax.persistence.*; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import java.time.LocalDateTime; /** * Entite des notifications permettant d'enregistrer des notications @@ -29,10 +38,10 @@ public class Notification { private String content; @NotNull - @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime") @CreatedDate @Column(nullable = false, name = "created_date") - private DateTime createdDate = DateTime.now(); + @Convert(converter= Jsr310JpaConverters.LocalDateTimeConverter.class) + private LocalDateTime createdDate = LocalDateTime.now(); @NotNull @Column(nullable = false, name = "is_read") diff --git a/src/main/java/fr/icdc/ebad/domain/Scheduling.java b/src/main/java/fr/icdc/ebad/domain/Scheduling.java index 450d3f2d..a6bb66e1 100644 --- a/src/main/java/fr/icdc/ebad/domain/Scheduling.java +++ b/src/main/java/fr/icdc/ebad/domain/Scheduling.java @@ -1,6 +1,15 @@ package fr.icdc.ebad.domain; import com.fasterxml.jackson.annotation.JsonBackReference; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -10,16 +19,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; - @EqualsAndHashCode(callSuper = true) @Entity diff --git a/src/main/java/fr/icdc/ebad/domain/Terminal.java b/src/main/java/fr/icdc/ebad/domain/Terminal.java index 90dcabfe..1b1057a7 100644 --- a/src/main/java/fr/icdc/ebad/domain/Terminal.java +++ b/src/main/java/fr/icdc/ebad/domain/Terminal.java @@ -1,6 +1,15 @@ package fr.icdc.ebad.domain; import com.fasterxml.jackson.annotation.JsonBackReference; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -8,15 +17,6 @@ import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import java.util.UUID; @Data diff --git a/src/main/java/fr/icdc/ebad/domain/TypeFichier.java b/src/main/java/fr/icdc/ebad/domain/TypeFichier.java index 0ec5a1b7..87faed4a 100644 --- a/src/main/java/fr/icdc/ebad/domain/TypeFichier.java +++ b/src/main/java/fr/icdc/ebad/domain/TypeFichier.java @@ -1,21 +1,20 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - /** * TypeFichier */ diff --git a/src/main/java/fr/icdc/ebad/domain/UsageApplication.java b/src/main/java/fr/icdc/ebad/domain/UsageApplication.java index ba16d5b7..76609391 100644 --- a/src/main/java/fr/icdc/ebad/domain/UsageApplication.java +++ b/src/main/java/fr/icdc/ebad/domain/UsageApplication.java @@ -1,19 +1,18 @@ package fr.icdc.ebad.domain; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.Column; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapsId; +import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ManyToOne; -import javax.persistence.MapsId; -import javax.persistence.Table; - @Entity @AllArgsConstructor @NoArgsConstructor diff --git a/src/main/java/fr/icdc/ebad/domain/UsageApplicationId.java b/src/main/java/fr/icdc/ebad/domain/UsageApplicationId.java index 99324213..2edcccff 100644 --- a/src/main/java/fr/icdc/ebad/domain/UsageApplicationId.java +++ b/src/main/java/fr/icdc/ebad/domain/UsageApplicationId.java @@ -1,11 +1,11 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import javax.persistence.Column; -import javax.persistence.Embeddable; import java.io.Serializable; @Embeddable diff --git a/src/main/java/fr/icdc/ebad/domain/User.java b/src/main/java/fr/icdc/ebad/domain/User.java index 51d5432d..13ed132a 100644 --- a/src/main/java/fr/icdc/ebad/domain/User.java +++ b/src/main/java/fr/icdc/ebad/domain/User.java @@ -1,5 +1,21 @@ package fr.icdc.ebad.domain; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -9,22 +25,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Transient; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/fr/icdc/ebad/repository/UserRepository.java b/src/main/java/fr/icdc/ebad/repository/UserRepository.java index ec30fe90..472cc64f 100644 --- a/src/main/java/fr/icdc/ebad/repository/UserRepository.java +++ b/src/main/java/fr/icdc/ebad/repository/UserRepository.java @@ -5,7 +5,6 @@ import com.querydsl.core.types.dsl.StringPath; import fr.icdc.ebad.domain.QUser; import fr.icdc.ebad.domain.User; -import org.joda.time.DateTime; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; @@ -17,6 +16,7 @@ import org.springframework.data.querydsl.binding.SingleValueBinding; import org.springframework.data.repository.query.Param; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -40,7 +40,7 @@ default void customize(QuerydslBindings bindings, QUser root) { Optional findOneByActivationKey(String activationKey); - List findAllByActivatedIsFalseAndCreatedDateBefore(DateTime dateTime); + List findAllByActivatedIsFalseAndCreatedDateBefore(LocalDateTime dateTime); Optional findOneByEmail(String email); diff --git a/src/main/java/fr/icdc/ebad/security/SecurityUtils.java b/src/main/java/fr/icdc/ebad/security/SecurityUtils.java index 459f1986..44834d78 100644 --- a/src/main/java/fr/icdc/ebad/security/SecurityUtils.java +++ b/src/main/java/fr/icdc/ebad/security/SecurityUtils.java @@ -5,6 +5,8 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; /** * Utility class for Spring Security. @@ -30,6 +32,8 @@ public static String getCurrentLogin() { userName = springSecurityUser.getUsername(); } else if (authentication.getPrincipal() instanceof String) { userName = (String) authentication.getPrincipal(); + } else if (authentication.getPrincipal() instanceof Jwt){ + userName = ((Jwt)authentication.getPrincipal()).getSubject(); } } return userName; diff --git a/src/main/java/fr/icdc/ebad/security/jwt/JWTFilter.java b/src/main/java/fr/icdc/ebad/security/jwt/JWTFilter.java index 66b43dd8..8578d380 100644 --- a/src/main/java/fr/icdc/ebad/security/jwt/JWTFilter.java +++ b/src/main/java/fr/icdc/ebad/security/jwt/JWTFilter.java @@ -1,15 +1,15 @@ package fr.icdc.ebad.security.jwt; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.util.StringUtils; 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 java.io.IOException; /** diff --git a/src/main/java/fr/icdc/ebad/security/jwt/TokenProvider.java b/src/main/java/fr/icdc/ebad/security/jwt/TokenProvider.java index db81df55..3e2c47ab 100644 --- a/src/main/java/fr/icdc/ebad/security/jwt/TokenProvider.java +++ b/src/main/java/fr/icdc/ebad/security/jwt/TokenProvider.java @@ -8,6 +8,7 @@ import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.SignatureException; import io.jsonwebtoken.UnsupportedJwtException; +import jakarta.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -17,7 +18,6 @@ import org.springframework.security.core.userdetails.User; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; import java.util.Arrays; import java.util.Collection; import java.util.Date; diff --git a/src/main/java/fr/icdc/ebad/service/AccreditationRequestService.java b/src/main/java/fr/icdc/ebad/service/AccreditationRequestService.java index d6a2d224..e6f528f4 100644 --- a/src/main/java/fr/icdc/ebad/service/AccreditationRequestService.java +++ b/src/main/java/fr/icdc/ebad/service/AccreditationRequestService.java @@ -14,6 +14,7 @@ import fr.icdc.ebad.service.util.EbadServiceException; import fr.icdc.ebad.web.rest.dto.AccreditationRequestDto; import fr.icdc.ebad.web.rest.dto.AuthorityApplicationDTO; +import jakarta.mail.MessagingException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; @@ -23,7 +24,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.mail.MessagingException; @Service @@ -60,7 +60,7 @@ public AccreditationRequest requestNewAccreditation(Long applicationId, boolean .wantUse(isWantUse) .build(); - AccreditationRequest result = accreditationRequestRepository.save(accreditationRequest); + AccreditationRequest result = accreditationRequestRepository.saveAndFlush(accreditationRequest); AccreditationRequestDto[] sendNotif = {mapStructMapper.convert(result)}; application.getUsageApplications() @@ -108,7 +108,7 @@ public void answerToRequest(Long idAccreditationRequest, boolean isAccepted) thr AccreditationRequest accreditationRequest = accreditationRequestRepository.findByIdAndState(idAccreditationRequest, StateRequest.SENT).orElseThrow(EbadServiceException::new); if (!isAccepted) { accreditationRequest.setState(StateRequest.REJECTED); - accreditationRequestRepository.save(accreditationRequest); + accreditationRequestRepository.saveAndFlush(accreditationRequest); } else { AuthorityApplicationDTO authorityApplicationDTO = new AuthorityApplicationDTO(); @@ -118,7 +118,7 @@ public void answerToRequest(Long idAccreditationRequest, boolean isAccepted) thr authorityApplicationDTO.setAddUser(accreditationRequest.isWantUse()); if (null != userService.changeAutorisationApplication(authorityApplicationDTO)) { accreditationRequest.setState(StateRequest.ACCEPTED); - accreditationRequestRepository.save(accreditationRequest); + accreditationRequestRepository.saveAndFlush(accreditationRequest); } } diff --git a/src/main/java/fr/icdc/ebad/service/ChaineService.java b/src/main/java/fr/icdc/ebad/service/ChaineService.java index 85069344..485f6d21 100644 --- a/src/main/java/fr/icdc/ebad/service/ChaineService.java +++ b/src/main/java/fr/icdc/ebad/service/ChaineService.java @@ -37,7 +37,6 @@ public ChaineService(BatchService batchService, ChaineRepository chaineRepositor } @Job(name = "Chain %0, User %1", retries = 0) - //@Transactional public RetourBatch jobRunChaine(Long chaineId, String login) throws EbadServiceException { Chaine chaine = getChaine(chaineId); return runChaine(chaine, login); @@ -86,7 +85,7 @@ public Chaine addChaine(Chaine chaine){ @Transactional(readOnly = true) public Chaine getChaine(Long id) { - return chaineRepository.getById(id); + return chaineRepository.getReferenceById(id); } @Transactional(readOnly = true) diff --git a/src/main/java/fr/icdc/ebad/service/EnvironnementService.java b/src/main/java/fr/icdc/ebad/service/EnvironnementService.java index af187c27..c2206eae 100644 --- a/src/main/java/fr/icdc/ebad/service/EnvironnementService.java +++ b/src/main/java/fr/icdc/ebad/service/EnvironnementService.java @@ -22,6 +22,8 @@ import fr.icdc.ebad.repository.NormeRepository; import fr.icdc.ebad.repository.SchedulingRepository; import fr.icdc.ebad.service.util.EbadServiceException; +import jakarta.annotation.Nullable; +import jakarta.validation.constraints.NotNull; import org.jobrunr.scheduling.JobScheduler; import org.pf4j.PluginRuntimeException; import org.pf4j.PluginWrapper; @@ -35,8 +37,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Nullable; -import javax.validation.constraints.NotNull; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; diff --git a/src/main/java/fr/icdc/ebad/service/MailService.java b/src/main/java/fr/icdc/ebad/service/MailService.java index 57b395a4..872d9e59 100644 --- a/src/main/java/fr/icdc/ebad/service/MailService.java +++ b/src/main/java/fr/icdc/ebad/service/MailService.java @@ -2,6 +2,8 @@ import fr.icdc.ebad.config.properties.EbadProperties; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.ObjectProvider; @@ -9,10 +11,8 @@ import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service; import org.thymeleaf.context.Context; -import org.thymeleaf.spring5.SpringTemplateEngine; +import org.thymeleaf.spring6.SpringTemplateEngine; -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; import java.util.HashMap; @Service diff --git a/src/main/java/fr/icdc/ebad/service/NotificationService.java b/src/main/java/fr/icdc/ebad/service/NotificationService.java index b88a53ce..f1a3dec0 100644 --- a/src/main/java/fr/icdc/ebad/service/NotificationService.java +++ b/src/main/java/fr/icdc/ebad/service/NotificationService.java @@ -4,12 +4,12 @@ import fr.icdc.ebad.domain.User; import fr.icdc.ebad.repository.NotificationRepository; import fr.icdc.ebad.security.SecurityUtils; -import org.joda.time.DateTime; import org.springframework.data.domain.Sort; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.List; /** @@ -32,7 +32,7 @@ public void createNotification(String message, User user, boolean isDanger) { } Notification notification = new Notification(); notification.setContent(message); - notification.setCreatedDate(DateTime.now()); + notification.setCreatedDate(LocalDateTime.now()); notification.setReceiver(user); notification.setDanger(isDanger); Notification result = notificationRepository.save(notification); diff --git a/src/main/java/fr/icdc/ebad/service/PluginService.java b/src/main/java/fr/icdc/ebad/service/PluginService.java index a43a0e72..1a3fad19 100644 --- a/src/main/java/fr/icdc/ebad/service/PluginService.java +++ b/src/main/java/fr/icdc/ebad/service/PluginService.java @@ -1,13 +1,12 @@ package fr.icdc.ebad.service; +import jakarta.annotation.PostConstruct; import org.pf4j.PluginWrapper; import org.pf4j.spring.SpringPluginManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import javax.annotation.PostConstruct; - @Service public class PluginService { private static final Logger LOGGER = LoggerFactory.getLogger(PluginService.class); diff --git a/src/main/java/fr/icdc/ebad/service/UserService.java b/src/main/java/fr/icdc/ebad/service/UserService.java index 24ead86c..94656e71 100644 --- a/src/main/java/fr/icdc/ebad/service/UserService.java +++ b/src/main/java/fr/icdc/ebad/service/UserService.java @@ -12,7 +12,6 @@ import fr.icdc.ebad.service.util.EbadServiceException; import fr.icdc.ebad.service.util.RandomUtil; import fr.icdc.ebad.web.rest.dto.AuthorityApplicationDTO; -import org.joda.time.DateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; @@ -22,6 +21,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalUnit; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -129,7 +132,7 @@ public User getUserWithAuthorities() throws EbadServiceException { @Scheduled(cron = "0 0 1 * * ?") @Transactional public void removeNotActivatedUsers() { - DateTime now = new DateTime(); + LocalDateTime now = LocalDateTime.now(); List users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minusDays(NUMBERS_OF_DAY_KEEP_INACTIVATE_USERS)); for (User user : users) { LOGGER.debug("Deleting not activated user {}", user.getLogin()); diff --git a/src/main/java/fr/icdc/ebad/web/ResponseUtil.java b/src/main/java/fr/icdc/ebad/web/ResponseUtil.java index e16d2bd6..48ba5cb2 100644 --- a/src/main/java/fr/icdc/ebad/web/ResponseUtil.java +++ b/src/main/java/fr/icdc/ebad/web/ResponseUtil.java @@ -4,7 +4,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; -import javax.persistence.EntityNotFoundException; import java.util.Optional; public final class ResponseUtil { diff --git a/src/main/java/fr/icdc/ebad/web/filter/CachingHttpHeadersFilter.java b/src/main/java/fr/icdc/ebad/web/filter/CachingHttpHeadersFilter.java index 2a93745e..e303f2cc 100644 --- a/src/main/java/fr/icdc/ebad/web/filter/CachingHttpHeadersFilter.java +++ b/src/main/java/fr/icdc/ebad/web/filter/CachingHttpHeadersFilter.java @@ -1,12 +1,14 @@ package fr.icdc.ebad.web.filter; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletResponse; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletResponse; + import java.io.IOException; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/fr/icdc/ebad/web/rest/AccountResource.java b/src/main/java/fr/icdc/ebad/web/rest/AccountResource.java index b57bdbf3..91b9a67b 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/AccountResource.java +++ b/src/main/java/fr/icdc/ebad/web/rest/AccountResource.java @@ -20,7 +20,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import javax.servlet.http.HttpServletRequest; import java.util.LinkedList; import java.util.Optional; import java.util.stream.Collectors; diff --git a/src/main/java/fr/icdc/ebad/web/rest/AccreditationRequestResource.java b/src/main/java/fr/icdc/ebad/web/rest/AccreditationRequestResource.java index e53eed37..7b430360 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/AccreditationRequestResource.java +++ b/src/main/java/fr/icdc/ebad/web/rest/AccreditationRequestResource.java @@ -2,24 +2,28 @@ import fr.icdc.ebad.domain.AccreditationRequest; +import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.service.AccreditationRequestService; import fr.icdc.ebad.service.util.EbadServiceException; import fr.icdc.ebad.web.rest.dto.AccreditationRequestDto; import fr.icdc.ebad.web.rest.dto.CreationAccreditationRequestDto; import fr.icdc.ebad.web.rest.dto.ResponseAccreditationRequestDto; -import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.web.rest.util.PaginationUtil; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import org.springdoc.core.converters.models.PageableAsQueryParam; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/accreditation-requests") diff --git a/src/main/java/fr/icdc/ebad/web/rest/ApiTokenResource.java b/src/main/java/fr/icdc/ebad/web/rest/ApiTokenResource.java index 24ad5eaa..ba53865d 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/ApiTokenResource.java +++ b/src/main/java/fr/icdc/ebad/web/rest/ApiTokenResource.java @@ -1,16 +1,17 @@ package fr.icdc.ebad.web.rest; import fr.icdc.ebad.domain.ApiToken; +import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.security.SecurityUtils; import fr.icdc.ebad.service.ApiTokenService; import fr.icdc.ebad.service.util.EbadServiceException; import fr.icdc.ebad.web.rest.dto.ApiTokenDto; import fr.icdc.ebad.web.rest.dto.ApiTokenWithKeyDto; -import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.web.rest.util.PaginationUtil; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springdoc.core.converters.models.PageableAsQueryParam; @@ -19,9 +20,13 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/api-tokens") diff --git a/src/main/java/fr/icdc/ebad/web/rest/BatchResource.java b/src/main/java/fr/icdc/ebad/web/rest/BatchResource.java index 8eb60151..5428e52b 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/BatchResource.java +++ b/src/main/java/fr/icdc/ebad/web/rest/BatchResource.java @@ -12,6 +12,7 @@ import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import org.jobrunr.jobs.JobId; import org.jobrunr.scheduling.JobScheduler; import org.slf4j.Logger; @@ -24,10 +25,17 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Flux; -import javax.validation.Valid; import java.time.Duration; import java.util.UUID; diff --git a/src/main/java/fr/icdc/ebad/web/rest/DirectoryResource.java b/src/main/java/fr/icdc/ebad/web/rest/DirectoryResource.java index b5b78093..3c0c7cf8 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/DirectoryResource.java +++ b/src/main/java/fr/icdc/ebad/web/rest/DirectoryResource.java @@ -2,11 +2,11 @@ import com.querydsl.core.types.Predicate; import fr.icdc.ebad.domain.Directory; +import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.service.DirectoryService; import fr.icdc.ebad.service.util.EbadServiceException; import fr.icdc.ebad.web.rest.dto.DirectoryDto; import fr.icdc.ebad.web.rest.dto.FilesDto; -import fr.icdc.ebad.mapper.MapStructMapper; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; @@ -14,6 +14,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springdoc.core.converters.models.PageableAsQueryParam; @@ -24,10 +25,17 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; diff --git a/src/main/java/fr/icdc/ebad/web/rest/IdentityResource.java b/src/main/java/fr/icdc/ebad/web/rest/IdentityResource.java index bc7f92c1..5feeb017 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/IdentityResource.java +++ b/src/main/java/fr/icdc/ebad/web/rest/IdentityResource.java @@ -2,15 +2,16 @@ import com.querydsl.core.types.Predicate; import fr.icdc.ebad.domain.Identity; +import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.service.IdentityService; import fr.icdc.ebad.web.ResponseUtil; import fr.icdc.ebad.web.rest.dto.CompleteIdentityDto; import fr.icdc.ebad.web.rest.dto.PublicIdentityDto; -import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.web.rest.util.PaginationUtil; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springdoc.core.converters.models.PageableAsQueryParam; @@ -22,9 +23,15 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; -import javax.validation.Valid; import java.util.Optional; @RestController diff --git a/src/main/java/fr/icdc/ebad/web/rest/NormResource.java b/src/main/java/fr/icdc/ebad/web/rest/NormResource.java index abb1657b..5c6c22c8 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/NormResource.java +++ b/src/main/java/fr/icdc/ebad/web/rest/NormResource.java @@ -2,15 +2,16 @@ import com.querydsl.core.types.Predicate; import fr.icdc.ebad.domain.Norme; +import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.service.NormeService; import fr.icdc.ebad.web.ResponseUtil; import fr.icdc.ebad.web.rest.dto.NormLabelIdDto; import fr.icdc.ebad.web.rest.dto.NormeDto; -import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.web.rest.util.PaginationUtil; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springdoc.core.converters.models.PageableAsQueryParam; @@ -21,9 +22,15 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; -import javax.validation.Valid; import java.util.Optional; @RestController diff --git a/src/main/java/fr/icdc/ebad/web/rest/SchedulingResource.java b/src/main/java/fr/icdc/ebad/web/rest/SchedulingResource.java index e9e89b12..7de729e5 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/SchedulingResource.java +++ b/src/main/java/fr/icdc/ebad/web/rest/SchedulingResource.java @@ -2,22 +2,28 @@ import fr.icdc.ebad.domain.Scheduling; +import fr.icdc.ebad.mapper.MapStructMapper; import fr.icdc.ebad.service.SchedulingService; import fr.icdc.ebad.service.util.EbadServiceException; import fr.icdc.ebad.web.rest.dto.CreationSchedulingDto; import fr.icdc.ebad.web.rest.dto.SchedulingDto; -import fr.icdc.ebad.mapper.MapStructMapper; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import org.springdoc.core.converters.models.PageableAsQueryParam; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; -import javax.validation.Valid; import java.net.URI; @RestController diff --git a/src/main/java/fr/icdc/ebad/web/rest/UserJWTController.java b/src/main/java/fr/icdc/ebad/web/rest/UserJWTController.java index b455438b..31336703 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/UserJWTController.java +++ b/src/main/java/fr/icdc/ebad/web/rest/UserJWTController.java @@ -10,6 +10,7 @@ import fr.icdc.ebad.web.rest.dto.UserDto; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import org.springframework.context.annotation.Profile; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -22,8 +23,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import javax.validation.Valid; - /** * Controller to authenticate users. */ diff --git a/src/main/java/fr/icdc/ebad/web/rest/UserResource.java b/src/main/java/fr/icdc/ebad/web/rest/UserResource.java index 8a4ffec2..41a38a6e 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/UserResource.java +++ b/src/main/java/fr/icdc/ebad/web/rest/UserResource.java @@ -13,6 +13,7 @@ import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springdoc.core.converters.models.PageableAsQueryParam; @@ -32,7 +33,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import javax.validation.Valid; import java.util.Optional; /** diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/AccreditationRequestDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/AccreditationRequestDto.java index 2e268cd8..ca91afde 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/AccreditationRequestDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/AccreditationRequestDto.java @@ -1,15 +1,13 @@ package fr.icdc.ebad.web.rest.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import fr.icdc.ebad.web.rest.validator.AccreditationValidator; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotNull; - @Data @Builder @EqualsAndHashCode diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/ApiTokenDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/ApiTokenDto.java index 0807fc80..93171ce2 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/ApiTokenDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/ApiTokenDto.java @@ -1,9 +1,8 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.NotNull; import lombok.Data; -import javax.validation.constraints.NotNull; - @Data public class ApiTokenDto { private Long id; diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/BatchDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/BatchDto.java index 11c621e3..2e4b1c5a 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/BatchDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/BatchDto.java @@ -1,12 +1,12 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Size; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/CompleteIdentityDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/CompleteIdentityDto.java index 8d034954..3f8496dc 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/CompleteIdentityDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/CompleteIdentityDto.java @@ -1,12 +1,11 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotNull; - @Data @Builder @NoArgsConstructor diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/CreationAccreditationRequestDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/CreationAccreditationRequestDto.java index 4522e333..7be02e20 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/CreationAccreditationRequestDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/CreationAccreditationRequestDto.java @@ -1,14 +1,13 @@ package fr.icdc.ebad.web.rest.dto; import fr.icdc.ebad.web.rest.validator.AccreditationValidator; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotNull; - @Data @Builder @EqualsAndHashCode diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/CreationSchedulingDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/CreationSchedulingDto.java index 6dea55f5..67d20a07 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/CreationSchedulingDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/CreationSchedulingDto.java @@ -1,14 +1,13 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; - @Data @ToString @Builder diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/LoginDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/LoginDto.java index ad31d4b5..aa312901 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/LoginDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/LoginDto.java @@ -1,10 +1,9 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - /** * View Model object for storing a user's credentials. */ diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/ManagedUserDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/ManagedUserDto.java index 028e4431..e7d4d03c 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/ManagedUserDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/ManagedUserDto.java @@ -1,13 +1,12 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import javax.validation.constraints.Size; - /** * View Model extending the UserAccountDto, which is meant to be used in the user management UI. */ diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/NormeDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/NormeDto.java index 94056ffb..058c3413 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/NormeDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/NormeDto.java @@ -1,13 +1,12 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.NotBlank; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotBlank; - @Data @Builder @AllArgsConstructor diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/NotificationDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/NotificationDto.java index be868352..526d0ecd 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/NotificationDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/NotificationDto.java @@ -1,12 +1,13 @@ package fr.icdc.ebad.web.rest.dto; import lombok.Data; -import org.joda.time.DateTime; + +import java.time.LocalDateTime; @Data public class NotificationDto { private Long id; private String content; - private DateTime createdDate = DateTime.now(); + private LocalDateTime createdDate = LocalDateTime.now(); private boolean read = false; } diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/PublicIdentityDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/PublicIdentityDto.java index 54fb24a5..611fbc04 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/PublicIdentityDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/PublicIdentityDto.java @@ -1,9 +1,8 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.NotNull; import lombok.Data; -import javax.validation.constraints.NotNull; - @Data public class PublicIdentityDto { private Long id; diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/ResponseAccreditationRequestDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/ResponseAccreditationRequestDto.java index a97f280c..b05dd814 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/ResponseAccreditationRequestDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/ResponseAccreditationRequestDto.java @@ -1,13 +1,12 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotNull; - @Data @Builder @EqualsAndHashCode diff --git a/src/main/java/fr/icdc/ebad/web/rest/dto/UserAccountDto.java b/src/main/java/fr/icdc/ebad/web/rest/dto/UserAccountDto.java index 4829707f..74e98c3a 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/dto/UserAccountDto.java +++ b/src/main/java/fr/icdc/ebad/web/rest/dto/UserAccountDto.java @@ -1,12 +1,12 @@ package fr.icdc.ebad.web.rest.dto; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; import lombok.Getter; import lombok.ToString; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; import java.util.List; @Getter diff --git a/src/main/java/fr/icdc/ebad/web/rest/errors/ApiError.java b/src/main/java/fr/icdc/ebad/web/rest/errors/ApiError.java index 1ea43a31..e2692623 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/errors/ApiError.java +++ b/src/main/java/fr/icdc/ebad/web/rest/errors/ApiError.java @@ -93,9 +93,10 @@ public void addValidationError(List globalErrors) { * @param cv the ConstraintViolation */ private void addValidationError(ConstraintViolation cv) { + PathImpl path = PathImpl.createPathFromString(cv.getPropertyPath().toString()); this.addValidationError( cv.getRootBeanClass().getSimpleName(), - ((PathImpl) cv.getPropertyPath()).getLeafNode().asString(), + path.getLeafNode().asString(), cv.getInvalidValue(), cv.getMessage()); } diff --git a/src/main/java/fr/icdc/ebad/web/rest/errors/ExceptionTranslator.java b/src/main/java/fr/icdc/ebad/web/rest/errors/ExceptionTranslator.java index f61e8e15..2467eefb 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/errors/ExceptionTranslator.java +++ b/src/main/java/fr/icdc/ebad/web/rest/errors/ExceptionTranslator.java @@ -4,11 +4,13 @@ import fr.icdc.ebad.security.UserNotActivatedException; import fr.icdc.ebad.service.util.EbadNotFoundException; import fr.icdc.ebad.service.util.EbadServiceException; +import jakarta.validation.ConstraintViolationException; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; @@ -24,8 +26,6 @@ import org.springframework.web.servlet.NoHandlerFoundException; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; -import javax.validation.ConstraintViolationException; - import static org.springframework.http.HttpStatus.BAD_REQUEST; /** @@ -52,7 +52,7 @@ public ExceptionTranslator(MessageSource messageSource) { @Override protected ResponseEntity handleMissingServletRequestParameter( MissingServletRequestParameterException ex, HttpHeaders headers, - HttpStatus status, WebRequest request) { + HttpStatusCode status, WebRequest request) { String error = ex.getParameterName() + " parameter is missing"; return buildResponseEntity(new ApiError(BAD_REQUEST, error, ex)); } @@ -71,7 +71,7 @@ protected ResponseEntity handleMissingServletRequestParameter( protected ResponseEntity handleHttpMediaTypeNotSupported( HttpMediaTypeNotSupportedException ex, HttpHeaders headers, - HttpStatus status, + HttpStatusCode status, WebRequest request) { StringBuilder builder = new StringBuilder(); builder.append(ex.getContentType()); @@ -93,7 +93,7 @@ protected ResponseEntity handleHttpMediaTypeNotSupported( protected ResponseEntity handleMethodArgumentNotValid( MethodArgumentNotValidException ex, HttpHeaders headers, - HttpStatus status, + HttpStatusCode status, WebRequest request) { ApiError apiError = new ApiError(BAD_REQUEST); apiError.setMessage("Error occured when validate field"); @@ -108,12 +108,12 @@ protected ResponseEntity handleMethodArgumentNotValid( * @param ex the ConstraintViolationException * @return the ApiError object */ - @ExceptionHandler(javax.validation.ConstraintViolationException.class) + @ExceptionHandler(ConstraintViolationException.class) protected ResponseEntity handleConstraintViolation( - javax.validation.ConstraintViolationException ex) { + ConstraintViolationException ex) { ApiError apiError = new ApiError(BAD_REQUEST); apiError.setMessage("Error occured when validate field"); - apiError.addValidationErrors(ex.getConstraintViolations()); +// apiError.addValidationErrors(ex.getConstraintViolations()); return buildResponseEntity(apiError); } @@ -128,7 +128,7 @@ protected ResponseEntity handleConstraintViolation( * @return the ApiError object */ @Override - protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { + protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { String error = "Malformed JSON request"; return buildResponseEntity(new ApiError(HttpStatus.BAD_REQUEST, error, ex)); } @@ -143,7 +143,7 @@ protected ResponseEntity handleHttpMessageNotReadable(HttpMessageNotRead * @return the ApiError object */ @Override - protected ResponseEntity handleHttpMessageNotWritable(HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { + protected ResponseEntity handleHttpMessageNotWritable(HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { String error = "Error writing JSON output"; return buildResponseEntity(new ApiError(HttpStatus.INTERNAL_SERVER_ERROR, error, ex)); } @@ -159,7 +159,7 @@ protected ResponseEntity handleHttpMessageNotWritable(HttpMessageNotWrit */ @Override protected ResponseEntity handleNoHandlerFoundException( - NoHandlerFoundException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { + NoHandlerFoundException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { ApiError apiError = new ApiError(BAD_REQUEST); apiError.setMessage(String.format("Could not find the %s method for URL %s", ex.getHttpMethod(), ex.getRequestURL())); apiError.setDebugMessage(ex.getMessage()); @@ -188,7 +188,7 @@ protected ResponseEntity handleEbadNotFound(EbadNotFoundException ex) { */ @ExceptionHandler(EbadServiceException.class) protected ResponseEntity handleEbadServiceException(EbadServiceException ex) { - return buildResponseEntity(new ApiError(HttpStatus.INTERNAL_SERVER_ERROR,ex.getMessage(), ex)); + return buildResponseEntity(new ApiError(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), ex)); } /** @@ -196,17 +196,16 @@ protected ResponseEntity handleEbadServiceException(EbadServiceException */ @ExceptionHandler(IllegalStateException.class) protected ResponseEntity handleIllegalStateException(IllegalStateException ex) { - return buildResponseEntity(new ApiError(BAD_REQUEST,ex.getMessage(), ex)); + return buildResponseEntity(new ApiError(BAD_REQUEST, ex.getMessage(), ex)); } @ExceptionHandler({InsufficientAuthenticationException.class, UserNotActivatedException.class, AccessDeniedException.class}) - public ResponseEntity handleInsufficientAuthenticationException(Exception ex){ - return buildResponseEntity(new ApiError(HttpStatus.FORBIDDEN,messageSource.getMessage(ErrorConstants.ERR_FORBIDDEN, null, LocaleContextHolder.getLocale()), ex)); + public ResponseEntity handleInsufficientAuthenticationException(Exception ex) { + return buildResponseEntity(new ApiError(HttpStatus.FORBIDDEN, messageSource.getMessage(ErrorConstants.ERR_FORBIDDEN, null, LocaleContextHolder.getLocale()), ex)); } - /** * Handle DataIntegrityViolationException, inspects the cause for different DB causes. * @@ -243,7 +242,7 @@ protected ResponseEntity handleMethodArgumentTypeMismatch(MethodArgument @ExceptionHandler(Exception.class) protected ResponseEntity handleException(Exception ex) { logger.error(ex.getMessage(), ex); - return buildResponseEntity(new ApiError(HttpStatus.INTERNAL_SERVER_ERROR,"Internal Server Error", ex)); + return buildResponseEntity(new ApiError(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error", ex)); } diff --git a/src/main/java/fr/icdc/ebad/web/rest/validator/AccreditationRequestValidator.java b/src/main/java/fr/icdc/ebad/web/rest/validator/AccreditationRequestValidator.java index ced13a2e..dde9fd4f 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/validator/AccreditationRequestValidator.java +++ b/src/main/java/fr/icdc/ebad/web/rest/validator/AccreditationRequestValidator.java @@ -1,12 +1,11 @@ package fr.icdc.ebad.web.rest.validator; import fr.icdc.ebad.web.rest.dto.CreationAccreditationRequestDto; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - public class AccreditationRequestValidator implements ConstraintValidator { private static final Logger LOGGER = LoggerFactory.getLogger(AccreditationRequestValidator.class); diff --git a/src/main/java/fr/icdc/ebad/web/rest/validator/AccreditationValidator.java b/src/main/java/fr/icdc/ebad/web/rest/validator/AccreditationValidator.java index ba05d6ad..1c5b8a09 100644 --- a/src/main/java/fr/icdc/ebad/web/rest/validator/AccreditationValidator.java +++ b/src/main/java/fr/icdc/ebad/web/rest/validator/AccreditationValidator.java @@ -1,7 +1,8 @@ package fr.icdc.ebad.web.rest.validator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -14,4 +15,4 @@ String message() default "{error.validation.accreditation}"; Class[] groups() default { }; Class[] payload() default { }; -} \ No newline at end of file +} diff --git a/src/main/resources/config/application-local.yml b/src/main/resources/config/application-local.yml index 3cc3ae58..57c830a3 100644 --- a/src/main/resources/config/application-local.yml +++ b/src/main/resources/config/application-local.yml @@ -1,6 +1,6 @@ spring: datasource: - url: jdbc:h2:~/ebad;MODE=PostgreSQL + url: jdbc:h2:~/ebad;MODE=PostgreSQL;CASE_INSENSITIVE_IDENTIFIERS=TRUE #url: jdbc:h2:file:/data/demo driverClassName: org.h2.Driver username: sa diff --git a/src/main/resources/config/application-oauth.yaml b/src/main/resources/config/application-oauth.yaml new file mode 100644 index 00000000..9402fe07 --- /dev/null +++ b/src/main/resources/config/application-oauth.yaml @@ -0,0 +1,6 @@ +spring: + security: + oauth2: + resourceserver: + jwt: + issuer-uri: http://idp.local/realms/Test diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index bd7525b7..dc2950db 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -37,6 +37,7 @@ spring: hibernate.current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext hibernate.javax.cache.missing_cache_strategy: create hibernate.enable_lazy_load_no_trans: true + hibernate.id.db_structure_naming_strategy: legacy thymeleaf: mode: HTML encoding: UTF-8 @@ -61,10 +62,13 @@ security: logging.level: fr.icdc.ebad: info root: info - + org: + springframework: + security: DEBUG org.jobrunr: background-job-server: enabled: true - poll-interval-in-seconds: 5 + poll-interval-in-seconds: 10 dashboard.enabled: true + diff --git a/src/test/java/fr/icdc/ebad/security/permission/PermissionIdentityTest.java b/src/test/java/fr/icdc/ebad/security/permission/PermissionIdentityTest.java index 3f3250ea..b46a12d5 100644 --- a/src/test/java/fr/icdc/ebad/security/permission/PermissionIdentityTest.java +++ b/src/test/java/fr/icdc/ebad/security/permission/PermissionIdentityTest.java @@ -3,7 +3,6 @@ import fr.icdc.ebad.domain.Application; import fr.icdc.ebad.domain.Identity; import fr.icdc.ebad.repository.IdentityRepository; -import liquibase.pro.packaged.A; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -25,7 +24,10 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -241,4 +243,4 @@ public void canWrite5() { verify(permissionApplication, times(1)).canWrite(eq(2L), eq(userDetails)); } -} \ No newline at end of file +} diff --git a/src/test/java/fr/icdc/ebad/service/AccreditationRequestServiceTest.java b/src/test/java/fr/icdc/ebad/service/AccreditationRequestServiceTest.java index 3578769e..5ff55ea4 100644 --- a/src/test/java/fr/icdc/ebad/service/AccreditationRequestServiceTest.java +++ b/src/test/java/fr/icdc/ebad/service/AccreditationRequestServiceTest.java @@ -10,6 +10,7 @@ import fr.icdc.ebad.repository.AccreditationRequestRepository; import fr.icdc.ebad.repository.ApplicationRepository; import fr.icdc.ebad.service.util.EbadServiceException; +import jakarta.mail.MessagingException; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -25,7 +26,6 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; -import javax.mail.MessagingException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -113,11 +113,11 @@ public void requestNewAccreditation() throws EbadServiceException, MessagingExce when(applicationRepository.findById(eq(1L))).thenReturn(Optional.of(accreditationRequest.getApplication())); when(userService.getUser(any())).thenReturn(Optional.of(User.builder().login("testlogin").email("test@test.fr").build())); - when(accreditationRequestRepository.save(eq(accreditationRequest))).thenReturn(accreditationRequestWithId); + when(accreditationRequestRepository.saveAndFlush(eq(accreditationRequest))).thenReturn(accreditationRequestWithId); doNothing().when(notificationService).createNotification(any(), any(), eq(false)); AccreditationRequest result = accreditationRequestService.requestNewAccreditation(1L, true, false); - verify(accreditationRequestRepository).save(eq(accreditationRequest)); + verify(accreditationRequestRepository).saveAndFlush(eq(accreditationRequest)); verify(messagingTemplate).convertAndSendToUser(any(), eq("/queue/accreditations"), any()); verify(mailService).sendMailAccreditation(eq("modo@test.fr")); @@ -150,14 +150,14 @@ public void requestNewAccreditationErrorMail() throws EbadServiceException, Mess when(applicationRepository.findById(eq(1L))).thenReturn(Optional.of(accreditationRequest.getApplication())); when(userService.getUser(any())).thenReturn(Optional.of(User.builder().login("testlogin").email("test@test.fr").build())); - when(accreditationRequestRepository.save(eq(accreditationRequest))).thenReturn(accreditationRequestWithId); + when(accreditationRequestRepository.saveAndFlush(eq(accreditationRequest))).thenReturn(accreditationRequestWithId); doThrow(MessagingException.class).when(mailService).sendMailAccreditation(eq("modo@test.fr")); doNothing().when(notificationService).createNotification(any(), any(), eq(false)); AccreditationRequest result = accreditationRequestService.requestNewAccreditation(1L, true, false); - verify(accreditationRequestRepository).save(eq(accreditationRequest)); + verify(accreditationRequestRepository).saveAndFlush(eq(accreditationRequest)); verify(messagingTemplate).convertAndSendToUser(any(), eq("/queue/accreditations"), any()); verify(mailService).sendMailAccreditation(eq("modo@test.fr")); @@ -323,7 +323,7 @@ public void answerToRequestReject() throws EbadServiceException { when(accreditationRequestRepository.findByIdAndState(eq(1L), eq(StateRequest.SENT))).thenReturn(Optional.of(accreditationRequest)); accreditationRequestService.answerToRequest(1L, false); - verify(accreditationRequestRepository).save(eq(accreditationRequestRejected)); + verify(accreditationRequestRepository).saveAndFlush(eq(accreditationRequestRejected)); } @Test @@ -357,7 +357,7 @@ public void answerToRequestAccept() throws EbadServiceException { accreditationRequestService.answerToRequest(1L, true); - verify(accreditationRequestRepository).save(eq(accreditationRequestAccepted)); + verify(accreditationRequestRepository).saveAndFlush(eq(accreditationRequestAccepted)); verify(userService).changeAutorisationApplication(argThat(authorityApplicationDTO -> "testlogin".equals(authorityApplicationDTO.getLoginUser()) diff --git a/src/test/java/fr/icdc/ebad/service/ChaineServiceTest.java b/src/test/java/fr/icdc/ebad/service/ChaineServiceTest.java index 357f71cf..7bdd3b59 100644 --- a/src/test/java/fr/icdc/ebad/service/ChaineServiceTest.java +++ b/src/test/java/fr/icdc/ebad/service/ChaineServiceTest.java @@ -165,7 +165,7 @@ public void addChaine() { public void testGetChaine() { Chaine chaine = new Chaine(); chaine.setId(1L); - when(chaineRepository.getById(chaine.getId())).thenReturn(chaine); + when(chaineRepository.getReferenceById(chaine.getId())).thenReturn(chaine); Chaine result = chaineService.getChaine(chaine.getId()); diff --git a/src/test/java/fr/icdc/ebad/service/DirectoryServiceTest.java b/src/test/java/fr/icdc/ebad/service/DirectoryServiceTest.java index aa515a20..ed4d3a93 100644 --- a/src/test/java/fr/icdc/ebad/service/DirectoryServiceTest.java +++ b/src/test/java/fr/icdc/ebad/service/DirectoryServiceTest.java @@ -11,7 +11,6 @@ import fr.icdc.ebad.web.rest.dto.FilesDto; import org.apache.commons.io.IOUtils; import org.apache.sshd.sftp.client.SftpClient; -import org.joda.time.DateTime; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -25,6 +24,8 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.attribute.FileTime; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.ArrayList; import java.util.List; @@ -139,7 +140,7 @@ private SftpClient.DirEntry lsEntryWithGivenFilenameAndMTime(String filename, lo } private long unixTimestampForDaysAgo(int days) { - return new DateTime().minusDays(days).getMillis() / 1000; + return LocalDateTime.now().minusDays(days).toInstant(ZoneOffset.UTC).toEpochMilli() / 1000; } @Test diff --git a/src/test/java/fr/icdc/ebad/service/EnvironnementServiceTest.java b/src/test/java/fr/icdc/ebad/service/EnvironnementServiceTest.java index ab8ae8fd..133d5547 100644 --- a/src/test/java/fr/icdc/ebad/service/EnvironnementServiceTest.java +++ b/src/test/java/fr/icdc/ebad/service/EnvironnementServiceTest.java @@ -26,7 +26,6 @@ import fr.icdc.ebad.repository.SchedulingRepository; import fr.icdc.ebad.service.util.EbadServiceException; import org.jobrunr.scheduling.JobScheduler; -import org.joda.time.format.DateTimeFormat; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,6 +44,9 @@ import org.springframework.data.domain.Pageable; import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; @@ -218,7 +220,12 @@ public void testChangeDateTraiement() throws EbadServiceException { Environnement environnement = Environnement.builder().id(1L).homePath("/home").norme(norme).application(application).build(); when(shellService.runCommandNew(eq(environnement), eq("echo 01022018 > /home/date.tr"))).thenReturn(retourBatch); when(environnementRepository.getById(eq(environnement.getId()))).thenReturn(environnement); - environnementService.changeDateTraiement(1L, DateTimeFormat.forPattern("ddMMyyyy").parseDateTime("01022018").toDate()); + + LocalDate now = LocalDate.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ddMMyyyy"); + LocalDate parsedDate = LocalDate.parse("01022018", formatter); + + environnementService.changeDateTraiement(1L, Date.from(parsedDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); verify(shellService).runCommandNew(eq(environnement), eq("echo 01022018 > /home/date.tr")); } @@ -234,7 +241,11 @@ public void testChangeDateTraiementError() throws EbadServiceException { when(shellService.runCommandNew(eq(environnement), eq("echo 01022018 > /home/date.tr"))).thenThrow(new EbadServiceException()); when(environnementRepository.getById(eq(environnement.getId()))).thenReturn(environnement); - environnementService.changeDateTraiement(1L, DateTimeFormat.forPattern("ddMMyyyy").parseDateTime("01022018").toDate()); + LocalDate now = LocalDate.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ddMMyyyy"); + LocalDate parsedDate = LocalDate.parse("01022018", formatter); + + environnementService.changeDateTraiement(1L, Date.from(parsedDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); } @Test diff --git a/src/test/java/fr/icdc/ebad/service/MailServiceTest.java b/src/test/java/fr/icdc/ebad/service/MailServiceTest.java index 64a3fe5e..1e181323 100644 --- a/src/test/java/fr/icdc/ebad/service/MailServiceTest.java +++ b/src/test/java/fr/icdc/ebad/service/MailServiceTest.java @@ -1,26 +1,29 @@ package fr.icdc.ebad.service; import fr.icdc.ebad.config.properties.EbadProperties; +import jakarta.mail.MessagingException; +import jakarta.mail.Session; +import jakarta.mail.internet.MimeMessage; import org.junit.Before; import org.junit.Test; -import org.junit.jupiter.api.BeforeEach; import org.junit.runner.RunWith; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.beans.factory.ObjectProvider; import org.springframework.mail.MailException; import org.springframework.mail.javamail.JavaMailSender; import org.thymeleaf.context.Context; -import org.thymeleaf.spring5.SpringTemplateEngine; - -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.internet.MimeMessage; -import java.io.IOException; +import org.thymeleaf.spring6.SpringTemplateEngine; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class MailServiceTest { @@ -69,4 +72,4 @@ public void testMail() throws MessagingException { assertEquals("EBAD - Demande accréditation en attente", mimeMessage.getSubject()); } -} \ No newline at end of file +} diff --git a/src/test/java/fr/icdc/ebad/service/jpa/BatchServiceJpaTest.java b/src/test/java/fr/icdc/ebad/service/jpa/BatchServiceJpaTest.java index 045c8a00..94f19880 100644 --- a/src/test/java/fr/icdc/ebad/service/jpa/BatchServiceJpaTest.java +++ b/src/test/java/fr/icdc/ebad/service/jpa/BatchServiceJpaTest.java @@ -2,9 +2,19 @@ import com.querydsl.core.types.dsl.BooleanExpression; import fr.icdc.ebad.config.Constants; -import fr.icdc.ebad.domain.*; +import fr.icdc.ebad.domain.Application; +import fr.icdc.ebad.domain.Authority; +import fr.icdc.ebad.domain.Batch; +import fr.icdc.ebad.domain.Environnement; +import fr.icdc.ebad.domain.Identity; +import fr.icdc.ebad.domain.Norme; +import fr.icdc.ebad.domain.QBatch; +import fr.icdc.ebad.domain.UsageApplication; +import fr.icdc.ebad.domain.UsageApplicationId; +import fr.icdc.ebad.domain.User; import fr.icdc.ebad.repository.BatchRepository; import fr.icdc.ebad.service.BatchService; +import jakarta.persistence.EntityManager; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -16,8 +26,6 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; -import javax.persistence.EntityManager; - import static org.junit.Assert.assertEquals; diff --git a/src/test/java/fr/icdc/ebad/web/rest/ExceptionTranslatorTest.java b/src/test/java/fr/icdc/ebad/web/rest/ExceptionTranslatorTest.java index 028f3b88..52d0ff64 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/ExceptionTranslatorTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/ExceptionTranslatorTest.java @@ -11,7 +11,11 @@ import fr.icdc.ebad.web.rest.dto.ApplicationDto; import fr.icdc.ebad.web.rest.dto.NormeDto; import fr.icdc.ebad.web.rest.errors.ExceptionTranslator; -import org.hibernate.validator.internal.engine.ConstraintViolationImpl; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.ConstraintViolationException; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import jakarta.validation.ValidatorFactory; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,12 +35,6 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import javax.management.RuntimeMBeanException; -import javax.persistence.EntityNotFoundException; -import javax.validation.ConstraintViolation; -import javax.validation.ConstraintViolationException; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.ValidatorFactory; import java.util.Locale; import java.util.Set; @@ -44,7 +42,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -164,7 +161,7 @@ public void testHandleHttpMessageNotReadable() throws Exception { @WithMockUser(roles = {"ADMIN"}) public void testHandleEntityNotFound() throws Exception { MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.put("/norms").content("{\"name\": \"toto\"}").contentType("application/json"); - when(normeService.saveNorme(any())).thenThrow(EntityNotFoundException.class); + when(normeService.saveNorme(any())).thenThrow(javax.persistence.EntityNotFoundException.class); restMvc.perform(builder) .andExpect(status().isNotFound()) .andExpect(jsonPath("$.apierror.message", is("Unexpected error"))); diff --git a/src/test/java/fr/icdc/ebad/web/rest/NotificationResourceTest.java b/src/test/java/fr/icdc/ebad/web/rest/NotificationResourceTest.java index 52bdcb9d..fa3de44c 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/NotificationResourceTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/NotificationResourceTest.java @@ -1,5 +1,7 @@ package fr.icdc.ebad.web.rest; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import fr.icdc.ebad.config.Constants; import fr.icdc.ebad.domain.Notification; import fr.icdc.ebad.repository.NotificationRepository; @@ -12,6 +14,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; @@ -46,11 +49,16 @@ public class NotificationResourceTest { private NotificationResource notificationResource; private MockMvc restMvc; + private ObjectMapper objectMapper = new ObjectMapper(); + @Before public void setup() { MockitoAnnotations.initMocks(this); - this.restMvc = MockMvcBuilders.standaloneSetup(notificationResource).build(); + this.restMvc = MockMvcBuilders + .standaloneSetup(notificationResource) + .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) + .build(); } @Test diff --git a/src/test/java/fr/icdc/ebad/web/rest/WebsocketTest.java b/src/test/java/fr/icdc/ebad/web/rest/WebsocketTest.java index 0d7fe6c2..f2ebac4b 100644 --- a/src/test/java/fr/icdc/ebad/web/rest/WebsocketTest.java +++ b/src/test/java/fr/icdc/ebad/web/rest/WebsocketTest.java @@ -3,12 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import fr.icdc.ebad.config.Constants; -import fr.icdc.ebad.domain.Authority; import fr.icdc.ebad.domain.Environnement; import fr.icdc.ebad.domain.Terminal; import fr.icdc.ebad.domain.User; -import fr.icdc.ebad.repository.TerminalRepository; -import fr.icdc.ebad.repository.UserRepository; import fr.icdc.ebad.security.jwt.TokenProvider; import fr.icdc.ebad.security.permission.PermissionEnvironnement; import fr.icdc.ebad.security.permission.PermissionServiceOpen; @@ -21,13 +18,9 @@ import org.apache.sshd.client.channel.ChannelShell; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.session.Session; -import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -53,26 +46,18 @@ import org.springframework.web.socket.WebSocketHttpHeaders; import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.messaging.WebSocketStompClient; -import org.springframework.web.socket.sockjs.client.SockJsClient; -import org.springframework.web.socket.sockjs.client.Transport; -import org.springframework.web.socket.sockjs.client.WebSocketTransport; -import javax.security.auth.login.LoginContext; import java.io.OutputStream; import java.lang.reflect.Type; -import java.net.URISyntaxException; import java.security.Principal; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; diff --git a/src/test/resources/config/application-test.yml b/src/test/resources/config/application-test.yml index 5ccf454d..b00966c0 100644 --- a/src/test/resources/config/application-test.yml +++ b/src/test/resources/config/application-test.yml @@ -15,6 +15,7 @@ spring: driverClassName: org.h2.Driver username: password: + security.oauth2.resourceserver.jwt.jwk-set-uri: http://localhost jpa: database-platform: org.hibernate.dialect.H2Dialect From 373ba281766d169bb3ce89a2f366bd03f6e8b99f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 Jul 2024 23:45:42 +0200 Subject: [PATCH 2/6] build(deps): bump org.bouncycastle:bcprov-jdk15to18 from 1.73 to 1.78 (#513) Bumps [org.bouncycastle:bcprov-jdk15to18](https://github.com/bcgit/bc-java) from 1.73 to 1.78. - [Changelog](https://github.com/bcgit/bc-java/blob/main/docs/releasenotes.html) - [Commits](https://github.com/bcgit/bc-java/commits) --- updated-dependencies: - dependency-name: org.bouncycastle:bcprov-jdk15to18 dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5fccf74c..5da75ef2 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ org.bouncycastle bcprov-jdk15to18 - 1.73 + 1.78 org.bouncycastle From 0d40ca6e01ab2c55e025a0f73783c876a35ad467 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 Jul 2024 23:46:00 +0200 Subject: [PATCH 3/6] build(deps): bump com.querydsl:querydsl-apt from 5.0.0 to 5.1.0 (#509) Bumps com.querydsl:querydsl-apt from 5.0.0 to 5.1.0. --- updated-dependencies: - dependency-name: com.querydsl:querydsl-apt dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5da75ef2..259c3201 100644 --- a/pom.xml +++ b/pom.xml @@ -391,7 +391,7 @@ com.querydsl querydsl-apt jakarta - 5.0.0 + 5.1.0 com.querydsl From 4a9410230cdfa2438fdc1453ec36ec9b740a83f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 Jul 2024 23:49:29 +0200 Subject: [PATCH 4/6] build(deps): bump com.sun.xml.bind:jaxb-impl from 4.0.3 to 4.0.5 (#510) Bumps com.sun.xml.bind:jaxb-impl from 4.0.3 to 4.0.5. --- updated-dependencies: - dependency-name: com.sun.xml.bind:jaxb-impl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Damien Trouillet <4112390+dtrouillet@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 259c3201..8578fbd0 100644 --- a/pom.xml +++ b/pom.xml @@ -194,7 +194,7 @@ com.sun.xml.bind jaxb-impl - 4.0.3 + 4.0.5 com.fasterxml.jackson.module From 83e109329660dbf93800532915c8d80578cc6416 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 Jul 2024 23:51:27 +0200 Subject: [PATCH 5/6] build(deps): bump org.pf4j:pf4j from 3.9.0 to 3.12.0 (#493) Bumps [org.pf4j:pf4j](https://github.com/pf4j/pf4j) from 3.9.0 to 3.12.0. - [Release notes](https://github.com/pf4j/pf4j/releases) - [Changelog](https://github.com/pf4j/pf4j/blob/master/CHANGELOG.md) - [Commits](https://github.com/pf4j/pf4j/compare/release-3.9.0...release-3.12.0) --- updated-dependencies: - dependency-name: org.pf4j:pf4j dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8578fbd0..bec8e127 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ ${project.build.directory}/test-results 0.8.0 5.3.1 - 3.9.0 + 3.12.0 From d173f913d74c359957907e00abb1f0549c230d94 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 Jul 2024 23:51:51 +0200 Subject: [PATCH 6/6] build(deps): bump org.pf4j:pf4j-spring from 0.8.0 to 0.9.0 (#495) Bumps [org.pf4j:pf4j-spring](https://github.com/pf4j/pf4j-spring) from 0.8.0 to 0.9.0. - [Release notes](https://github.com/pf4j/pf4j-spring/releases) - [Changelog](https://github.com/pf4j/pf4j-spring/blob/master/CHANGELOG.md) - [Commits](https://github.com/pf4j/pf4j-spring/compare/release-0.8.0...release-0.9.0) --- updated-dependencies: - dependency-name: org.pf4j:pf4j-spring dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bec8e127..3dbc9e55 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ 2.5.0.RELEASE 7.0.0.CR1 ${project.build.directory}/test-results - 0.8.0 + 0.9.0 5.3.1 3.12.0