默认logout请求实现是有状态的,返回到login请求页面;我们现在是前后端分离处理,所以需要自定义实现logout
新建JwtLogoutSuccessHandler
/**
* 自定义Logout处理
* @author java1234_小锋 (公众号:java1234)
* @site www.java1234.vip
* @company 南通小锋网络科技有限公司
*/
@Component
public class JwtLogoutSuccessHandler implements LogoutSuccessHandler {
@Override
public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
httpServletResponse.setContentType("application/json;charset=UTF-8");
ServletOutputStream outputStream = httpServletResponse.getOutputStream();
outputStream.write(JSONUtil.toJsonStr(R.ok("退出成功")).getBytes("UTF-8"));
outputStream.flush();
outputStream.close();
}
}
SecurityConfig配置