mirror of
https://github.com/yzcheng90/X-SpringBoot
synced 2025-11-04 05:35:45 +08:00
提交
This commit is contained in:
@@ -47,10 +47,8 @@ public class CustomAuthenticationSuccessHandler implements AuthenticationSuccess
|
||||
token = SecureUtil.md5(String.valueOf(System.currentTimeMillis()));
|
||||
}
|
||||
// 保存token
|
||||
redisTemplate.opsForValue().set(Constant.AUTHENTICATION_TOKEN + token,token,Constant.TOKEN_EXPIRE, TimeUnit.SECONDS);
|
||||
// 保存用户ID
|
||||
redisTemplate.opsForValue().set(token,userId,Constant.TOKEN_EXPIRE, TimeUnit.SECONDS);
|
||||
|
||||
redisTemplate.opsForValue().set(Constant.AUTHENTICATION_TOKEN + token,userId,Constant.TOKEN_EXPIRE, TimeUnit.SECONDS);
|
||||
log.info("token:{}",token);
|
||||
response.setCharacterEncoding(CharsetUtil.UTF_8);
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
PrintWriter printWriter = response.getWriter();
|
||||
|
||||
@@ -31,6 +31,5 @@ public class CustomLogoutSuccessHandler implements LogoutHandler {
|
||||
public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
|
||||
String token = request.getHeader(Constant.TOKEN);
|
||||
redisTemplate.delete(Constant.AUTHENTICATION_TOKEN + token);
|
||||
redisTemplate.delete(token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class R extends HashMap<String, Object> {
|
||||
private static final int defaultLevel = 1;
|
||||
|
||||
public R() {
|
||||
put("code", 0);
|
||||
put("code", 200);
|
||||
put("msg", "success");
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AuthenticationTokenFilter extends BasicAuthenticationFilter {
|
||||
}
|
||||
|
||||
if(StrUtil.isNotBlank(token) && !StrUtil.equals(token,"null")){
|
||||
Object userId = redisTemplate.opsForValue().get(token);
|
||||
Object userId = redisTemplate.opsForValue().get(Constant.AUTHENTICATION_TOKEN + token);
|
||||
if(ObjectUtil.isNull(userId)){
|
||||
writer(response,"无效token");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user