BigDong~ 2021-12-06 18:29 采纳率: 60%
浏览 228
已结题

SpringSecurity LogoutSuccessHandler空指针问题

1.自定义LogoutSuccessHandler实现类

@Slf4j
@Component
public class UserLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        SecurityUser user = (SecurityUser) authentication.getPrincipal();
        String username = user.getUsername();
        log.info("用户: {}  注销登录成功", username);
        ResponseUtil.write(httpServletResponse, JsonResult.ok("退出成功"));
    }
}

  1. SecurityConfig中添加了logoutSuccessHandler
.and().logout().logoutSuccessHandler(userLogoutSuccessHandler)

3.发现UserLogoutSuccessHandler中authentication为null,我想拿到用户信息保存日志,有朋友知道怎么解决吗?

  • 写回答

1条回答 默认 最新

  • BigDong~ 2021-12-06 19:24
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月14日
  • 已采纳回答 12月6日
  • 创建了问题 12月6日

悬赏问题

  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services