当前位置: 首页 > news >正文

HTTPS请求头缺少HttpOnly和Secure属性解决方案

问题描述:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
建立Filter拦截器类

package com.ruoyi.framework.security.filter;import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Component;import javax.servlet.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;/*** token过滤器 验证token有效性** @author ruoyi*/
@Component
public class JwtAuthenticationTokenFilter implements Filter {@Autowiredprivate TokenService tokenService;@Value("${token.expireTime}")private int expireTime;@Overridepublic void init(FilterConfig filterConfig) throws ServletException {}@Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest) servletRequest;HttpServletResponse response = (HttpServletResponse) servletResponse;LoginUser loginUser = tokenService.getLoginUser(request);if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) {tokenService.verifyToken(loginUser);UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));SecurityContextHolder.getContext().setAuthentication(authenticationToken);Cookie[] cookies = request.getCookies();if (cookies != null) {for (Cookie cookie : cookies) {String value = cookie.getValue();String builder = "JSESSIONID=" + value + "; " +"Secure; " +"HttpOnly; " +"Expires=" + expireTime;response.setHeader("Set-Cookie", builder);}}}filterChain.doFilter(request, response);}@Overridepublic void destroy() {}}

在这里插入图片描述

http://www.lryc.cn/news/401791.html

相关文章:

  • react基础样式控制
  • 【区块链 + 智慧政务】涉税行政事业性收费“e 链通”项目 | FISCO BCOS应用案例
  • Socket、WebSocket 和 MQTT 的区别
  • 企业网络实验(vmware虚拟机充当DHCP服务器)所有IP全部保留,只为已知mac分配固定IP
  • HouseCrafter:平面草稿至3D室内场景的革新之旅
  • C#统一委托Func与Action
  • MongoDB 基本查询语句
  • 28_EfficientNetV2网络详解
  • PyCharm查看文件或代码变更记录
  • Java开发手册中-避免Random实例被多线程使用、多线程下Random与ThreadLoacalRandom性能对比
  • 【Arduino IDE】安装及开发环境、ESP32库
  • 【C++开源】GuiLite:超轻量UI框架-入门
  • SQL面试题练习 —— 查询每个用户最大连续登录天数
  • 服务器系统盘存储不够,添加数据盘并挂载(阿里云)
  • Visual Studio2022中使用.Net 8 在 Windows 下使用 Worker Service 创建守护进程
  • HTML5应用的安全防护策略与实践
  • 堆叠和集群
  • 【5G Sub-6GHz模块】专为IoT/eMBB应用而设计的RG520NNA、RG520FEB、RG530FNA、RG500LEU 5G模组
  • 云计算监控减少网络安全事件的五种方法
  • java之 junit单元测试案例【经典版】
  • Golang面试题整理(持续更新...)
  • uni-app:文字竖直排列,并且在父级view中水平竖直对齐
  • Linux 中停止 Docker 服务报 warning 导致无法彻底停止问题如何解决?
  • Git 用法
  • 《昇思25天学习打卡营第20天|GAN图像生成》
  • 【字幕】字幕特效入门
  • Ubuntu 24.04安装Jellyfin媒体服务器图解教程
  • css3 中的伪类和伪元素
  • 人工智能导论-知识图谱
  • LabVIEW液压数据采集测试系统