mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、清空本地缓存方法名优化;
2、增加oauth2设置过期时间方法,用expire替代set不用每次重新设内容
This commit is contained in:
+2
-2
@@ -24,11 +24,11 @@ public interface SecurityFrameworkService {
|
||||
boolean hasAnyPermissions(String... permissions);
|
||||
|
||||
/**
|
||||
* 清空本地缓存
|
||||
* 清空本地权限缓存
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
void invalidateAll();
|
||||
void invalidateAllPermissionsCache();
|
||||
|
||||
/**
|
||||
* 判断是否有角色
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateAll() {
|
||||
public void invalidateAllPermissionsCache() {
|
||||
hasAnyPermissionsCache.invalidateAll();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -25,6 +25,6 @@ public class SystemPermissionRefreshRedisListener extends AbstractRedisSimpleMes
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message, byte[] bytes) {
|
||||
securityFrameworkService.invalidateAll();
|
||||
securityFrameworkService.invalidateAllPermissionsCache();
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -52,6 +52,17 @@ public class OAuth2AccessTokenRedisDAO {
|
||||
stringRedisTemplate.delete(redisKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置过期时间
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
* @param timeout 过期时间
|
||||
* @param unit 时间单位
|
||||
*/
|
||||
public void expire(String accessToken, long timeout, final TimeUnit unit) {
|
||||
stringRedisTemplate.expire(formatKey(accessToken), timeout, unit);
|
||||
}
|
||||
|
||||
private static String formatKey(String accessToken) {
|
||||
return String.format(RedisKeyConstants.OAUTH2_ACCESS_TOKEN, accessToken);
|
||||
}
|
||||
|
||||
+3
-2
@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception0;
|
||||
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
@@ -111,7 +112,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
|
||||
|
||||
if(accessTokenDO != null){
|
||||
// 有令牌的校验,代表有接口访问,延长令牌的过期时间(30分钟)
|
||||
oauth2AccessTokenRedisDAO.set(accessTokenDO.setExpiresTime(LocalDateTime.now().plusSeconds(1800)));
|
||||
oauth2AccessTokenRedisDAO.expire(accessToken, 1800, TimeUnit.SECONDS);
|
||||
}
|
||||
return accessTokenDO;
|
||||
}
|
||||
@@ -124,7 +125,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
|
||||
}
|
||||
// if (DateUtils.isExpired(accessTokenDO.getExpiresTime())) {
|
||||
// throw exception0(GlobalErrorCodeConstants.UNAUTHORIZED.getCode(), "访问令牌已过期");
|
||||
// }
|
||||
|
||||
return accessTokenDO;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user