Skip to content

Commit 0233178

Browse files
committed
Use explicit matchers following Spring Security 6.0.5 upgrade
See gh-36293
1 parent 12011fb commit 0233178

File tree

1 file changed

+9
-4
lines changed
  • spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity

1 file changed

+9
-4
lines changed

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SecurityConfiguration.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
import org.springframework.security.core.userdetails.UserDetails;
3232
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
3333
import org.springframework.security.web.SecurityFilterChain;
34+
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
35+
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
36+
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
3437

3538
@Configuration(proxyBeanMethods = false)
3639
public class SecurityConfiguration {
@@ -54,16 +57,18 @@ private UserDetails createUserDetails(String username, String password, String..
5457
}
5558

5659
@Bean
57-
SecurityFilterChain configure(HttpSecurity http) throws Exception {
60+
SecurityFilterChain configure(HttpSecurity http, HandlerMappingIntrospector handlerMappingIntrospector)
61+
throws Exception {
5862
http.authorizeHttpRequests((requests) -> {
59-
requests.requestMatchers("/actuator/beans").hasRole("BEANS");
63+
requests.requestMatchers(new MvcRequestMatcher(handlerMappingIntrospector, "/actuator/beans"))
64+
.hasRole("BEANS");
6065
requests.requestMatchers(EndpointRequest.to("health")).permitAll();
6166
requests.requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class))
6267
.hasRole("ACTUATOR");
6368
requests.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();
6469
requests.requestMatchers("/foo").permitAll();
65-
requests.requestMatchers("/error").permitAll();
66-
requests.requestMatchers("/**").hasRole("USER");
70+
requests.requestMatchers(new AntPathRequestMatcher("/error")).permitAll();
71+
requests.requestMatchers(new AntPathRequestMatcher("/**")).hasRole("USER");
6772
});
6873
http.cors(Customizer.withDefaults());
6974
http.httpBasic();

0 commit comments

Comments
 (0)