添加token更新时间

This commit is contained in:
wuchunlei
2025-01-07 09:28:58 +08:00
parent 2e40f1ff31
commit be2aee3a47
6 changed files with 44 additions and 27 deletions

View File

@@ -72,6 +72,7 @@ public class OAuth2Realm extends AuthorizingRealm {
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String accessToken = (String) token.getPrincipal();
String appType = token.getCredentials().toString();
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo();
//根据accessToken查询用户信息
SysUserTokenEntity tokenEntity = shiroService.queryByToken(accessToken);
@@ -80,26 +81,27 @@ public class OAuth2Realm extends AuthorizingRealm {
throw new IncorrectCredentialsException("token失效请重新登录");
}
Long userId = tokenEntity.getUserId();
Long timeout = (tokenEntity.getExpireTime().getTime() - System.currentTimeMillis())/(1000 * 60 * 60);
if (timeout <= 24*10){
// token 续期
//当前时间
Date now = new Date();
//过期时间
Date expireTime = new Date(now.getTime() + (3600 *24 * 10 * 1000) );
tokenEntity.setExpireTime(expireTime);
if ("".equals(appType)){
tokenEntity.setUpdateTime(now);
}else if ("medical".equals(appType)){
tokenEntity.setMedicalUpdateTime(now);
}else if ("sociology".equals(appType)){
tokenEntity.setSociologyUpdateTime(now);
}
sysUserTokenService.updateById(tokenEntity);
}
//判断前后台用户
if (userId >= 10000) {
MyUserEntity myUserEntity = shiroService.queryAppUser(userId);
info = new SimpleAuthenticationInfo(myUserEntity, accessToken, getName());
info = new SimpleAuthenticationInfo(myUserEntity, appType, getName());
}else {
//查询用户信息
SysUserEntity user = shiroService.queryUser(tokenEntity.getUserId());
@@ -107,7 +109,7 @@ public class OAuth2Realm extends AuthorizingRealm {
if(user.getStatus() == 0){
throw new LockedAccountException("账号已被锁定,请联系管理员");
}
info = new SimpleAuthenticationInfo(user, accessToken, getName());
info = new SimpleAuthenticationInfo(user, appType, getName());
}
return info;