REM:
1. 优化代码
This commit is contained in:
HuangXin 2020-05-14 17:49:26 +08:00
parent 41029fd9c3
commit 4f16bc1dcc
1 changed files with 10 additions and 9 deletions

View File

@ -242,13 +242,15 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
*/
@Override
public String getUserToken(String username) throws NoSuchAlgorithmException {
UserAccountCache uc;
// 根据用户名在缓存中查找用户
Optional<UserAccountCache> findRet = userAccountCache.values().stream()
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
.findFirst();
if (findRet.isPresent()) {
UserAccountCache uc = findRet.get();
uc = findRet.get();
// token过期获取以前没有token创建一个新token
if ((System.currentTimeMillis() - uc.getLastAccess())
@ -262,22 +264,21 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
uc.setLastAccess(System.currentTimeMillis());
return uc.getToken();
} else {
// 用户不存在说明没有登陆过创建一个新的用户缓存
UserAccountCache uc = UserAccountCache.builder()
.username(username)
.token(createUserToken(username))
.lastAccess(System.currentTimeMillis())
.pwdErrTimes(0)
.lastAccess(System.currentTimeMillis()).build();
uc = UserAccountCache.builder()
.username(username)
.token(createUserToken(username))
.lastAccess(System.currentTimeMillis())
.pwdErrTimes(0)
.lastAccess(System.currentTimeMillis()).build();
userAccountCache.put(uc.getToken(), uc);
log.info("Create {} Token:{}", username, uc.getToken());
return uc.getToken();
}
return uc.getToken();
}
/**