【发布时间】:2016-02-09 17:17:19
【问题描述】:
我正在使用 spring-boot 和 spring-security。
我有一个通用的WebSecurityConfigurerAdapter 设置用于许多不同的项目。问题是我想要每个项目的自定义控制器安全性,其他一切都保持不变。最明显的解决方案是将其抽象化并强制每个项目对其进行扩展,但我怀疑有更好的方法来处理事件或其他东西。
这里是WebSecurityConfigurerAdapter的配置方法
@Override
protected void configure(final HttpSecurity http) throws Exception {
...
http.authorizeRequests()
.antMatchers("/health*").permitAll()
.antMatchers("/endpoints/**").permitAll()
.antMatchers("/rest/open/**").permitAll()
.antMatchers("/login/impersonate*").hasAnyRole("ADMIN", "ADMINISTRATOR")
// AT THIS POINT I WOULD LIKE EACH PROJECT TO OPTIONALLY CONFIGURE http AS THEY WISH
http.authorizeRequests().antMatchers("/**").authenticated();
...
}
春季有没有很酷的方法可以通过 bean 配置或其他方式做到这一点?
@Bean //something like this perhaps????
public void configureSecurity(final HttpSecurity http) {
http.authorizeRequests()
.antMatchers("/rest/admin*").hasAnyRole("ADMIN", "ADMINISTRATOR")
}
【问题讨论】:
标签: spring spring-boot