|
|
|
@ -23,9 +23,12 @@ public class TokenUtils { |
|
|
|
|
|
|
|
private static UserService service; |
|
|
|
|
|
|
|
private static RedisUtil redisService; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() { |
|
|
|
service= this.userService; |
|
|
|
redisService = this.redisUtil; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -52,9 +55,26 @@ public class TokenUtils { |
|
|
|
User user = service.getUser(username); |
|
|
|
|
|
|
|
// 校验token是否超时失效 & 或者账号密码是否错误
|
|
|
|
//TokenValidity(token,user);
|
|
|
|
TokenValidity(token,user,redisService); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* TOKEN有效期校验 |
|
|
|
* @param token |
|
|
|
* @param user |
|
|
|
*/ |
|
|
|
public static void TokenValidity(String token, User user,RedisUtil redisService) { |
|
|
|
String redisToken = String.valueOf(redisService.get(PaymentConstant.TOKEN_PREFIX + token)); |
|
|
|
if(StringUtils.isBlank(redisToken)) |
|
|
|
throw new BusinessException(ErrorConstant.TOKEN_EXPIRATION_DATE); |
|
|
|
if(!JwtUtil.verify(redisToken, user.getUserName(), user.getPassword())) |
|
|
|
throw new BusinessException(ErrorConstant.ILLEGAL_TOKEN); |
|
|
|
String newAuthorization = JwtUtil.sign(user.getUserName(), user.getPassword()); |
|
|
|
// 设置Toekn缓存有效时间
|
|
|
|
redisService.set(PaymentConstant.TOKEN_PREFIX + token, newAuthorization); |
|
|
|
redisService.expire(PaymentConstant.TOKEN_PREFIX + token, JwtUtil.EXPIRE_TIME * 2 / 1000); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void departmentInfo(HttpServletRequest request) { |
|
|
|
|