Skip to content

Commit 30cc2a4

Browse files
committed
Merge branch '3.0.x' into 3.1.x
2 parents e3c238d + 0233178 commit 30cc2a4

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
@@ -30,6 +30,9 @@
3030
import org.springframework.security.core.userdetails.UserDetails;
3131
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
3232
import org.springframework.security.web.SecurityFilterChain;
33+
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
34+
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
35+
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
3336

3437
import static org.springframework.security.config.Customizer.withDefaults;
3538

@@ -55,16 +58,18 @@ private UserDetails createUserDetails(String username, String password, String..
5558
}
5659

5760
@Bean
58-
SecurityFilterChain configure(HttpSecurity http) throws Exception {
61+
SecurityFilterChain configure(HttpSecurity http, HandlerMappingIntrospector handlerMappingIntrospector)
62+
throws Exception {
5963
http.authorizeHttpRequests((requests) -> {
60-
requests.requestMatchers("/actuator/beans").hasRole("BEANS");
64+
requests.requestMatchers(new MvcRequestMatcher(handlerMappingIntrospector, "/actuator/beans"))
65+
.hasRole("BEANS");
6166
requests.requestMatchers(EndpointRequest.to("health")).permitAll();
6267
requests.requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class))
6368
.hasRole("ACTUATOR");
6469
requests.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();
6570
requests.requestMatchers("/foo").permitAll();
66-
requests.requestMatchers("/error").permitAll();
67-
requests.requestMatchers("/**").hasRole("USER");
71+
requests.requestMatchers(new AntPathRequestMatcher("/error")).permitAll();
72+
requests.requestMatchers(new AntPathRequestMatcher("/**")).hasRole("USER");
6873
});
6974
http.cors(withDefaults());
7075
http.httpBasic(withDefaults());

0 commit comments

Comments
 (0)