From fd72b5de64980e82e76bca38d87b26320e6e85a1 Mon Sep 17 00:00:00 2001 From: DaniR <1026415175@qq.com> Date: Mon, 5 Jul 2021 20:57:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(RedisGatewayConfig.java):=20=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=9C=AC=E5=9C=B0=E7=BC=93=E5=AD=98=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、添加用户缓存到本地 2、添加用户修改之后清除本地缓存 3、发布Redis消息到其他集群节点,清除本地缓存 4、添加环境变量开关(使用之前的demo) Closes I3W2A款 --- .../gateway/security/ResourceServerManager.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerManager.java b/youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerManager.java index 682626edb..7a1888571 100644 --- a/youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerManager.java +++ b/youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerManager.java @@ -8,6 +8,7 @@ import com.youlai.common.constant.GlobalConstants; import com.youlai.gateway.component.AdminRoleLocalCache; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.HttpMethod; import org.springframework.http.server.reactive.ServerHttpRequest; @@ -39,6 +40,10 @@ public class ResourceServerManager implements ReactiveAuthorizationManager check(Mono mono, AuthorizationContext authorizationContext) { ServerHttpRequest request = authorizationContext.getExchange().getRequest(); @@ -64,12 +69,13 @@ public class ResourceServerManager implements ReactiveAuthorizationManager角色集合】权限规则 Map permRolesRules = (Map) adminRoleLocalCache.getCache(GlobalConstants.URL_PERM_ROLES_KEY); - if(null==permRolesRules){ - permRolesRules = redisTemplate.opsForHash().entries(GlobalConstants.URL_PERM_ROLES_KEY); - adminRoleLocalCache.setLocalCache(GlobalConstants.URL_PERM_ROLES_KEY,permRolesRules); + if (isDemoEnv){ + // 缓存取【URL权限标识->角色集合】权限规则 + if(null==permRolesRules){ + permRolesRules = redisTemplate.opsForHash().entries(GlobalConstants.URL_PERM_ROLES_KEY); + adminRoleLocalCache.setLocalCache(GlobalConstants.URL_PERM_ROLES_KEY,permRolesRules); + } } // 根据 “请求路径” 和 权限规则中的“URL权限标识”进行Ant匹配,得出拥有权限的角色集合