代码优化
This commit is contained in:
parent
3fe7e97b71
commit
a17b49b37f
@ -33,7 +33,7 @@ public class JwtTokenProvider {
|
|||||||
private Integer userTokenExpireMinute;
|
private Integer userTokenExpireMinute;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisRepository redisRepository;
|
private RedisRepository redisRepository;
|
||||||
private final String USER_TOKEN_EXPIRE_PREFIX = "USER_TOKEN_EXPIRE:" + EnvironmentUtil.activeEnvironment + ":";
|
private final String USER_TOKEN_EXPIRE_PREFIX = "USER_TOKEN_EXPIRE:";
|
||||||
private static ConcurrentHashMap<String, String> userMap = new ConcurrentHashMap<>();
|
private static ConcurrentHashMap<String, String> userMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -76,7 +76,7 @@ public class JwtTokenProvider {
|
|||||||
.compact();
|
.compact();
|
||||||
userMap.put(username, token);
|
userMap.put(username, token);
|
||||||
//刷新token
|
//刷新token
|
||||||
String key = USER_TOKEN_EXPIRE_PREFIX + username + ":" + uuid;
|
String key = USER_TOKEN_EXPIRE_PREFIX + EnvironmentUtil.activeEnvironment + ":" + username + ":" + uuid;
|
||||||
redisRepository.set(key, "", userTokenExpireMinute * 60L);
|
redisRepository.set(key, "", userTokenExpireMinute * 60L);
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ public class JwtTokenProvider {
|
|||||||
Map<String, Object> cs = (Map<String, Object>) body;
|
Map<String, Object> cs = (Map<String, Object>) body;
|
||||||
if (Objects.equals(cs.get("loginTimeOut"), 1)) {
|
if (Objects.equals(cs.get("loginTimeOut"), 1)) {
|
||||||
//判断token过期没有
|
//判断token过期没有
|
||||||
String key = USER_TOKEN_EXPIRE_PREFIX + cs.get("account") + ":" + cs.get("uuid");
|
String key = USER_TOKEN_EXPIRE_PREFIX + EnvironmentUtil.activeEnvironment + ":" + cs.get("account") + ":" + cs.get("uuid");
|
||||||
if (redisRepository.get(key) == null) {
|
if (redisRepository.get(key) == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -121,8 +121,6 @@ public class JwtTokenProvider {
|
|||||||
return true;
|
return true;
|
||||||
} catch (JwtException | IllegalArgumentException e) {
|
} catch (JwtException | IllegalArgumentException e) {
|
||||||
throw new CustomException("Expired or invalid JWT token", HttpStatus.FORBIDDEN);
|
throw new CustomException("Expired or invalid JWT token", HttpStatus.FORBIDDEN);
|
||||||
//throw new CustomException("Expired or invalid JWT token", HttpStatus.OK);
|
|
||||||
//throw new OpenAlertException(403,"Expired or invalid JWT token");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user