随笔分类 -  SpringSecurity

摘要:我们需要自定义一个过滤器,这个过滤器会去获取请求头中的token,对token进行解析取出其中的userid。 使用userid去redis中获取对应的LoginUser对象。 然后封装Authentication对象存入SecurityContextHolder package com.secur 阅读全文
posted @ 2023-08-19 22:21 iTao0128 阅读(15) 评论(0) 推荐(0) 编辑
摘要:自定义登陆接口,然后让SpringSecurity对这个接口放行,让用户访问这个接口的时候不用登录也能访问。 在接口中我们通过AuthenticationManager的authenticate方法来进行用户认证,所以需要在SecurityConfig中配置把AuthenticationManage 阅读全文
posted @ 2023-08-18 22:51 iTao0128 阅读(139) 评论(0) 推荐(0) 编辑
摘要:默认使用的PasswordEncoder要求数据库中的密码格式为:{id}password 。它会根据id去判断密码的加密方式。但是我们一般不会采用这种方式。所以就需要替换PasswordEncoder。 我们一般使用SpringSecurity为我们提供的BCryptPasswordEncoder 阅读全文
posted @ 2023-08-17 22:02 iTao0128 阅读(25) 评论(0) 推荐(0) 编辑
摘要:自定义一个UserDetailsService,让SpringSecurity使用我们的UserDetailsService。我们自己的UserDetailsService可以从数据库中查询用户名和密码 mapper package com.security.mapper; import com.b 阅读全文
posted @ 2023-08-17 21:36 iTao0128 阅读(484) 评论(0) 推荐(0) 编辑
摘要:登录 ①自定义登录接口 ​ 调用ProviderManager的方法进行认证 如果认证通过生成jwt ​ 把用户信息存入redis中【userId作为Key,用户信息作为Value】 ​ ②自定义UserDetailsService ​ 【因为原本这个接口的实现类是在内存中查询用户信息,不符合我们的 阅读全文
posted @ 2023-08-14 22:27 iTao0128 阅读(16) 评论(0) 推荐(0) 编辑
摘要:pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance 阅读全文
posted @ 2023-08-14 21:01 iTao0128 阅读(8) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示