JAVA-31190: Preparation for migrating spring-boot-modules to version 3. (#15834)

This commit is contained in:
Harry9656
2024-02-27 02:49:02 +01:00
committed by GitHub
parent 74da22b9c4
commit aefd833c3b
190 changed files with 1052 additions and 832 deletions
@@ -25,13 +25,13 @@
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${spring-boot-admin-server.version}</version>
<version>${spring-boot.version}</version>
</dependency>
<!--Add login page and logout feature -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui-login</artifactId>
<version>${spring-boot-admin-server-ui-login.version}</version>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -45,7 +45,7 @@
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring-boot-admin-starter-client.version}</version>
<version>${spring-boot.version}</version>
</dependency>
<!--mail notifications -->
<dependency>
@@ -69,16 +69,8 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-maven-plugin.version}</version>
</plugin>
</plugins>
</build>
<properties>
<spring-boot-admin-server.version>2.4.1</spring-boot-admin-server.version>
<spring-boot-admin-starter-client.version>2.4.1</spring-boot-admin-starter-client.version>
<spring-boot-admin-server-ui-login.version>1.5.7</spring-boot-admin-server-ui-login.version>
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
</properties>
</project>
@@ -5,6 +5,7 @@ import java.util.UUID;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
@@ -17,6 +18,7 @@ import de.codecentric.boot.admin.server.config.AdminServerProperties;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
private final AdminServerProperties adminServer;
public WebSecurityConfig(AdminServerProperties adminServer) {
@@ -29,32 +31,24 @@ public class WebSecurityConfig {
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(this.adminServer.getContextPath() + "/");
http.authorizeRequests()
.antMatchers(this.adminServer.getContextPath() + "/assets/**")
.permitAll()
.antMatchers(this.adminServer.getContextPath() + "/login")
.permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage(this.adminServer.getContextPath() + "/login")
.successHandler(successHandler)
.and()
.logout()
.logoutUrl(this.adminServer.getContextPath() + "/logout")
.and()
.httpBasic()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringRequestMatchers(new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances", HttpMethod.POST.toString()), new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances/*", HttpMethod.DELETE.toString()),
new AntPathRequestMatcher(this.adminServer.getContextPath() + "/actuator/**"))
.and()
.rememberMe()
.key(UUID.randomUUID()
.toString())
.tokenValiditySeconds(1209600);
http.authorizeHttpRequests(req -> req.requestMatchers(this.adminServer.getContextPath() + "/assets/**")
.permitAll()
.requestMatchers(this.adminServer.getContextPath() + "/login")
.permitAll()
.anyRequest()
.authenticated())
.formLogin(formLogin -> formLogin.loginPage(this.adminServer.getContextPath() + "/login")
.successHandler(successHandler))
.logout((logout) -> logout.logoutUrl(this.adminServer.getContextPath() + "/logout"))
.httpBasic(Customizer.withDefaults())
.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringRequestMatchers(
new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances", HttpMethod.POST.toString()),
new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances/*", HttpMethod.DELETE.toString()),
new AntPathRequestMatcher(this.adminServer.getContextPath() + "/actuator/**")))
.rememberMe(rememberMe -> rememberMe.key(UUID.randomUUID()
.toString())
.tokenValiditySeconds(1209600));
return http.build();
}
}
@@ -52,7 +52,7 @@ public class WebSecurityConfigIntegrationTest {
.password("admin"));
mockMvc
.perform(get("/applications/"))
.perform(get("/applications"))
.andExpect(status().is2xxSuccessful());
}