From 417deddefb2b05706226655b0757c9422de504c3 Mon Sep 17 00:00:00 2001 From: junyan29 Date: Mon, 20 Jul 2020 18:33:30 +0800 Subject: [PATCH 1/2] Remove the deleted roles and permissions info 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..253fd14b0c9 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>> permissionIt = permissionInfoMap.entrySet().iterator(); permissionIt.hasNext();) { + Map.Entry> item = permissionIt.next(); + if (!tmpPermissionInfoMap.containsKey(item.getKey())) { + permissionIt.remove(); + } + } permissionInfoMap.putAll(tmpPermissionInfoMap); } catch (Exception e) { Loggers.AUTH.warn("[LOAD-ROLES] load failed", e); From c1fd546fe319c24e9c07e56c7a40a60e0879abf0 Mon Sep 17 00:00:00 2001 From: yanjunnf Date: Mon, 20 Jul 2020 18:33:30 +0800 Subject: [PATCH 2/2] Remove the deleted roles and permissions info 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..253fd14b0c9 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>> permissionIt = permissionInfoMap.entrySet().iterator(); permissionIt.hasNext();) { + Map.Entry> item = permissionIt.next(); + if (!tmpPermissionInfoMap.containsKey(item.getKey())) { + permissionIt.remove(); + } + } permissionInfoMap.putAll(tmpPermissionInfoMap); } catch (Exception e) { Loggers.AUTH.warn("[LOAD-ROLES] load failed", e);