Skip to content

Commit

Permalink
Merge pull request #6342 from qmonmert/spring-boot310
Browse files Browse the repository at this point in the history
Spring-boot 3.1.0
  • Loading branch information
pascalgrimaud authored May 21, 2023
2 parents a56c027 + edf28c7 commit dd33534
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.and()
.springMainProperties()
.set(propertyKey("spring.data.mongodb.database"), propertyValue(properties.projectBaseName().get()))
.set(propertyKey("spring.data.mongodb.uri"), propertyValue("mongodb://localhost:27017"))
.set(propertyKey("spring.data.mongodb.uri"), propertyValue("mongodb://localhost:27017/" + properties.projectBaseName().get()))
.and()
.springTestProperties()
.set(propertyKey("spring.data.mongodb.uri"), propertyValue("${TEST_MONGODB_URI}"))
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/generator/dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<assertj.version>3.24.2</assertj.version>
<mockito.version>5.3.1</mockito.version>
<logstash-logback-encoder.version>7.3</logstash-logback-encoder.version>
<spring-boot.version>3.0.6</spring-boot.version>
<spring-boot.version>3.1.0</spring-boot.version>
<spring-cloud.version>2022.0.0</spring-cloud.version>
<spring-cloud-netflix-eureka-client.version>4.0.1</spring-cloud-netflix-eureka-client.version>
<springdoc-openapi-starter-webmvc.version>2.1.0</springdoc-openapi-starter-webmvc.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
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.WebSecurityCustomizer;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer.FrameOptionsConfig;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
Expand Down Expand Up @@ -59,26 +61,20 @@ class SecurityConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// @formatter:off
return http
.csrf()
.disable()
.addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class)
.headers()
.contentSecurityPolicy(properties.getContentSecurityPolicy())
.and()
.referrerPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN)
.and()
.permissionsPolicy().policy("camera=(), fullscreen=(self), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), sync-xhr=()")
.and()
.frameOptions()
.deny()
.and()
.formLogin().disable()
.httpBasic().disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeHttpRequests()
http
.csrf(csrf -> csrf.disable())
.addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class)
.headers(headers -> headers
.contentSecurityPolicy(csp -> csp.policyDirectives(properties.getContentSecurityPolicy()))
.frameOptions(FrameOptionsConfig::deny)
.referrerPolicy(referrer -> referrer.policy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN))
.permissionsPolicy(permissions ->
permissions.policy("camera=(), fullscreen=(self), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), sync-xhr=()"))
)
.formLogin(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(authz -> authz
.requestMatchers("/api/authenticate").permitAll()
.requestMatchers("/api/register").permitAll()
.requestMatchers("/api/activate").permitAll()
Expand All @@ -92,10 +88,11 @@ class SecurityConfiguration {
.requestMatchers("/management/prometheus").permitAll()
.requestMatchers("/management/**").hasAuthority(Role.ADMIN.key())
.anyRequest().authenticated()
.and()
.apply(new JWTConfigurer(authenticationTokenReader()))
.and()
.build();
);
JWTConfigurer jwtConfigurer = new JWTConfigurer(authenticationTokenReader());
http.apply(jwtConfigurer);
return http.build();
// @formatter:on
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
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.WebSecurityCustomizer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer.FrameOptionsConfig;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
Expand All @@ -35,6 +36,8 @@ import org.springframework.web.filter.CorsFilter;
import {{packageName}}.authentication.domain.Role;
import {{packageName}}.common.domain.Generated;

import static org.springframework.security.config.Customizer.withDefaults;

@Configuration
@EnableWebSecurity
@EnableMethodSecurity(prePostEnabled = true, securedEnabled = true)
Expand Down Expand Up @@ -75,40 +78,33 @@ public class SecurityConfiguration {
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// @formatter:off
return http
.csrf()
.disable()
.csrf(csrf -> csrf.disable())
.addFilterBefore(corsFilter, CsrfFilter.class)
.headers()
.contentSecurityPolicy(applicationSecurityProperties.getContentSecurityPolicy())
.and()
.referrerPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN)
.and()
.permissionsPolicy().policy("camera=(), fullscreen=(self), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), sync-xhr=()")
.and()
.frameOptions()
.sameOrigin()
.and()
.authorizeHttpRequests()
.requestMatchers("/api/authenticate").permitAll()
.requestMatchers("/api/auth-info").permitAll()
.requestMatchers("/api/admin/**").hasAuthority(Role.ADMIN.key())
.requestMatchers("/api/**").authenticated()
.requestMatchers("/management/health").permitAll()
.requestMatchers("/management/health/**").permitAll()
.requestMatchers("/management/info").permitAll()
.requestMatchers("/management/prometheus").permitAll()
.requestMatchers("/management/**").hasAuthority(Role.ADMIN.key())
.anyRequest().authenticated()
.and()
.oauth2Login()
.and()
.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(authenticationConverter())
.and()
.and()
.oauth2Client()
.and().build();
.headers(headers -> headers
.contentSecurityPolicy(csp -> csp.policyDirectives(applicationSecurityProperties.getContentSecurityPolicy()))
.frameOptions(FrameOptionsConfig::sameOrigin)
.referrerPolicy(referrer -> referrer.policy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN))
.permissionsPolicy(permissions ->
permissions.policy("camera=(), fullscreen=(self), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), sync-xhr=()"))
)
.authorizeHttpRequests(authz -> authz
.requestMatchers("/api/authenticate").permitAll()
.requestMatchers("/api/auth-info").permitAll()
.requestMatchers("/api/admin/**").hasAuthority(Role.ADMIN.key())
.requestMatchers("/api/**").authenticated()
.requestMatchers("/management/health").permitAll()
.requestMatchers("/management/health/**").permitAll()
.requestMatchers("/management/info").permitAll()
.requestMatchers("/management/prometheus").permitAll()
.requestMatchers("/management/**").hasAuthority(Role.ADMIN.key())
.anyRequest().authenticated()
)
.oauth2Login(withDefaults())
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(jwt -> jwt.jwtAuthenticationConverter(authenticationConverter()))
)
.oauth2Client(withDefaults())
.build();
// @formatter:on
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void shouldBuildModule() {
.and()
.hasFile("src/main/resources/config/application.properties")
.containing("spring.data.mongodb.database=jhipster")
.containing("spring.data.mongodb.uri=mongodb://localhost:27017")
.containing("spring.data.mongodb.uri=mongodb://localhost:27017/jhipster")
.and()
.hasFile("src/test/resources/config/application.properties")
.containing("spring.data.mongodb.uri=${TEST_MONGODB_URI}")
Expand Down

0 comments on commit dd33534

Please sign in to comment.