Spring Security--自动登录

也就是remember me

在配置链上加一个

 然后发送请求时加上:remember-me字段

value值可以为,ture,1,on

我们记住登录后,关掉浏览器再打开,访问一下接口,可以访问,说明记住登录成功了。

 

 因为有的接口可以支持rememberMe认证,有的接口不支持,用上图的方式做区别。

//禁止给url编码

org.springframework.security.web.session.DisableEncodeUrlFilter@3730ab42,

//异步管理器

org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilte

r@537c8c7e,

//读取当前用户信息

org.springframework.security.web.context.SecurityContextPersistenceFilter@3f93e4a8,

//处理请求头

org.springframework.security.web.header.HeaderWriterFilter@2e2f720,

//注销

org.springframework.security.web.authentication.logout.LogoutFilter@2264e43c,

//用户认证的

org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@

3f1ddac2,

//请求缓存的

org.springframework.security.web.savedrequest.RequestCacheAwareFilter@5445f5ba,

org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@67

110f71,

//记住登录

org.springframework.security.web.authentication.rememberme.RememberMeAuthentication

Filter@455824ad,

//匿名访问

org.springframework.security.web.authentication.AnonymousAuthenticationFilter@7308fff

f, org.springframework.security.web.session.SessionManagementFilter@7f572c37,

org.springframework.security.web.access.ExceptionTranslationFilter@1ffcf674, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@12010fd1
 

rememberMe还有一个key属性,当key设置了值的时候,即使服务端重启了也不用重新登录。

开启rememberMe之后,登陆成功,服务端会响应一个 rememberMe字符串回来:

YWRtaW46MTY4Nzc2ODQ5Nzk1NDpjZTM0YzQ2NWMzYzE4M2UwYjAwOTgxZmU1Zjg3Y2UxNg

base64解密完是

admin:1687768497954:ce34c465c3c183e0b00981fe5f87ce16

分三部分:用户名:时间戳:加密字符串(根据用户名+用户密码+时间戳+key加密的字符串)

以后每次请求,都会自动携带这个cookie。


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海上生日朋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值