SpringSecurity分布式整合之验证认证的过滤器
编写检验token过滤器
public class JwtVerifyFilter extends BasicAuthenticationFilter {private RsaKeyProperties prop;public JwtVerifyFilter(AuthenticationManager authenticationManager, RsaKeyProperties prop) {super(authenticationManager);this.prop = prop;}public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {String header = request.getHeader("Authorization");if (header == null || !header.startsWith("Bearer ")) {//如果携带错误的token,则给用户提示请登录!chain.doFilter(request, response);response.setContentType("application/json;charset=utf-8");response.setStatus(HttpServletResponse.SC_FORBIDDEN);PrintWriter out = response.getWriter();Map resultMap = new HashMap();resultMap.put("code", HttpServletResponse.SC_FORBIDDEN);resultMap.put("msg", "请登录!");out.write(new ObjectMapper().writeValueAsString(resultMap));out.flush();out.close();} else {//如果携带了正确格式的token要先得到tokenString token = header.replace("Bearer ", "");//验证tken是否正确Payload<SysUser> payload = JwtUtils.getInfoFromToken(token, prop.getPublicKey(), SysUser.class);SysUser user = payload.getUserInfo();if(user!=null){UsernamePasswordAuthenticationToken authResult = new UsernamePasswordAuthenticationToken(user.getUsername(), null, user.getAuthorities());SecurityContextHolder.getContext().setAuthentication(authResult);chain.doFilter(request, response);}}}
}
SpringSecurity分布式整合之验证认证的过滤器相关推荐
- SpringSecurity分布式整合之资源服务器搭建和测试
资源服务 说明 资源服务可以有很多个,这里只拿产品服务为例,记住,资源服务中只能通过公钥验证认证.不能签发token! 创建产品服务并导入jar包 根据实际业务导包即可,咱们就暂时和认证服务一样了. ...
- SpringSecurity分布式整合之分布式认证流程说明
分布式认证概念说明 分布式认证,即我们常说的单点登录,简称SSO,指的是在多应用系统的项目中,用户只需要登录一次,就可以访 问所有互相信任的应用系统. 分布式认证流程图 首先,我们要明确,在分布式项目 ...
- SpringSecurity分布式整合之认证模块搭建
认证服务 创建认证服务工程并导入jar包 <?xml version="1.0" encoding="UTF-8"?> <project xm ...
- SpringSecurity分布式整合之实现思路分析
JWT相关工具类 jar包 <dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt ...
- SpringSecurity分布式整合之jwt和rsa说明
JWT介绍 概念说明 从分布式认证流程中,我们不难发现,这中间起最关键作用的就是token,token的安全与否,直接关系到系统的 健壮性,这里我们选择使用JWT来实现token的生成和校验. JWT ...
- SpringSecurity分布式整合之认证服务配置文件编写和测试
编写SpringSecurity配置类 @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(securedEnabled=tru ...
- SpringSecurity分布式整合之common工具模块创建
通用模块 创建通用子模块并导入JWT相关jar包 <?xml version="1.0" encoding="UTF-8"?> <projec ...
- SpringBoot+SpringSecurity+JWT整合实现单点登录SSO史上最全详解
作者:波波烤鸭 blog.csdn.net/qq_38526573/article/details/103409430 一.什么是单点登陆 单点登录(Single Sign On),简称为 SSO,是 ...
- SpringSecurity+JWT实现登陆验证的思路(有一点点源码分析)
看了几个SpringSecurity+JWT的登陆demo,两个demo在一些细节实现上有一些不同,然后对于各个类和接口的关系比较模糊,就决定整理一下思路. 先简单的借用一下一位UP 三更草堂的图了解 ...
最新文章
- java学习笔记(十一)基本数据类型的对象包装类
- 如何查看numpy库数组的:类型、数据类型、尺寸、形状、维度? (type、dtype、size、shape、ndim)
- 空间离散点拟合成空间平面
- docker mysql忘记密码_docker 容器 mysql5.7 忘记root密码 重置密码
- hadoop集群中客户端修改、删除文件失败
- OllyDbg笔记-修改Messagebox的标题
- windows 2012 powershell 创建Ad
- LintCode 820. 矩形
- Junit5 以及与Spring boot整合
- VirtualBox创建Linux虚拟机图文教程
- AutoJsPro,猜歌红包群(看广告游戏脚本源码)
- 07 给Form视图添加Chatter(学Odoo,就得Do)
- 谷歌分析相关套件简介
- 一个博士毕业之际写的一些发文章的心得
- 关于MySQL错误提示ERROR 1265 (01000)的问题分析及解决方案
- arm linux驱动 知乎_学习linux驱动开发的方法?
- S5700的Eth-Trunk端口汇聚及Trunk删除
- C# 将Base64转换为图片并保存到Image数组
- 微信识别二维码下载不了app
- selenium之chromedriver与chrome版本映射表(最新版!)