Allow actuator endpoints to be used with mvcMatchers
This commit changes AbstractWebMvcEndpointHandlerMapping to be a MatchableHandlerMapping. Additionally, EndpointRequest, now delegates to MvcRequestMatcher for Spring MVC applications. For all other applications, AntPathRequestMatcher is used as a delegate. Closes gh-13962
This commit is contained in:
@@ -35,6 +35,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
return new InMemoryUserDetailsManager(
|
||||
User.withDefaultPasswordEncoder().username("user").password("password")
|
||||
.authorities("ROLE_USER").build(),
|
||||
User.withDefaultPasswordEncoder().username("beans").password("beans")
|
||||
.authorities("ROLE_BEANS").build(),
|
||||
User.withDefaultPasswordEncoder().username("admin").password("admin")
|
||||
.authorities("ROLE_ACTUATOR", "ROLE_USER").build());
|
||||
}
|
||||
@@ -43,6 +45,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// @formatter:off
|
||||
http.authorizeRequests()
|
||||
.mvcMatchers("/actuator/beans").hasRole("BEANS")
|
||||
.requestMatchers(EndpointRequest.to("health", "info")).permitAll()
|
||||
.requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class)).hasRole("ACTUATOR")
|
||||
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
|
||||
|
||||
Reference in New Issue
Block a user