From 4d3d0c41e2fe732ea98d3a1ad7dbd834e724bece Mon Sep 17 00:00:00 2001 From: junyan29 Date: Mon, 20 Jul 2020 17:54:07 +0800 Subject: [PATCH] Remove already deleted roles and permissions during reloading role info --- .../nacos/roles/NacosRoleServiceImpl.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/console/src/main/java/com/alibaba/nacos/console/security/nacos/roles/NacosRoleServiceImpl.java b/console/src/main/java/com/alibaba/nacos/console/security/nacos/roles/NacosRoleServiceImpl.java index 2d9b66aabb6..26c539b65c8 100644 --- a/console/src/main/java/com/alibaba/nacos/console/security/nacos/roles/NacosRoleServiceImpl.java +++ b/console/src/main/java/com/alibaba/nacos/console/security/nacos/roles/NacosRoleServiceImpl.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -95,8 +96,29 @@ private void reload() { tmpPermissionInfoMap.put(role, permissionInfoPage.getPageItems()); } + Iterator roleIt = roleSet.iterator(); + while (roleIt.hasNext()) { + String role = roleIt.next(); + if (!tmpRoleSet.contains(role)) { + roleIt.remove(); + } + } roleSet.addAll(tmpRoleSet); + + for (Iterator>> roleInfoIt = roleInfoMap.entrySet().iterator(); roleInfoIt.hasNext();){ + Map.Entry> item = roleInfoIt.next(); + if (!tmpRoleInfoMap.containsKey(item.getKey())) { + roleInfoIt.remove(); + } + } roleInfoMap.putAll(tmpRoleInfoMap); + + for (Iterator>> permissionInfoIt = permissionInfoMap.entrySet().iterator(); permissionInfoIt.hasNext();){ + Map.Entry> item = permissionInfoIt.next(); + if (!tmpPermissionInfoMap.containsKey(item.getKey())) { + permissionInfoIt.remove(); + } + } permissionInfoMap.putAll(tmpPermissionInfoMap); } catch (Exception e) { Loggers.AUTH.warn("[LOAD-ROLES] load failed", e);