spring security 4 http资源无法静态资源缓存设置

阅读更多
spring security 4 对比spring security 3 对http缓存进行了禁止,需要开启,才能进行http静态资源缓存。

看官方文档

In the past Spring Security required you to provide your own cache control for your web application. This seemed reasonable at the time, but browser caches have evolved to include caches for secure connections as well. This means that a user may view an authenticated page, log out, and then a malicious user can use the browser history to view the cached page. To help mitigate this Spring Security has added cache control support which will insert the following headers into you response.
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0

Simply adding the element with no child elements will automatically add Cache Control and quite a few other protections. However, if you only want cache control, you can enable this feature using Spring Security’s XML namespace with the element and the headers@defaults-disabled attribute.


	

	
		
	


@EnableWebSecurity
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
	http
	// ...
	.headers()
		.defaultsDisabled()
		.cacheControl();
}
}


解决方案:
1. 直接关闭header 的设置


2.开启缓存

	

你可能感兴趣的:(缓存,http,静态资源)