Skip to content

Commit

Permalink
test: Replace deprecated methods of Spring Security with new alternat…
Browse files Browse the repository at this point in the history
…ives

Fixes #100
  • Loading branch information
wimdeblauwe committed Sep 18, 2024
1 parent d5dab38 commit ccb5bc5
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit ccb5bc5

Please sign in to comment.