【发布时间】:2021-06-19 12:55:45
【问题描述】:
我有 REST 服务和静态页面,它们都是由我的 Spring Boot 应用程序提供的。
应用程序操作将在 /myapp 下进行,而在 /myapp/api 下有一些受过滤器保护的服务。 过滤器需要一个 cookie。
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/**")
.permitAll()
.and()
.addFilter(new CookieFilter(...));
}
'root-context (/myapp) 中未受保护的页面没有 cookie。
如何配置静态页面被 Spring 安全“忽略”?静态页面下方的 REST 端点是否经过安全检查?
当我尝试通过网络安全为“排除”配置静态页面时,/myapp/api 下的所有 REST 端点也会被忽略
@Override
public void configure(final WebSecurity web) {
web.ignoring()
.antMatchers("/");
}
如果我配置了 permitAll():
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/").permitAll();
http.authorizeRequests()
.antMatchers("/api/**")
.permitAll()
.and()
.addFilter(new CookieFilter(...));
}
Spring security 报我的安全过滤器无法检查静态页面,所以进行了授权。
【问题讨论】:
标签: spring-boot spring-security