使用Spring安全过滤器锁定除少数路线之外的所有内容
我们正在重新设计我们的产品,以删除SpringSecurity中默认的“匿名用户”行为,并希望锁定所有URL(通过过滤器安全性),除了几个端点。我们无法弄清楚的是如何指定“锁定除X,Y和Z之外的所有内容”
我们的安全设置基本上可以归结为以下内容:
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// disable anonymous users
.anonymous().disable()
// don't add ROLE_ to the role...
.authorizeRequests()
.regexMatchers("^/", "^/login", "^/mobile/login", "^/api/auth/.*")
.authenticated()
.and()
;
}
}
我采取的其他路线类似于:
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// disable anonymous users
.anonymous().disable()
// don't add ROLE_ to the role...
.authorizeRequests()
.antMatchers("/**")
.authenticated()
.antMatchers("/", "/login", "/mobile/login", "/api/auth/**", "/reservations/**")
.permitAll()
.and()
;
}
}
任何建议/意见将不胜感激。
谢谢!