|
|
@ -41,6 +41,9 @@ public class UserTokenService
|
|
|
|
@Value("${token.expireTime}")
|
|
|
|
@Value("${token.expireTime}")
|
|
|
|
private int expireTime;
|
|
|
|
private int expireTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${token.appExpireTime}")
|
|
|
|
|
|
|
|
private int appExpireTime;
|
|
|
|
|
|
|
|
|
|
|
|
protected static final long MILLIS_SECOND = 1000;
|
|
|
|
protected static final long MILLIS_SECOND = 1000;
|
|
|
|
|
|
|
|
|
|
|
|
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
|
|
|
|
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
|
|
|
@ -118,6 +121,18 @@ public class UserTokenService
|
|
|
|
return createToken(claims);
|
|
|
|
return createToken(claims);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String createTokenForApp(LoginUser loginUser)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String token = IdUtils.fastUUID();
|
|
|
|
|
|
|
|
loginUser.setToken(token);
|
|
|
|
|
|
|
|
setUserAgent(loginUser);
|
|
|
|
|
|
|
|
refreshTokenForApp(loginUser);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> claims = new HashMap<>();
|
|
|
|
|
|
|
|
claims.put(Constants.LOGIN_USER_KEY, token);
|
|
|
|
|
|
|
|
return createToken(claims);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 验证令牌有效期,相差不足20分钟,自动刷新缓存
|
|
|
|
* 验证令牌有效期,相差不足20分钟,自动刷新缓存
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -148,6 +163,15 @@ public class UserTokenService
|
|
|
|
redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
|
|
|
|
redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void refreshTokenForApp(LoginUser loginUser)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
loginUser.setLoginTime(System.currentTimeMillis());
|
|
|
|
|
|
|
|
loginUser.setExpireTime(loginUser.getLoginTime() + appExpireTime * MILLIS_MINUTE);
|
|
|
|
|
|
|
|
// 根据uuid将loginUser缓存
|
|
|
|
|
|
|
|
String userKey = getTokenKey(loginUser.getToken());
|
|
|
|
|
|
|
|
redisCache.setCacheObject(userKey, loginUser, appExpireTime, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 设置用户代理信息
|
|
|
|
* 设置用户代理信息
|
|
|
|
*
|
|
|
|
*
|
|
|
|