修改权限

This commit is contained in:
wanggeng888 2021-06-22 17:19:25 +08:00
parent d6d6d612f5
commit 1a3155f8d5
5 changed files with 128 additions and 347 deletions

View File

@ -130,25 +130,15 @@ public class ClientRbacServiceImpl implements IClientRbacService {
} }
List<String> savePaths = accessControl.getSavePaths(); List<String> savePaths = accessControl.getSavePaths();
// 匹配接口 // 匹配接口
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiSaveMenu()) { for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getSaveMenu()) {
for (String savePath : savePaths) { 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; return true;
} }
} if (!StringUtils.isBlank(roleMenuBO.getResourcePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + savePath, uri)) {
}
// 匹配资源
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceSaveMenu()) {
for (String savePath : savePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + savePath, uri)) {
return true; return true;
} }
} if (!StringUtils.isBlank(roleMenuBO.getRoutePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + savePath, uri)) {
}
// 匹配路由
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteSaveMenu()) {
for (String savePath : savePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + savePath, uri)) {
return true; return true;
} }
} }
@ -173,17 +163,12 @@ public class ClientRbacServiceImpl implements IClientRbacService {
} }
List<String> deletePaths = accessControl.getDeletePaths(); List<String> deletePaths = accessControl.getDeletePaths();
// 匹配接口 // 匹配接口
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiDeleteMenu()) { for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getDeleteMenu()) {
for (String deletePath : deletePaths) { 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; return true;
} }
} if (!StringUtils.isBlank(roleMenuBO.getResourcePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + deletePath, uri)) {
}
// 匹配资源
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceDeleteMenu()) {
for (String deletePath : deletePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + deletePath, uri)) {
return true; return true;
} }
} }
@ -208,25 +193,15 @@ public class ClientRbacServiceImpl implements IClientRbacService {
} }
List<String> updatePaths = accessControl.getUpdatePaths(); List<String> updatePaths = accessControl.getUpdatePaths();
// 匹配接口 // 匹配接口
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiUpdateMenu()) { for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getUpdateMenu()) {
for (String updatePath : updatePaths) { 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; return true;
} }
} if (!StringUtils.isBlank(roleMenuBO.getResourcePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + updatePath, uri)) {
}
// 匹配资源
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceUpdateMenu()) {
for (String updatePath : updatePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + updatePath, uri)) {
return true; return true;
} }
} if (!StringUtils.isBlank(roleMenuBO.getRoutePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + updatePath, uri)) {
}
// 匹配路由
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteUpdateMenu()) {
for (String updatePath : updatePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + updatePath, uri)) {
return true; return true;
} }
} }
@ -251,26 +226,23 @@ public class ClientRbacServiceImpl implements IClientRbacService {
} }
List<String> queryPaths = accessControl.getQueryPaths(); List<String> 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) { for (String queryPath : queryPaths) {
String queryAntPath = contextPath + roleMenuBO.getApiPrefix() + queryPath; String queryAntPath = contextPath + roleMenuBO.getApiPrefix() + queryPath;
if (antPathMatcher.match(queryAntPath, uri)) { if (!StringUtils.isBlank(roleMenuBO.getApiPrefix()) && antPathMatcher.match(queryAntPath, uri)) {
return true; return true;
} }
} queryAntPath = contextPath + roleMenuBO.getResourcePrefix() + queryPath;
} if (!StringUtils.isBlank(roleMenuBO.getResourcePrefix()) && antPathMatcher.match(queryAntPath, uri)) {
// 匹配资源
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceQueryMenu()) {
for (String queryPath : queryPaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + queryPath, uri)) {
return true; return true;
} }
} queryAntPath = contextPath + roleMenuBO.getRoutePrefix() + queryPath;
} if (!StringUtils.isBlank(roleMenuBO.getRoutePrefix()) && antPathMatcher.match(queryAntPath, uri)) {
// 匹配路由
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteQueryMenu()) {
for (String queryPath : queryPaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + queryPath, uri)) {
return true; return true;
} }
} }

View File

