mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge branch '3.0.x' into 3.1.x
This commit is contained in:
commit
30cc2a48c7
@ -30,6 +30,9 @@ import org.springframework.security.core.userdetails.User.UserBuilder;
|
|||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
||||||
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||||
|
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
|
||||||
|
|
||||||
import static org.springframework.security.config.Customizer.withDefaults;
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
@ -55,16 +58,18 @@ public class SecurityConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
SecurityFilterChain configure(HttpSecurity http) throws Exception {
|
SecurityFilterChain configure(HttpSecurity http, HandlerMappingIntrospector handlerMappingIntrospector)
|
||||||
|
throws Exception {
|
||||||
http.authorizeHttpRequests((requests) -> {
|
http.authorizeHttpRequests((requests) -> {
|
||||||
requests.requestMatchers("/actuator/beans").hasRole("BEANS");
|
requests.requestMatchers(new MvcRequestMatcher(handlerMappingIntrospector, "/actuator/beans"))
|
||||||
|
.hasRole("BEANS");
|
||||||
requests.requestMatchers(EndpointRequest.to("health")).permitAll();
|
requests.requestMatchers(EndpointRequest.to("health")).permitAll();
|
||||||
requests.requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class))
|
requests.requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class))
|
||||||
.hasRole("ACTUATOR");
|
.hasRole("ACTUATOR");
|
||||||
requests.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();
|
requests.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();
|
||||||
requests.requestMatchers("/foo").permitAll();
|
requests.requestMatchers("/foo").permitAll();
|
||||||
requests.requestMatchers("/error").permitAll();
|
requests.requestMatchers(new AntPathRequestMatcher("/error")).permitAll();
|
||||||
requests.requestMatchers("/**").hasRole("USER");
|
requests.requestMatchers(new AntPathRequestMatcher("/**")).hasRole("USER");
|
||||||
});
|
});
|
||||||
http.cors(withDefaults());
|
http.cors(withDefaults());
|
||||||
http.httpBasic(withDefaults());
|
http.httpBasic(withDefaults());
|
||||||
|
Loading…
Reference in New Issue
Block a user