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("退出成功"));
}
}
- SecurityConfig中添加了logoutSuccessHandler
.and().logout().logoutSuccessHandler(userLogoutSuccessHandler)
3.发现UserLogoutSuccessHandler中authentication为null,我想拿到用户信息保存日志,有朋友知道怎么解决吗?