JAVA-14680 Update spring-boot-admin module under spring-boot-modules to remove usage of deprecated WebSecurityConfigurerAdapter (#12732)

This commit is contained in:
anuragkumawat 2022-09-18 10:32:09 +05:30 committed by GitHub
parent fe187e8f98
commit 919da4dfe6
1 changed files with 6 additions and 4 deletions

View File

@ -2,11 +2,12 @@ package com.baeldung.springbootadminserver.configs;
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.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.web.SecurityFilterChain;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@ -15,15 +16,15 @@ import de.codecentric.boot.admin.server.config.AdminServerProperties;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public class WebSecurityConfig {
private final AdminServerProperties adminServer;
public WebSecurityConfig(AdminServerProperties adminServer) {
this.adminServer = adminServer;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(this.adminServer.getContextPath() + "/");
@ -54,5 +55,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.key(UUID.randomUUID()
.toString())
.tokenValiditySeconds(1209600);
return http.build();
}
}