我想过滤一些网址格式缓存。 我所尝试的是将一些代码放入WebSecurityConfigurerAdapter
的实现中。春季安全 - 如何删除特定网址格式的缓存控制
@Override
protected void configure(HttpSecurity http) throws Exception {
initSecurityConfigService();
// For cache
http.headers().defaultsDisabled()
.cacheControl()
.and().frameOptions();
securityConfigService.configure(http,this);
}
但是这段代码会影响所有的web应用程序。我该如何将此应用于某些URL
或Content-Type
,如images
。
我已经试过RegexRequestMatcher
,但它不适用于我。
// For cache
http.requestMatcher(new RegexRequestMatcher("/page/", "GET"))
.headers().defaultsDisabled()
.cacheControl()
.and().frameOptions();
我看过这篇文章:SpringSecurityResponseHeaders,但这里没有样本。
感谢。
P.S.总之,我想为某些网址和资源删除SpringSecurity defaults
。
也许我不明白你的问题。既然你想为一般的请求添加缓存控制,为什么Spring Security会涉及这个?你可以尝试添加一个过滤器吗? – Simon
@Simon安全性默认设置应该适用于一般性调用,但我只希望该选项只适用于'image/*'类型。这就是为什么我想分开这些选项。 –
我明白这一点,但对我来说,这是非常简单的过滤器,你可以设置一些url模式(在你的情况下图像/ *)来过滤。您只需在响应中设置一些标题,然后设置所有内容。如果你更喜欢Spring Security,它有过滤链,你只需在最后一个过滤器后面添加一个过滤器并设置响应 – Simon