@ApiOperation("退出") public ResponseResult logout();
//从redis中删除令牌 public boolean delToken(String access_token){
String name = "user_token:" + access_token;
stringRedisTemplate.delete(name);
return true;
}
//退出
@Override
@PostMapping("/userlogout")
public ResponseResult logout() {
//取出身份令牌
String uid = getTokenFormCookie();
//删除redis中token
authService.delToken(uid);
//清除cookie
clearCookie(uid);
return new ResponseResult(CommonCode.SUCCESS);
}
//清除cookie
private void clearCookie(String token){
CookieUtil.addCookie(response, cookieDomain, "/", "uid", token, 0, false);
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/userlogin","/userlogout");
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |