`

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 <headers> 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 <cache-control> element and the headers@defaults-disabled attribute.

<http>
	<!-- ... -->

	<headers defaults-disable="true">
		<cache-control />
	</headers>
</http>


@EnableWebSecurity
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {

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


解决方案:
1. 直接关闭header 的设置
<headers disabled="true" />

2.开启缓存
<headers>
	<cache-control disabled="true"/>
</headers>
分享到:
评论

相关推荐

    spring security 参考手册中文版

    12.1设置MockMvc和Spring Security 104 12.2 SecurityMockMvcRequestPostProcessors 105 12.2.1使用CSRF保护进行测试 105 12.2.2在Spring MVC测试中以用户身份运行测试 106 12.2.3使用RequestPostProcessor在Spring ...

    基于SpringBoot+Mybatis+SpringSecurity+Redis+ElasticSe的个人博客系统(源码)

    基于RBAC模型构建权限管理模块,并集成安全框架SpringSecurity,实现用户的认证和授权。 使用Spring Data集成缓存中间件Redis,加快访问速度。 使用Spring Data集成全文搜索搜索引擎ElasticSearch,实现文章信息的...

    在Spring Boot中实现HTTP缓存的方法

    缓存是HTTP协议的一个强大功能,但由于某些原因,它主要用于静态资源,如图像,CSS样式表或JavaScript文件。本文重点给大家介绍在Spring Boot中实现HTTP缓存的方法,感兴趣的朋友跟随小编一起看看吧

    JavaEE开发的颠覆者SpringBoot实战[完整版].part3

    4.4.1 静态资源映射 88 4.4.2 拦截器配置 89 4.4.3 @ControllerAdvice 91 4.4.4 其他配置 94 4.5 Spring MVC 的高级配置 98 4.5.1 文件上传配置 98 4.5.2 自定义HttpMessageConverter 101 4.5.3 服务器端推送技术 ...

    JavaEE开发的颠覆者SpringBoot实战[完整版].part2

    4.4.1 静态资源映射 88 4.4.2 拦截器配置 89 4.4.3 @ControllerAdvice 91 4.4.4 其他配置 94 4.5 Spring MVC 的高级配置 98 4.5.1 文件上传配置 98 4.5.2 自定义HttpMessageConverter 101 4.5.3 服务器端推送技术 ...

    JavaEE开发的颠覆者SpringBoot实战[完整版].part1

    4.4.1 静态资源映射 88 4.4.2 拦截器配置 89 4.4.3 @ControllerAdvice 91 4.4.4 其他配置 94 4.5 Spring MVC 的高级配置 98 4.5.1 文件上传配置 98 4.5.2 自定义HttpMessageConverter 101 4.5.3 服务器端推送技术 ...

    2019品优购.txt

    技术选型 前端:angularJS + Bootstrap 后台:SSM( springmvc+...SpringSecurity, 跨域:cro s 支付:微信扫描 短信验证:阿里大于 密码加密:BCrypt 富文本:KindEditor 事务:声明式事务 任务调度:spring task

    黑马品优购电商项目全套资源

    前端:angularJS + Bootstrap 后台:SSM(springmvc +...权限管理:SpringSecurity, 跨域:cros 支付:微信扫描 短信验证:阿里大于 密码加密:BCrypt 富文本:KindEditor 事务:声明式事务 任务调度:spring task

    geek_blog:一个基于SpringBoot+Mybatis(MybatisPlus)+SpringSecurity+Redis+ElasticSearch的个人博客系统,预览地址:

    基于RBAC模型构建权限管理模块,并集成安全框架SpringSecurity,实现用户的认证和授权。 使用Spring Data集成缓存中间件Redis,加快访问速度。 使用Spring Data集成全文搜索搜索引擎ElasticSearch,实现文章信息的...

    一个基于Vue3&Springboot&Tensorflow的音视频会议系统(毕业设计)

    SpringSecurity + JWT 用户鉴权 Mybatisplus 持久化 Redis 缓存 netty-socketio 消息推送 swagger 生成接口文档 接口文档 http://localhost:8080/doc.html 配置文件 application.yaml 设置静态文件位置、AI端...

    geek_blog-front-v2.zip

    基于RBAC模型构建权限管理模块,并集成安全框架SpringSecurity,实现用户的认证和授权。 使用Spring Data集成缓存中间件Redis,加快访问速度。 使用Spring Data集成全文搜索搜索引擎ElasticSearch,实现文章信息的...

    黑马49期全系列包括品优购

    freemarker 单点登录:cas 权限管理:SpringSecurity, 跨域:cros 支付:微信扫描 短信验证:阿里大于 密码加密:BCrypt 富文本:KindEditor 事务:声明式事务 任务调度:spring task,有问题请留言

    基于Spring Boot的社区论坛项目源码+数据库+项目说明.zip

    - static文件夹:前端静态资源,需独立部署 ### 本地开发运行部署 - 下载zip直接解压或安装git后执行克隆命令 `git clone https://github.com/AatroxC/WeCommunity.git` - 安装各组件并启动:Redis、ZooKee

    基于SpringBoot+Vue前后端分离实现在线办公系统源码+数据库,实现了职位、职称、部门、操作员、员工、工资帐套管理及聊天

    使用Redis缓存存储菜单列表,使用SpringSecurity角色权限验证,使用WebSocket进行在线聊天,使用 FastDFS存储静态资源文件 实现的功能 实现了登录功能、职位管理、职称管理、部门管 理、操作员管理、员工管理、工资...

    MF00001-JAVA多用户B2B2C商城源码.zip

    使用Spring+JPA+Velocity+Ehcache作为基础开发架构,应用SpringSecurity框架管理系统权限,结合URL重写技术静态化商城前台页面。 Shopping结合多年的电商开发经验及主流电商的功能特点,注重系统易用性、功能性、...

    JAVA多用户B2B2C商城系统源码

    使用Spring+JPA+Velocity+Ehcache作为基础开发架构,应用SpringSecurity框架管理系统权限,结合URL重写技术静态化商城前台页面。 Shopping结合多年的电商开发经验及主流电商的功能特点,注重系统易用性、功能性、...

    人工智能-项目实践-信息检索-Java 分布式项(SSM、分布式Dubbo、全文检索Solr、Vue、Zookeeper、文件系

    Java 分布式项(SSM、分布式Dubbo、全文检索Solr、Vue、Zookeeper、文件系统FastDFS、缓存Redis、单点登录CAS,权限控制Spring Security,跨域CORS) 技术选型 后端框架采用 Spring + SpringMVC + MyBatis + DubboX...

    leaf

    用于静态资源(例如js,css,图片等)的缓存克星... Spock单元和集成测试。 将fluentlenium与htmlunit一起用于UI回归测试。 去做 新功能正在添加。 运行本地mongoDB 运行本地docker run --rm --name local-mongo ...

    java版商城源码下载-master:掌握

    --静态资源处理 技术选型 后端技术 技术 说明 官网 SpringBoot 容器+MVC框架 SpringSecurity 认证和授权框架 MyBatis ORM框架 MyBatisGenerator 数据层代码生成 PageHelper MyBatis物理分页插件 Swagger-UI 文档生产...

    java版商城源码下载-trymall:mall项目学习

    java版商城源码下载 TryMall 该项目旨在学习mall电商项目 组织结构 mall ├── mall-common -- 工具类及通用代码 ├── ...MyBatisGenerator生成的数据库操作代码 ...SpringSecurity封装...静态资源服务器 Docker 应用容

Global site tag (gtag.js) - Google Analytics