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

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条回答 默认 最新

相关推荐 更多相似问题