|
|
|
@ -3,9 +3,12 @@ package com.op.common.security.service;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import com.op.common.core.constant.CacheConstants;
|
|
|
|
|
import com.op.common.core.constant.SecurityConstants;
|
|
|
|
|
import com.op.common.core.utils.JwtUtils;
|
|
|
|
@ -31,7 +34,7 @@ public class TokenService {
|
|
|
|
|
|
|
|
|
|
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
|
|
|
|
|
|
|
|
|
|
private final static long expireTime = CacheConstants.EXPIRATION;
|
|
|
|
|
// private final static long expireTime = CacheConstants.EXPIRATION;
|
|
|
|
|
|
|
|
|
|
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
|
|
|
|
|
|
|
|
|
@ -59,7 +62,7 @@ public class TokenService {
|
|
|
|
|
// 接口返回信息
|
|
|
|
|
Map<String, Object> rspMap = new HashMap<String, Object>();
|
|
|
|
|
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
|
|
|
|
rspMap.put("expires_in", expireTime);
|
|
|
|
|
rspMap.put("expires_in", CacheConstants.EXPIRATION);
|
|
|
|
|
return rspMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -140,15 +143,16 @@ public class TokenService {
|
|
|
|
|
*/
|
|
|
|
|
public void refreshToken(LoginUser loginUser) {
|
|
|
|
|
loginUser.setLoginTime(System.currentTimeMillis());
|
|
|
|
|
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
|
|
|
|
|
loginUser.setExpireTime(loginUser.getLoginTime() + CacheConstants.EXPIRATION * MILLIS_MINUTE);
|
|
|
|
|
// 根据uuid将loginUser缓存
|
|
|
|
|
String userKey = getTokenKey(loginUser.getToken());
|
|
|
|
|
redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
|
|
|
|
|
redisService.setCacheObject(userKey, loginUser, CacheConstants.EXPIRATION, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
String username = loginUser.getUsername();
|
|
|
|
|
// 重置过期时间
|
|
|
|
|
String pool = redisService.getCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username);
|
|
|
|
|
redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, pool, expireTime, TimeUnit.MINUTES);
|
|
|
|
|
redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, pool, CacheConstants.EXPIRATION,
|
|
|
|
|
TimeUnit.MINUTES);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getTokenKey(String token) {
|
|
|
|
|