This commit is contained in:
yzcheng90
2023-01-18 15:29:40 +08:00
parent b6bf720318
commit aaf4134de0
4 changed files with 4 additions and 7 deletions

View File

@@ -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();

View File

@@ -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);
}
}

View File

@@ -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");
}

View File

@@ -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;