From 919da4dfe6c6acbb7cd8f4a3298f109e134dde98 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Sun, 18 Sep 2022 10:32:09 +0530 Subject: [PATCH] JAVA-14680 Update spring-boot-admin module under spring-boot-modules to remove usage of deprecated WebSecurityConfigurerAdapter (#12732) --- .../configs/WebSecurityConfig.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/WebSecurityConfig.java b/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/WebSecurityConfig.java index 1943c61ff4..fa421eadcd 100644 --- a/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/WebSecurityConfig.java +++ b/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/WebSecurityConfig.java @@ -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(); } }