Spring Sercurity获取不到当前用户信息值为Null

今天使用Spring security获取当前用户信息时发现拿不到 Principal值为空并且报异常
在这里插入图片描述前面我通过Spring Security的全局上下文设置 UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken= new UsernamePasswordAuthenticationToken(userDetails,null,userDetails.getAuthorities());
//加入全局上下文
SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken);
后面我才知道是配置除了问题
在这里插入图片描述
这里http配置的authorizeRequests() .antMatchers(“xxx”) .permitAll()**不会绕开springsecurity的过滤器验证

  • 而web.ignoring是直接绕开security的所有filter,直接跳过验证。这里的登录地址不能放到web.ignoring()里面去这会导致sercurity不知道你已经登录了(去看过滤器源码),而http.permitAll()不会有影响
    这算找到问题算在了
    详细请到江南一点雨中的这边文章https://blog.csdn.net/dnc8371/article/details/106702093阅读
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值