@ -18,17 +18,10 @@ public class RoleBO implements Serializable {
private String roleName; private String roleName;
private String roleSummary; private String roleSummary;
private String roleDataAuthority; private String roleDataAuthority;
private List<RoleMenuBO> apiSaveMenu = new ArrayList<>(); private List<RoleMenuBO> saveMenu = new ArrayList<>();
private List<RoleMenuBO> apiDeleteMenu = new ArrayList<>(); private List<RoleMenuBO> deleteMenu = new ArrayList<>();
private List<RoleMenuBO> apiUpdateMenu = new ArrayList<>(); private List<RoleMenuBO> updateMenu = new ArrayList<>();
private List<RoleMenuBO> apiQueryMenu = new ArrayList<>(); private List<RoleMenuBO> queryMenu = new ArrayList<>();
private List<RoleMenuBO> resourceSaveMenu = new ArrayList<>();
private List<RoleMenuBO> resourceDeleteMenu = new ArrayList<>();
private List<RoleMenuBO> resourceUpdateMenu = new ArrayList<>();
private List<RoleMenuBO> resourceQueryMenu = new ArrayList<>();
private List<RoleMenuBO> routeSaveMenu = new ArrayList<>();
private List<RoleMenuBO> routeUpdateMenu = new ArrayList<>();
private List<RoleMenuBO> routeQueryMenu = new ArrayList<>();
private List<PermissionBO> permissionInsert = new ArrayList<>(); private List<PermissionBO> permissionInsert = new ArrayList<>();
private List<PermissionBO> permissionDelete = new ArrayList<>(); private List<PermissionBO> permissionDelete = new ArrayList<>();
private List<PermissionBO> permissionUpdate = new ArrayList<>(); private List<PermissionBO> permissionUpdate = new ArrayList<>();
@ -66,92 +59,36 @@ public class RoleBO implements Serializable {
this.roleDataAuthority = roleDataAuthority; this.roleDataAuthority = roleDataAuthority;
} }
public List<RoleMenuBO> getApiSaveMenu() { public List<RoleMenuBO> getSaveMenu() {
return apiSaveMenu; return saveMenu == null ? new ArrayList() : saveMenu;
} }
public void setApiSaveMenu(List<RoleMenuBO> apiSaveMenu) { public void setSaveMenu(List<RoleMenuBO> saveMenu) {
this.apiSaveMenu = apiSaveMenu; this.saveMenu = saveMenu;
} }
public List<RoleMenuBO> getApiDeleteMenu() { public List<RoleMenuBO> getDeleteMenu() {
return apiDeleteMenu; return deleteMenu == null ? new ArrayList() : deleteMenu;
} }
public void setApiDeleteMenu(List<RoleMenuBO> apiDeleteMenu) { public void setDeleteMenu(List<RoleMenuBO> deleteMenu) {
this.apiDeleteMenu = apiDeleteMenu; this.deleteMenu = deleteMenu;
} }
public List<RoleMenuBO> getApiUpdateMenu() { public List<RoleMenuBO> getUpdateMenu() {
return apiUpdateMenu; return updateMenu == null ? new ArrayList() : updateMenu;
} }
public void setApiUpdateMenu(List<RoleMenuBO> apiUpdateMenu) { public void setUpdateMenu(List<RoleMenuBO> updateMenu) {
this.apiUpdateMenu = apiUpdateMenu; this.updateMenu = updateMenu;
} }
public List<RoleMenuBO> getApiQueryMenu() { public List<RoleMenuBO> getQueryMenu() {
return apiQueryMenu; return queryMenu == null ? new ArrayList() : queryMenu;
} }
public void setApiQueryMenu(List<RoleMenuBO> apiQueryMenu) { public void setQueryMenu(List<RoleMenuBO> queryMenu) {
this.apiQueryMenu = apiQueryMenu; this.queryMenu = queryMenu;
}
public List<RoleMenuBO> getResourceSaveMenu() {
return resourceSaveMenu;
}
public void setResourceSaveMenu(List<RoleMenuBO> resourceSaveMenu) {
this.resourceSaveMenu = resourceSaveMenu;
}
public List<RoleMenuBO> getResourceDeleteMenu() {
return resourceDeleteMenu;
}
public void setResourceDeleteMenu(List<RoleMenuBO> resourceDeleteMenu) {
this.resourceDeleteMenu = resourceDeleteMenu;
}
public List<RoleMenuBO> getResourceUpdateMenu() {
return resourceUpdateMenu;
}
public void setResourceUpdateMenu(List<RoleMenuBO> resourceUpdateMenu) {
this.resourceUpdateMenu = resourceUpdateMenu;
}
public List<RoleMenuBO> getResourceQueryMenu() {
return resourceQueryMenu;
}
public void setResourceQueryMenu(List<RoleMenuBO> resourceQueryMenu) {
this.resourceQueryMenu = resourceQueryMenu;
}
public List<RoleMenuBO> getRouteSaveMenu() {
return routeSaveMenu;
}
public void setRouteSaveMenu(List<RoleMenuBO> routeSaveMenu) {
this.routeSaveMenu = routeSaveMenu;
}
public List<RoleMenuBO> getRouteUpdateMenu() {
return routeUpdateMenu;
}
public void setRouteUpdateMenu(List<RoleMenuBO> routeUpdateMenu) {
this.routeUpdateMenu = routeUpdateMenu;
}
public List<RoleMenuBO> getRouteQueryMenu() {
return routeQueryMenu;
}
public void setRouteQueryMenu(List<RoleMenuBO> routeQueryMenu) {
this.routeQueryMenu = routeQueryMenu;
} }
public List<PermissionBO> getPermissionInsert() { public List<PermissionBO> getPermissionInsert() {
@ -189,36 +126,22 @@ public class RoleBO implements Serializable {
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder("{"); final StringBuilder sb = new StringBuilder("{");
sb.append("\"roleId\":") sb.append("\"roleId\":\"")
.append("\"").append(roleId).append("\""); .append(roleId).append('\"');
sb.append(",\"roleName\":") sb.append(",\"roleName\":\"")
.append("\"").append(roleName).append("\""); .append(roleName).append('\"');
sb.append(",\"roleSummary\":") sb.append(",\"roleSummary\":\"")
.append("\"").append(roleSummary).append("\""); .append(roleSummary).append('\"');
sb.append(",\"roleDataAuthority\":") sb.append(",\"roleDataAuthority\":\"")
.append("\"").append(roleDataAuthority).append("\""); .append(roleDataAuthority).append('\"');
sb.append(",\"apiSaveMenu\":") sb.append(",\"saveMenu\":")
.append(apiSaveMenu); .append(saveMenu);
sb.append(",\"apiDeleteMenu\":") sb.append(",\"deleteMenu\":")
.append(apiDeleteMenu); .append(deleteMenu);
sb.append(",\"apiUpdateMenu\":") sb.append(",\"updateMenu\":")
.append(apiUpdateMenu); .append(updateMenu);
sb.append(",\"apiQueryMenu\":") sb.append(",\"queryMenu\":")
.append(apiQueryMenu); .append(queryMenu);
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(",\"permissionInsert\":") sb.append(",\"permissionInsert\":")
.append(permissionInsert); .append(permissionInsert);
sb.append(",\"permissionDelete\":") sb.append(",\"permissionDelete\":")

View File

@ -2,6 +2,7 @@ package com.cm.common.pojo.bos;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -17,17 +18,10 @@ public class RoleGrantedAuthority implements GrantedAuthority {
private String role; private String role;
private String roleId; private String roleId;
private String roleName; private String roleName;
private List<RoleMenuBO> apiSaveMenu; private List<RoleMenuBO> saveMenu;
private List<RoleMenuBO> apiDeleteMenu; private List<RoleMenuBO> deleteMenu;
private List<RoleMenuBO> apiUpdateMenu; private List<RoleMenuBO> updateMenu;
private List<RoleMenuBO> apiQueryMenu; private List<RoleMenuBO> queryMenu;
private List<RoleMenuBO> resourceSaveMenu;
private List<RoleMenuBO> resourceDeleteMenu;
private List<RoleMenuBO> resourceUpdateMenu;
private List<RoleMenuBO> resourceQueryMenu;
private List<RoleMenuBO> routeSaveMenu;
private List<RoleMenuBO> routeUpdateMenu;
private List<RoleMenuBO> routeQueryMenu;
private List<PermissionBO> permissionInsert; private List<PermissionBO> permissionInsert;
private List<PermissionBO> permissionDelete; private List<PermissionBO> permissionDelete;
private List<PermissionBO> permissionUpdate; private List<PermissionBO> permissionUpdate;
@ -41,17 +35,10 @@ public class RoleGrantedAuthority implements GrantedAuthority {
this.role = role; this.role = role;
this.roleId = roleBO.getRoleId(); this.roleId = roleBO.getRoleId();
this.roleName = roleBO.getRoleName(); this.roleName = roleBO.getRoleName();
this.apiSaveMenu = roleBO.getApiSaveMenu(); this.saveMenu = roleBO.getSaveMenu();
this.apiDeleteMenu = roleBO.getApiDeleteMenu(); this.deleteMenu = roleBO.getDeleteMenu();
this.apiUpdateMenu = roleBO.getApiUpdateMenu(); this.updateMenu = roleBO.getUpdateMenu();
this.apiQueryMenu = roleBO.getApiQueryMenu(); this.queryMenu = roleBO.getQueryMenu();
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.permissionInsert = roleBO.getPermissionInsert(); this.permissionInsert = roleBO.getPermissionInsert();
this.permissionDelete = roleBO.getPermissionDelete(); this.permissionDelete = roleBO.getPermissionDelete();
this.permissionUpdate = roleBO.getPermissionUpdate(); this.permissionUpdate = roleBO.getPermissionUpdate();
@ -93,92 +80,36 @@ public class RoleGrantedAuthority implements GrantedAuthority {
this.roleName = roleName; this.roleName = roleName;
} }
public List<RoleMenuBO> getApiSaveMenu() { public List<RoleMenuBO> getSaveMenu() {
return apiSaveMenu; return saveMenu == null ? new ArrayList() : saveMenu;
} }
public void setApiSaveMenu(List<RoleMenuBO> apiSaveMenu) { public void setSaveMenu(List<RoleMenuBO> saveMenu) {
this.apiSaveMenu = apiSaveMenu; this.saveMenu = saveMenu;
} }
public List<RoleMenuBO> getApiDeleteMenu() { public List<RoleMenuBO> getDeleteMenu() {
return apiDeleteMenu; return deleteMenu == null ? new ArrayList() : deleteMenu;
} }
public void setApiDeleteMenu(List<RoleMenuBO> apiDeleteMenu) { public void setDeleteMenu(List<RoleMenuBO> deleteMenu) {
this.apiDeleteMenu = apiDeleteMenu; this.deleteMenu = deleteMenu;
} }
public List<RoleMenuBO> getApiUpdateMenu() { public List<RoleMenuBO> getUpdateMenu() {
return apiUpdateMenu; return updateMenu == null ? new ArrayList() : updateMenu;
} }
public void setApiUpdateMenu(List<RoleMenuBO> apiUpdateMenu) { public void setUpdateMenu(List<RoleMenuBO> updateMenu) {
this.apiUpdateMenu = apiUpdateMenu; this.updateMenu = updateMenu;
} }
public List<RoleMenuBO> getApiQueryMenu() { public List<RoleMenuBO> getQueryMenu() {
return apiQueryMenu; return queryMenu == null ? new ArrayList() : queryMenu;
} }
public void setApiQueryMenu(List<RoleMenuBO> apiQueryMenu) { public void setQueryMenu(List<RoleMenuBO> queryMenu) {
this.apiQueryMenu = apiQueryMenu; this.queryMenu = queryMenu;
}
public List<RoleMenuBO> getResourceSaveMenu() {
return resourceSaveMenu;
}
public void setResourceSaveMenu(List<RoleMenuBO> resourceSaveMenu) {
this.resourceSaveMenu = resourceSaveMenu;
}
public List<RoleMenuBO> getResourceDeleteMenu() {
return resourceDeleteMenu;
}
public void setResourceDeleteMenu(List<RoleMenuBO> resourceDeleteMenu) {
this.resourceDeleteMenu = resourceDeleteMenu;
}
public List<RoleMenuBO> getResourceUpdateMenu() {
return resourceUpdateMenu;
}
public void setResourceUpdateMenu(List<RoleMenuBO> resourceUpdateMenu) {
this.resourceUpdateMenu = resourceUpdateMenu;
}
public List<RoleMenuBO> getResourceQueryMenu() {
return resourceQueryMenu;
}
public void setResourceQueryMenu(List<RoleMenuBO> resourceQueryMenu) {
this.resourceQueryMenu = resourceQueryMenu;
}
public List<RoleMenuBO> getRouteSaveMenu() {
return routeSaveMenu;
}
public void setRouteSaveMenu(List<RoleMenuBO> routeSaveMenu) {
this.routeSaveMenu = routeSaveMenu;
}
public List<RoleMenuBO> getRouteUpdateMenu() {
return routeUpdateMenu;
}
public void setRouteUpdateMenu(List<RoleMenuBO> routeUpdateMenu) {
this.routeUpdateMenu = routeUpdateMenu;
}
public List<RoleMenuBO> getRouteQueryMenu() {
return routeQueryMenu;
}
public void setRouteQueryMenu(List<RoleMenuBO> routeQueryMenu) {
this.routeQueryMenu = routeQueryMenu;
} }
public List<PermissionBO> getPermissionInsert() { public List<PermissionBO> getPermissionInsert() {
@ -216,34 +147,20 @@ public class RoleGrantedAuthority implements GrantedAuthority {
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder("{"); final StringBuilder sb = new StringBuilder("{");
sb.append("\"role\":") sb.append("\"role\":\"")
.append("\"").append(role).append("\""); .append(role).append('\"');
sb.append(",\"roleId\":") sb.append(",\"roleId\":\"")
.append("\"").append(roleId).append("\""); .append(roleId).append('\"');
sb.append(",\"roleName\":") sb.append(",\"roleName\":\"")
.append("\"").append(roleName).append("\""); .append(roleName).append('\"');
sb.append(",\"apiSaveMenu\":") sb.append(",\"saveMenu\":")
.append(apiSaveMenu); .append(saveMenu);
sb.append(",\"apiDeleteMenu\":") sb.append(",\"deleteMenu\":")
.append(apiDeleteMenu); .append(deleteMenu);
sb.append(",\"apiUpdateMenu\":") sb.append(",\"updateMenu\":")
.append(apiUpdateMenu); .append(updateMenu);
sb.append(",\"apiQueryMenu\":") sb.append(",\"queryMenu\":")
.append(apiQueryMenu); .append(queryMenu);
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(",\"permissionInsert\":") sb.append(",\"permissionInsert\":")
.append(permissionInsert); .append(permissionInsert);
sb.append(",\"permissionDelete\":") sb.append(",\"permissionDelete\":")

View File

@ -18,6 +18,7 @@ public class RoleMenuBO implements Serializable {
private String apiPrefix; private String apiPrefix;
private String resourcePrefix; private String resourcePrefix;
private String routePrefix; private String routePrefix;
private String menuUrl;
public String getRoleId() { public String getRoleId() {
return roleId == null ? "" : roleId.trim(); return roleId == null ? "" : roleId.trim();
@ -67,21 +68,31 @@ public class RoleMenuBO implements Serializable {
this.routePrefix = routePrefix; this.routePrefix = routePrefix;
} }
public String getMenuUrl() {
return menuUrl == null ? "" : menuUrl;
}
public void setMenuUrl(String menuUrl) {
this.menuUrl = menuUrl;
}
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder("{"); final StringBuilder sb = new StringBuilder("{");
sb.append("\"roleId\":") sb.append("\"roleId\":\"")
.append("\"").append(roleId).append("\""); .append(roleId).append('\"');
sb.append(",\"roleType\":") sb.append(",\"roleType\":\"")
.append("\"").append(roleType).append("\""); .append(roleType).append('\"');
sb.append(",\"menuId\":") sb.append(",\"menuId\":\"")
.append("\"").append(menuId).append("\""); .append(menuId).append('\"');
sb.append(",\"apiPrefix\":") sb.append(",\"apiPrefix\":\"")
.append("\"").append(apiPrefix).append("\""); .append(apiPrefix).append('\"');
sb.append(",\"resourcePrefix\":") sb.append(",\"resourcePrefix\":\"")
.append("\"").append(resourcePrefix).append("\""); .append(resourcePrefix).append('\"');
sb.append(",\"routePrefix\":") sb.append(",\"routePrefix\":\"")
.append("\"").append(routePrefix).append("\""); .append(routePrefix).append('\"');
sb.append(",\"menuUrl\":\"")
.append(menuUrl).append('\"');
sb.append('}'); sb.append('}');
return sb.toString(); return sb.toString();
} }

View File

@ -66,17 +66,10 @@ public class RbacServiceImpl implements IRbacService {
RoleBO roleBO = new RoleBO(); RoleBO roleBO = new RoleBO();
roleBO.setRoleId(authorityObject.getString("roleId")); roleBO.setRoleId(authorityObject.getString("roleId"));
roleBO.setRoleName(authorityObject.getString("roleName")); roleBO.setRoleName(authorityObject.getString("roleName"));
roleBO.setApiSaveMenu(JSON.parseArray(authorityObject.getString("apiSaveMenu"), RoleMenuBO.class)); roleBO.setSaveMenu(JSON.parseArray(authorityObject.getString("saveMenu"), RoleMenuBO.class));
roleBO.setApiDeleteMenu(JSON.parseArray(authorityObject.getString("apiDeleteMenu"), RoleMenuBO.class)); roleBO.setDeleteMenu(JSON.parseArray(authorityObject.getString("deleteMenu"), RoleMenuBO.class));
roleBO.setApiUpdateMenu(JSON.parseArray(authorityObject.getString("apiSaveMenu"), RoleMenuBO.class)); roleBO.setUpdateMenu(JSON.parseArray(authorityObject.getString("updateMenu"), RoleMenuBO.class));
roleBO.setApiQueryMenu(JSON.parseArray(authorityObject.getString("apiQueryMenu"), RoleMenuBO.class)); roleBO.setQueryMenu(JSON.parseArray(authorityObject.getString("queryMenu"), 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));
roleGrantedAuthority = new RoleGrantedAuthority(authorityObject.getString("authority"), roleBO); 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) { private boolean hasSavePermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) {
List<String> savePaths = accessControl.getSavePaths(); List<String> savePaths = accessControl.getSavePaths();
// 匹配接口 // 匹配接口
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiSaveMenu()) { for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getSaveMenu()) {
for (String savePath : savePaths) { for (String savePath : savePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + savePath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + savePath, uri)) {
return true; return true;
} }
}
}
// 匹配资源
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceSaveMenu()) {
for (String savePath : savePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + savePath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + savePath, uri)) {
return true; return true;
} }
}
}
// 匹配路由
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteSaveMenu()) {
for (String savePath : savePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + savePath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + savePath, uri)) {
return true; return true;
} }
@ -188,16 +171,11 @@ public class RbacServiceImpl implements IRbacService {
private boolean hasDeletePermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) { private boolean hasDeletePermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) {
List<String> deletePaths = accessControl.getDeletePaths(); List<String> deletePaths = accessControl.getDeletePaths();
// 匹配接口 // 匹配接口
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiDeleteMenu()) { for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getDeleteMenu()) {
for (String deletePath : deletePaths) { for (String deletePath : deletePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + deletePath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + deletePath, uri)) {
return true; return true;
} }
}
}
// 匹配资源
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceDeleteMenu()) {
for (String deletePath : deletePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + deletePath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + deletePath, uri)) {
return true; return true;
} }
@ -217,24 +195,14 @@ public class RbacServiceImpl implements IRbacService {
private boolean hasUpdatePermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) { private boolean hasUpdatePermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) {
List<String> updatePaths = accessControl.getUpdatePaths(); List<String> updatePaths = accessControl.getUpdatePaths();
// 匹配接口 // 匹配接口
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiUpdateMenu()) { for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getUpdateMenu()) {
for (String updatePath : updatePaths) { for (String updatePath : updatePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + updatePath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + updatePath, uri)) {
return true; return true;
} }
}
}
// 匹配资源
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceUpdateMenu()) {
for (String updatePath : updatePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + updatePath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + updatePath, uri)) {
return true; return true;
} }
}
}
// 匹配路由
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteUpdateMenu()) {
for (String updatePath : updatePaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + updatePath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + updatePath, uri)) {
return true; return true;
} }
@ -254,25 +222,15 @@ public class RbacServiceImpl implements IRbacService {
private boolean hasQueryPermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) { private boolean hasQueryPermission(String contextPath, String uri, RoleGrantedAuthority roleGrantedAuthority, AntPathMatcher antPathMatcher) {
List<String> queryPaths = accessControl.getQueryPaths(); List<String> queryPaths = accessControl.getQueryPaths();
// 匹配接口 // 匹配接口
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getApiQueryMenu()) { for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getQueryMenu()) {
for (String queryPath : queryPaths) { for (String queryPath : queryPaths) {
String queryAntPath = contextPath + roleMenuBO.getApiPrefix() + queryPath; String queryAntPath = contextPath + roleMenuBO.getApiPrefix() + queryPath;
if (antPathMatcher.match(queryAntPath, uri)) { if (antPathMatcher.match(queryAntPath, uri)) {
return true; return true;
} }
}
}
// 匹配资源
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceQueryMenu()) {
for (String queryPath : queryPaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + queryPath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + queryPath, uri)) {
return true; return true;
} }
}
}
// 匹配路由
for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getRouteQueryMenu()) {
for (String queryPath : queryPaths) {
if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + queryPath, uri)) { if (antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + queryPath, uri)) {
return true; return true;
} }