From ccb5bc5ca9b1107e51031cadf7db2b369b9229e0 Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Wed, 18 Sep 2024 21:21:41 +0200 Subject: [PATCH] test: Replace deprecated methods of Spring Security with new alternatives Fixes #100 --- .../SpringSecurityApiExceptionHandlerTest.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandlerTest.java b/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandlerTest.java index 62f9db3..2613b46 100644 --- a/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandlerTest.java +++ b/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandlerTest.java @@ -17,6 +17,7 @@ import org.springframework.security.authentication.AccountExpiredException; 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.configurers.AbstractHttpConfigurer; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.access.AccessDeniedHandler; @@ -130,15 +131,15 @@ public AccessDeniedHandler accessDeniedHandler(HttpStatusMapper httpStatusMapper public SecurityFilterChain securityFilterChain(HttpSecurity http, UnauthorizedEntryPoint unauthorizedEntryPoint, AccessDeniedHandler accessDeniedHandler) throws Exception { - http.httpBasic().disable(); + http.httpBasic(AbstractHttpConfigurer::disable); - http.authorizeHttpRequests() - .requestMatchers("/test/spring-security/admin-global").hasRole("ADMIN") - .anyRequest().authenticated(); + http.authorizeHttpRequests(customizer -> customizer + .requestMatchers("/test/spring-security/admin-global").hasRole("ADMIN") + .anyRequest().authenticated()); - http.exceptionHandling() - .authenticationEntryPoint(unauthorizedEntryPoint) - .accessDeniedHandler(accessDeniedHandler); + http.exceptionHandling(customizer -> customizer + .authenticationEntryPoint(unauthorizedEntryPoint) + .accessDeniedHandler(accessDeniedHandler)); return http.build(); }