From 1a3155f8d518c6ede5ca5bea5b832b9c72ca8c33 Mon Sep 17 00:00:00 2001 From: wanggeng888 <450292408@qq.com> Date: Tue, 22 Jun 2021 17:19:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rbac/impl/ClientRbacServiceImpl.java | 72 +++----- .../java/com/cm/common/pojo/bos/RoleBO.java | 149 ++++------------ .../common/pojo/bos/RoleGrantedAuthority.java | 161 +++++------------- .../com/cm/common/pojo/bos/RoleMenuBO.java | 35 ++-- .../common/service/impl/RbacServiceImpl.java | 58 +------ 5 files changed, 128 insertions(+), 347 deletions(-) diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/rbac/impl/ClientRbacServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/rbac/impl/ClientRbacServiceImpl.java index f38f51b..5fd78d6 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/rbac/impl/ClientRbacServiceImpl.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/rbac/impl/ClientRbacServiceImpl.java @@ -130,25 +130,15 @@ public class ClientRbacServiceImpl implements IClientRbacService { } List savePaths = accessControl.getSavePaths(); // 匹配接口 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiSaveMenu()) { + for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getSaveMenu()) { for (String savePath : savePaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + savePath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getApiPrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + savePath, uri)) { return true; } - } - } - // 匹配资源 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceSaveMenu()) { - for (String savePath : savePaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + savePath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getResourcePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + savePath, uri)) { return true; } - } - } - // 匹配路由 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteSaveMenu()) { - for (String savePath : savePaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + savePath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getRoutePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + savePath, uri)) { return true; } } @@ -173,17 +163,12 @@ public class ClientRbacServiceImpl implements IClientRbacService { } List deletePaths = accessControl.getDeletePaths(); // 匹配接口 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiDeleteMenu()) { + for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getDeleteMenu()) { for (String deletePath : deletePaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + deletePath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getApiPrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + deletePath, uri)) { return true; } - } - } - // 匹配资源 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceDeleteMenu()) { - for (String deletePath : deletePaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + deletePath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getResourcePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + deletePath, uri)) { return true; } } @@ -208,25 +193,15 @@ public class ClientRbacServiceImpl implements IClientRbacService { } List updatePaths = accessControl.getUpdatePaths(); // 匹配接口 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiUpdateMenu()) { + for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getUpdateMenu()) { for (String updatePath : updatePaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + updatePath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getApiPrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + updatePath, uri)) { return true; } - } - } - // 匹配资源 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceUpdateMenu()) { - for (String updatePath : updatePaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + updatePath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getResourcePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + updatePath, uri)) { return true; } - } - } - // 匹配路由 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteUpdateMenu()) { - for (String updatePath : updatePaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + updatePath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getRoutePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + updatePath, uri)) { return true; } } @@ -251,26 +226,23 @@ public class ClientRbacServiceImpl implements IClientRbacService { } List queryPaths = accessControl.getQueryPaths(); // 匹配接口 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiQueryMenu()) { + for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getQueryMenu()) { + if (StringUtils.isBlank(roleMenuBO.getApiPrefix()) + && StringUtils.isBlank(roleMenuBO.getResourcePrefix()) + && StringUtils.isBlank(roleMenuBO.getRoutePrefix())) { + continue; + } for (String queryPath : queryPaths) { String queryAntPath = contextPath + roleMenuBO.getApiPrefix() + queryPath; - if (antPathMatcher.match(queryAntPath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getApiPrefix()) && antPathMatcher.match(queryAntPath, uri)) { return true; } - } - } - // 匹配资源 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceQueryMenu()) { - for (String queryPath : queryPaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + queryPath, uri)) { + queryAntPath = contextPath + roleMenuBO.getResourcePrefix() + queryPath; + if (!StringUtils.isBlank(roleMenuBO.getResourcePrefix()) && antPathMatcher.match(queryAntPath, uri)) { return true; } - } - } - // 匹配路由 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteQueryMenu()) { - for (String queryPath : queryPaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + queryPath, uri)) { + queryAntPath = contextPath + roleMenuBO.getRoutePrefix() + queryPath; + if (!StringUtils.isBlank(roleMenuBO.getRoutePrefix()) && antPathMatcher.match(queryAntPath, uri)) { return true; } } diff --git a/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleBO.java b/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleBO.java index 24f394d..a5d4cce 100644 --- a/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleBO.java +++ b/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleBO.java @@ -18,17 +18,10 @@ public class RoleBO implements Serializable { private String roleName; private String roleSummary; private String roleDataAuthority; - private List apiSaveMenu = new ArrayList<>(); - private List apiDeleteMenu = new ArrayList<>(); - private List apiUpdateMenu = new ArrayList<>(); - private List apiQueryMenu = new ArrayList<>(); - private List resourceSaveMenu = new ArrayList<>(); - private List resourceDeleteMenu = new ArrayList<>(); - private List resourceUpdateMenu = new ArrayList<>(); - private List resourceQueryMenu = new ArrayList<>(); - private List routeSaveMenu = new ArrayList<>(); - private List routeUpdateMenu = new ArrayList<>(); - private List routeQueryMenu = new ArrayList<>(); + private List saveMenu = new ArrayList<>(); + private List deleteMenu = new ArrayList<>(); + private List updateMenu = new ArrayList<>(); + private List queryMenu = new ArrayList<>(); private List permissionInsert = new ArrayList<>(); private List permissionDelete = new ArrayList<>(); private List permissionUpdate = new ArrayList<>(); @@ -66,92 +59,36 @@ public class RoleBO implements Serializable { this.roleDataAuthority = roleDataAuthority; } - public List getApiSaveMenu() { - return apiSaveMenu; + public List getSaveMenu() { + return saveMenu == null ? new ArrayList() : saveMenu; } - public void setApiSaveMenu(List apiSaveMenu) { - this.apiSaveMenu = apiSaveMenu; + public void setSaveMenu(List saveMenu) { + this.saveMenu = saveMenu; } - public List getApiDeleteMenu() { - return apiDeleteMenu; + public List getDeleteMenu() { + return deleteMenu == null ? new ArrayList() : deleteMenu; } - public void setApiDeleteMenu(List apiDeleteMenu) { - this.apiDeleteMenu = apiDeleteMenu; + public void setDeleteMenu(List deleteMenu) { + this.deleteMenu = deleteMenu; } - public List getApiUpdateMenu() { - return apiUpdateMenu; + public List getUpdateMenu() { + return updateMenu == null ? new ArrayList() : updateMenu; } - public void setApiUpdateMenu(List apiUpdateMenu) { - this.apiUpdateMenu = apiUpdateMenu; + public void setUpdateMenu(List updateMenu) { + this.updateMenu = updateMenu; } - public List getApiQueryMenu() { - return apiQueryMenu; + public List getQueryMenu() { + return queryMenu == null ? new ArrayList() : queryMenu; } - public void setApiQueryMenu(List apiQueryMenu) { - this.apiQueryMenu = apiQueryMenu; - } - - public List getResourceSaveMenu() { - return resourceSaveMenu; - } - - public void setResourceSaveMenu(List resourceSaveMenu) { - this.resourceSaveMenu = resourceSaveMenu; - } - - public List getResourceDeleteMenu() { - return resourceDeleteMenu; - } - - public void setResourceDeleteMenu(List resourceDeleteMenu) { - this.resourceDeleteMenu = resourceDeleteMenu; - } - - public List getResourceUpdateMenu() { - return resourceUpdateMenu; - } - - public void setResourceUpdateMenu(List resourceUpdateMenu) { - this.resourceUpdateMenu = resourceUpdateMenu; - } - - public List getResourceQueryMenu() { - return resourceQueryMenu; - } - - public void setResourceQueryMenu(List resourceQueryMenu) { - this.resourceQueryMenu = resourceQueryMenu; - } - - public List getRouteSaveMenu() { - return routeSaveMenu; - } - - public void setRouteSaveMenu(List routeSaveMenu) { - this.routeSaveMenu = routeSaveMenu; - } - - public List getRouteUpdateMenu() { - return routeUpdateMenu; - } - - public void setRouteUpdateMenu(List routeUpdateMenu) { - this.routeUpdateMenu = routeUpdateMenu; - } - - public List getRouteQueryMenu() { - return routeQueryMenu; - } - - public void setRouteQueryMenu(List routeQueryMenu) { - this.routeQueryMenu = routeQueryMenu; + public void setQueryMenu(List queryMenu) { + this.queryMenu = queryMenu; } public List getPermissionInsert() { @@ -189,36 +126,22 @@ public class RoleBO implements Serializable { @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); - sb.append("\"roleId\":") - .append("\"").append(roleId).append("\""); - sb.append(",\"roleName\":") - .append("\"").append(roleName).append("\""); - sb.append(",\"roleSummary\":") - .append("\"").append(roleSummary).append("\""); - sb.append(",\"roleDataAuthority\":") - .append("\"").append(roleDataAuthority).append("\""); - sb.append(",\"apiSaveMenu\":") - .append(apiSaveMenu); - sb.append(",\"apiDeleteMenu\":") - .append(apiDeleteMenu); - sb.append(",\"apiUpdateMenu\":") - .append(apiUpdateMenu); - sb.append(",\"apiQueryMenu\":") - .append(apiQueryMenu); - sb.append(",\"resourceSaveMenu\":") - .append(resourceSaveMenu); - sb.append(",\"resourceDeleteMenu\":") - .append(resourceDeleteMenu); - sb.append(",\"resourceUpdateMenu\":") - .append(resourceUpdateMenu); - sb.append(",\"resourceQueryMenu\":") - .append(resourceQueryMenu); - sb.append(",\"routeSaveMenu\":") - .append(routeSaveMenu); - sb.append(",\"routeUpdateMenu\":") - .append(routeUpdateMenu); - sb.append(",\"routeQueryMenu\":") - .append(routeQueryMenu); + sb.append("\"roleId\":\"") + .append(roleId).append('\"'); + sb.append(",\"roleName\":\"") + .append(roleName).append('\"'); + sb.append(",\"roleSummary\":\"") + .append(roleSummary).append('\"'); + sb.append(",\"roleDataAuthority\":\"") + .append(roleDataAuthority).append('\"'); + sb.append(",\"saveMenu\":") + .append(saveMenu); + sb.append(",\"deleteMenu\":") + .append(deleteMenu); + sb.append(",\"updateMenu\":") + .append(updateMenu); + sb.append(",\"queryMenu\":") + .append(queryMenu); sb.append(",\"permissionInsert\":") .append(permissionInsert); sb.append(",\"permissionDelete\":") diff --git a/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleGrantedAuthority.java b/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleGrantedAuthority.java index b2ab029..7fdf95a 100644 --- a/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleGrantedAuthority.java +++ b/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleGrantedAuthority.java @@ -2,6 +2,7 @@ package com.cm.common.pojo.bos; import org.springframework.security.core.GrantedAuthority; +import java.util.ArrayList; import java.util.List; /** @@ -17,17 +18,10 @@ public class RoleGrantedAuthority implements GrantedAuthority { private String role; private String roleId; private String roleName; - private List apiSaveMenu; - private List apiDeleteMenu; - private List apiUpdateMenu; - private List apiQueryMenu; - private List resourceSaveMenu; - private List resourceDeleteMenu; - private List resourceUpdateMenu; - private List resourceQueryMenu; - private List routeSaveMenu; - private List routeUpdateMenu; - private List routeQueryMenu; + private List saveMenu; + private List deleteMenu; + private List updateMenu; + private List queryMenu; private List permissionInsert; private List permissionDelete; private List permissionUpdate; @@ -41,17 +35,10 @@ public class RoleGrantedAuthority implements GrantedAuthority { this.role = role; this.roleId = roleBO.getRoleId(); this.roleName = roleBO.getRoleName(); - this.apiSaveMenu = roleBO.getApiSaveMenu(); - this.apiDeleteMenu = roleBO.getApiDeleteMenu(); - this.apiUpdateMenu = roleBO.getApiUpdateMenu(); - this.apiQueryMenu = roleBO.getApiQueryMenu(); - this.resourceSaveMenu = roleBO.getResourceSaveMenu(); - this.resourceDeleteMenu = roleBO.getResourceDeleteMenu(); - this.resourceUpdateMenu = roleBO.getResourceUpdateMenu(); - this.resourceQueryMenu = roleBO.getResourceQueryMenu(); - this.routeSaveMenu = roleBO.getRouteSaveMenu(); - this.routeUpdateMenu = roleBO.getRouteUpdateMenu(); - this.routeQueryMenu = roleBO.getRouteQueryMenu(); + this.saveMenu = roleBO.getSaveMenu(); + this.deleteMenu = roleBO.getDeleteMenu(); + this.updateMenu = roleBO.getUpdateMenu(); + this.queryMenu = roleBO.getQueryMenu(); this.permissionInsert = roleBO.getPermissionInsert(); this.permissionDelete = roleBO.getPermissionDelete(); this.permissionUpdate = roleBO.getPermissionUpdate(); @@ -93,92 +80,36 @@ public class RoleGrantedAuthority implements GrantedAuthority { this.roleName = roleName; } - public List getApiSaveMenu() { - return apiSaveMenu; + public List getSaveMenu() { + return saveMenu == null ? new ArrayList() : saveMenu; } - public void setApiSaveMenu(List apiSaveMenu) { - this.apiSaveMenu = apiSaveMenu; + public void setSaveMenu(List saveMenu) { + this.saveMenu = saveMenu; } - public List getApiDeleteMenu() { - return apiDeleteMenu; + public List getDeleteMenu() { + return deleteMenu == null ? new ArrayList() : deleteMenu; } - public void setApiDeleteMenu(List apiDeleteMenu) { - this.apiDeleteMenu = apiDeleteMenu; + public void setDeleteMenu(List deleteMenu) { + this.deleteMenu = deleteMenu; } - public List getApiUpdateMenu() { - return apiUpdateMenu; + public List getUpdateMenu() { + return updateMenu == null ? new ArrayList() : updateMenu; } - public void setApiUpdateMenu(List apiUpdateMenu) { - this.apiUpdateMenu = apiUpdateMenu; + public void setUpdateMenu(List updateMenu) { + this.updateMenu = updateMenu; } - public List getApiQueryMenu() { - return apiQueryMenu; + public List getQueryMenu() { + return queryMenu == null ? new ArrayList() : queryMenu; } - public void setApiQueryMenu(List apiQueryMenu) { - this.apiQueryMenu = apiQueryMenu; - } - - public List getResourceSaveMenu() { - return resourceSaveMenu; - } - - public void setResourceSaveMenu(List resourceSaveMenu) { - this.resourceSaveMenu = resourceSaveMenu; - } - - public List getResourceDeleteMenu() { - return resourceDeleteMenu; - } - - public void setResourceDeleteMenu(List resourceDeleteMenu) { - this.resourceDeleteMenu = resourceDeleteMenu; - } - - public List getResourceUpdateMenu() { - return resourceUpdateMenu; - } - - public void setResourceUpdateMenu(List resourceUpdateMenu) { - this.resourceUpdateMenu = resourceUpdateMenu; - } - - public List getResourceQueryMenu() { - return resourceQueryMenu; - } - - public void setResourceQueryMenu(List resourceQueryMenu) { - this.resourceQueryMenu = resourceQueryMenu; - } - - public List getRouteSaveMenu() { - return routeSaveMenu; - } - - public void setRouteSaveMenu(List routeSaveMenu) { - this.routeSaveMenu = routeSaveMenu; - } - - public List getRouteUpdateMenu() { - return routeUpdateMenu; - } - - public void setRouteUpdateMenu(List routeUpdateMenu) { - this.routeUpdateMenu = routeUpdateMenu; - } - - public List getRouteQueryMenu() { - return routeQueryMenu; - } - - public void setRouteQueryMenu(List routeQueryMenu) { - this.routeQueryMenu = routeQueryMenu; + public void setQueryMenu(List queryMenu) { + this.queryMenu = queryMenu; } public List getPermissionInsert() { @@ -216,34 +147,20 @@ public class RoleGrantedAuthority implements GrantedAuthority { @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); - sb.append("\"role\":") - .append("\"").append(role).append("\""); - sb.append(",\"roleId\":") - .append("\"").append(roleId).append("\""); - sb.append(",\"roleName\":") - .append("\"").append(roleName).append("\""); - sb.append(",\"apiSaveMenu\":") - .append(apiSaveMenu); - sb.append(",\"apiDeleteMenu\":") - .append(apiDeleteMenu); - sb.append(",\"apiUpdateMenu\":") - .append(apiUpdateMenu); - sb.append(",\"apiQueryMenu\":") - .append(apiQueryMenu); - sb.append(",\"resourceSaveMenu\":") - .append(resourceSaveMenu); - sb.append(",\"resourceDeleteMenu\":") - .append(resourceDeleteMenu); - sb.append(",\"resourceUpdateMenu\":") - .append(resourceUpdateMenu); - sb.append(",\"resourceQueryMenu\":") - .append(resourceQueryMenu); - sb.append(",\"routeSaveMenu\":") - .append(routeSaveMenu); - sb.append(",\"routeUpdateMenu\":") - .append(routeUpdateMenu); - sb.append(",\"routeQueryMenu\":") - .append(routeQueryMenu); + sb.append("\"role\":\"") + .append(role).append('\"'); + sb.append(",\"roleId\":\"") + .append(roleId).append('\"'); + sb.append(",\"roleName\":\"") + .append(roleName).append('\"'); + sb.append(",\"saveMenu\":") + .append(saveMenu); + sb.append(",\"deleteMenu\":") + .append(deleteMenu); + sb.append(",\"updateMenu\":") + .append(updateMenu); + sb.append(",\"queryMenu\":") + .append(queryMenu); sb.append(",\"permissionInsert\":") .append(permissionInsert); sb.append(",\"permissionDelete\":") diff --git a/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleMenuBO.java b/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleMenuBO.java index fa07c83..ddf7c58 100644 --- a/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleMenuBO.java +++ b/cloud-common/src/main/java/com/cm/common/pojo/bos/RoleMenuBO.java @@ -18,6 +18,7 @@ public class RoleMenuBO implements Serializable { private String apiPrefix; private String resourcePrefix; private String routePrefix; + private String menuUrl; public String getRoleId() { return roleId == null ? "" : roleId.trim(); @@ -67,21 +68,31 @@ public class RoleMenuBO implements Serializable { this.routePrefix = routePrefix; } + public String getMenuUrl() { + return menuUrl == null ? "" : menuUrl; + } + + public void setMenuUrl(String menuUrl) { + this.menuUrl = menuUrl; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); - sb.append("\"roleId\":") - .append("\"").append(roleId).append("\""); - sb.append(",\"roleType\":") - .append("\"").append(roleType).append("\""); - sb.append(",\"menuId\":") - .append("\"").append(menuId).append("\""); - sb.append(",\"apiPrefix\":") - .append("\"").append(apiPrefix).append("\""); - sb.append(",\"resourcePrefix\":") - .append("\"").append(resourcePrefix).append("\""); - sb.append(",\"routePrefix\":") - .append("\"").append(routePrefix).append("\""); + sb.append("\"roleId\":\"") + .append(roleId).append('\"'); + sb.append(",\"roleType\":\"") + .append(roleType).append('\"'); + sb.append(",\"menuId\":\"") + .append(menuId).append('\"'); + sb.append(",\"apiPrefix\":\"") + .append(apiPrefix).append('\"'); + sb.append(",\"resourcePrefix\":\"") + .append(resourcePrefix).append('\"'); + sb.append(",\"routePrefix\":\"") + .append(routePrefix).append('\"'); + sb.append(",\"menuUrl\":\"") + .append(menuUrl).append('\"'); sb.append('}'); return sb.toString(); } diff --git a/cloud-common/src/main/java/com/cm/common/service/impl/RbacServiceImpl.java b/cloud-common/src/main/java/com/cm/common/service/impl/RbacServiceImpl.java index 9832e6a..7dc1acd 100644 --- a/cloud-common/src/main/java/com/cm/common/service/impl/RbacServiceImpl.java +++ b/cloud-common/src/main/java/com/cm/common/service/impl/RbacServiceImpl.java @@ -66,17 +66,10 @@ public class RbacServiceImpl implements IRbacService { RoleBO roleBO = new RoleBO(); roleBO.setRoleId(authorityObject.getString("roleId")); roleBO.setRoleName(authorityObject.getString("roleName")); - roleBO.setApiSaveMenu(JSON.parseArray(authorityObject.getString("apiSaveMenu"), RoleMenuBO.class)); - roleBO.setApiDeleteMenu(JSON.parseArray(authorityObject.getString("apiDeleteMenu"), RoleMenuBO.class)); - roleBO.setApiUpdateMenu(JSON.parseArray(authorityObject.getString("apiSaveMenu"), RoleMenuBO.class)); - roleBO.setApiQueryMenu(JSON.parseArray(authorityObject.getString("apiQueryMenu"), RoleMenuBO.class)); - roleBO.setResourceSaveMenu(JSON.parseArray(authorityObject.getString("resourceSaveMenu"), RoleMenuBO.class)); - roleBO.setResourceDeleteMenu(JSON.parseArray(authorityObject.getString("resourceDeleteMenu"), RoleMenuBO.class)); - roleBO.setResourceUpdateMenu(JSON.parseArray(authorityObject.getString("resourceUpdateMenu"), RoleMenuBO.class)); - roleBO.setResourceQueryMenu(JSON.parseArray(authorityObject.getString("resourceQueryMenu"), RoleMenuBO.class)); - roleBO.setRouteSaveMenu(JSON.parseArray(authorityObject.getString("routeSaveMenu"), RoleMenuBO.class)); - roleBO.setRouteUpdateMenu(JSON.parseArray(authorityObject.getString("routeUpdateMenu"), RoleMenuBO.class)); - roleBO.setRouteQueryMenu(JSON.parseArray(authorityObject.getString("routeQueryMenu"), RoleMenuBO.class)); + roleBO.setSaveMenu(JSON.parseArray(authorityObject.getString("saveMenu"), RoleMenuBO.class)); + roleBO.setDeleteMenu(JSON.parseArray(authorityObject.getString("deleteMenu"), RoleMenuBO.class)); + roleBO.setUpdateMenu(JSON.parseArray(authorityObject.getString("updateMenu"), RoleMenuBO.class)); + roleBO.setQueryMenu(JSON.parseArray(authorityObject.getString("queryMenu"), RoleMenuBO.class)); roleGrantedAuthority = new RoleGrantedAuthority(authorityObject.getString("authority"), roleBO); } } @@ -151,24 +144,14 @@ public class RbacServiceImpl implements IRbacService { private boolean hasSavePermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) { List savePaths = accessControl.getSavePaths(); // 匹配接口 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiSaveMenu()) { + for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getSaveMenu()) { for (String savePath : savePaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + savePath, uri)) { return true; } - } - } - // 匹配资源 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceSaveMenu()) { - for (String savePath : savePaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + savePath, uri)) { return true; } - } - } - // 匹配路由 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteSaveMenu()) { - for (String savePath : savePaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + savePath, uri)) { return true; } @@ -188,16 +171,11 @@ public class RbacServiceImpl implements IRbacService { private boolean hasDeletePermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) { List deletePaths = accessControl.getDeletePaths(); // 匹配接口 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiDeleteMenu()) { + for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getDeleteMenu()) { for (String deletePath : deletePaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + deletePath, uri)) { return true; } - } - } - // 匹配资源 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceDeleteMenu()) { - for (String deletePath : deletePaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + deletePath, uri)) { return true; } @@ -217,24 +195,14 @@ public class RbacServiceImpl implements IRbacService { private boolean hasUpdatePermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) { List updatePaths = accessControl.getUpdatePaths(); // 匹配接口 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiUpdateMenu()) { + for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getUpdateMenu()) { for (String updatePath : updatePaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + updatePath, uri)) { return true; } - } - } - // 匹配资源 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceUpdateMenu()) { - for (String updatePath : updatePaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + updatePath, uri)) { return true; } - } - } - // 匹配路由 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteUpdateMenu()) { - for (String updatePath : updatePaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + updatePath, uri)) { return true; } @@ -254,25 +222,15 @@ public class RbacServiceImpl implements IRbacService { private boolean hasQueryPermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) { List queryPaths = accessControl.getQueryPaths(); // 匹配接口 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiQueryMenu()) { + for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getQueryMenu()) { for (String queryPath : queryPaths) { String queryAntPath = contextPath + roleMenuBO.getApiPrefix() + queryPath; if (antPathMatcher.match(queryAntPath, uri)) { return true; } - } - } - // 匹配资源 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceQueryMenu()) { - for (String queryPath : queryPaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + queryPath, uri)) { return true; } - } - } - // 匹配路由 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteQueryMenu()) { - for (String queryPath : queryPaths) { if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + queryPath, uri)) { return true; }