我正在尝试过滤一些 url 模式以进行缓存。
我尝试的是将一些代码放入 WebSecurityConfigurerAdapter
实现中。
@Override
protected void configure(HttpSecurity http) throws Exception {
initSecurityConfigService();
// For cache
http.headers().defaultsDisabled()
.cacheControl()
.and().frameOptions();
securityConfigService.configure(http,this);
}
但是这段代码会影响所有的网络应用程序。我如何将其应用于某些 URL
或 Content-Type
,例如 images
。
我已经尝试过使用 RegexRequestMatcher
,但它对我不起作用。
// For cache
http.requestMatcher(new RegexRequestMatcher("/page/", "GET"))
.headers().defaultsDisabled()
.cacheControl()
.and().frameOptions();
我读了这篇文章:SpringSecurityResponseHeaders , 但没有这种情况的样本。
谢谢。
附言简而言之,我想删除某些 url 和资源的 SpringSecurity defaults
。
最佳答案
拥有多个 WebSecurityConfigurerAdapter 怎么样?一个适配器可以对某些 URL 进行缓存控制,而另一个适配器不会对这些 URL 启用缓存控制。
关于spring security - 如何删除某些 url 模式中的缓存控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42638687/