如果需要配置多个
HttpSecurity
在您的应用程序中,
HttpSecurity.requestMatchers()
或其他(但类似)配置选项之一:
HttpSecurity.requestMatcher(RequestMatcher)
HttpSecurity.antMatcher(String)
HttpSecurity.mvcMatcher(String)
HttpSecurity.regexMatcher(String)
例如,如果应用程序在基本路径上有一组API的根
/api
以及应用程序的管理部分的另一类终结点,根位于基路径
/admin
比你可能定义的2x
WebSecurityConfigurerAdapter
对于您的申请:
@EnableWebSecurity
public class SecurityConfig {
@Configuration
@Order(1)
public static class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.requestMatchers()
.antMatchers("/api/**")
.and()
.authorizeRequests()
.antMatchers("/api/endpoint1")
.hasRol