diff --git a/src/main/java/com/cm/serviceusercenter/controller/apis/system/menu/MenuController.java b/src/main/java/com/cm/serviceusercenter/controller/apis/system/menu/MenuController.java index 143aa7d..62c1d7b 100644 --- a/src/main/java/com/cm/serviceusercenter/controller/apis/system/menu/MenuController.java +++ b/src/main/java/com/cm/serviceusercenter/controller/apis/system/menu/MenuController.java @@ -105,8 +105,8 @@ public class MenuController extends BaseController { params.put("menuStatus", menuVO.getMenuStatus()); if (StringUtils.isBlank(menuVO.getMenuUrl())) { - params.put("menuUrl", "javascript:void(0);"); - } else if (StringUtils.equals(menuVO.getMenuUrl(), "javascript:void(0);")) { + params.put("menuUrl", IMenuService.PARENT_MENU_URL); + } else if (StringUtils.equals(menuVO.getMenuUrl(), IMenuService.PARENT_MENU_URL)) { params.put("menuUrl", menuVO.getMenuUrl()); } else { params.put("menuUrl", addSlash(menuVO.getMenuUrl())); diff --git a/src/main/java/com/cm/serviceusercenter/service/rbac/impl/UserRbacServiceImpl.java b/src/main/java/com/cm/serviceusercenter/service/rbac/impl/UserRbacServiceImpl.java index d7ba7a2..14ac197 100644 --- a/src/main/java/com/cm/serviceusercenter/service/rbac/impl/UserRbacServiceImpl.java +++ b/src/main/java/com/cm/serviceusercenter/service/rbac/impl/UserRbacServiceImpl.java @@ -11,7 +11,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.stereotype.Component; import org.springframework.util.AntPathMatcher; @@ -54,7 +53,7 @@ public class UserRbacServiceImpl implements IRbacService { String contextPath = request.getContextPath(); for (GrantedAuthority grantedAuthority : grantedAuthorities) { // 权限类型错误,认证失败 - if(!(grantedAuthority instanceof RoleGrantedAuthority)) { + if (!(grantedAuthority instanceof RoleGrantedAuthority)) { return false; } RoleGrantedAuthority roleGrantedAuthority = (RoleGrantedAuthority) grantedAuthority; @@ -135,25 +134,15 @@ public class UserRbacServiceImpl implements IRbacService { } 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; } } @@ -178,17 +167,12 @@ public class UserRbacServiceImpl implements IRbacService { } 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; } } @@ -213,25 +197,15 @@ public class UserRbacServiceImpl implements IRbacService { } 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; } } @@ -256,26 +230,15 @@ public class UserRbacServiceImpl implements IRbacService { } 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)) { + if (!StringUtils.isBlank(roleMenuBO.getApiPrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getApiPrefix() + queryPath, uri)) { return true; } - } - } - // 匹配资源 - for (RoleMenuBO roleMenuBO : roleGrantedAuthority.getResourceQueryMenu()) { - for (String queryPath : queryPaths) { - if (antPathMatcher.match(contextPath + roleMenuBO.getResourcePrefix() + queryPath, uri)) { + if (!StringUtils.isBlank(roleMenuBO.getResourcePrefix()) && 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)) { + if (!StringUtils.isBlank(roleMenuBO.getRoutePrefix()) && antPathMatcher.match(contextPath + roleMenuBO.getRoutePrefix() + queryPath, uri)) { return true; } } diff --git a/src/main/java/com/cm/serviceusercenter/service/system/menu/IMenuService.java b/src/main/java/com/cm/serviceusercenter/service/system/menu/IMenuService.java index 2ee3f1c..ffc933a 100644 --- a/src/main/java/com/cm/serviceusercenter/service/system/menu/IMenuService.java +++ b/src/main/java/com/cm/serviceusercenter/service/system/menu/IMenuService.java @@ -23,6 +23,8 @@ import java.util.Map; **/ public interface IMenuService { + String PARENT_MENU_URL = "javascript:void(0);"; + /** * 菜单列表 * diff --git a/src/main/java/com/cm/serviceusercenter/service/system/role/impl/RoleServiceImpl.java b/src/main/java/com/cm/serviceusercenter/service/system/role/impl/RoleServiceImpl.java index 6b8f67d..d2d9c09 100644 --- a/src/main/java/com/cm/serviceusercenter/service/system/role/impl/RoleServiceImpl.java +++ b/src/main/java/com/cm/serviceusercenter/service/system/role/impl/RoleServiceImpl.java @@ -18,11 +18,11 @@ import com.cm.serviceusercenter.pojo.dtos.RoleDTO; import com.cm.serviceusercenter.pojo.dtos.permission.PermissionRoleDTO; import com.cm.serviceusercenter.pojo.dtos.role.RoleDataAuthorityDTO; import com.cm.serviceusercenter.pojo.dtos.role.RoleDataAuthorityTypeDTO; -import com.cm.serviceusercenter.pojo.vos.permission.PermissionRoleVO; import com.cm.serviceusercenter.pojo.vos.role.RoleDataAuthorityVO; import com.cm.serviceusercenter.pojo.vos.role.RoleUserAuthorityVO; import com.cm.serviceusercenter.service.BaseService; import com.cm.serviceusercenter.service.permission.IPermissionService; +import com.cm.serviceusercenter.service.system.menu.IMenuService; import com.cm.serviceusercenter.service.system.role.IRoleService; import com.cm.serviceusercenter.service.system.user.IUserService; import com.github.pagehelper.PageHelper; @@ -166,19 +166,10 @@ public class RoleServiceImpl extends BaseService implements IRoleService { params.put("roleId", roleId); List roleMenuBOs = listRoleMenuDetail(params); - List apiSaveMenu = new ArrayList<>(0); - List apiDeleteMenu = new ArrayList<>(0); - List apiUpdateMenu = new ArrayList<>(0); - List apiQueryMenu = new ArrayList<>(0); - - List resourceSaveMenu = new ArrayList<>(0); - List resourceDeleteMenu = new ArrayList<>(0); - List resourceUpdateMenu = new ArrayList<>(0); - List resourceQueryMenu = new ArrayList<>(0); - - List routeSaveMenu = new ArrayList<>(0); - List routeUpdateMenu = new ArrayList<>(0); - List routeQueryMenu = new ArrayList<>(0); + List saveMenu = new ArrayList<>(0); + List deleteMenu = new ArrayList<>(0); + List updateMenu = new ArrayList<>(0); + List queryMenu = new ArrayList<>(0); List permissionInsert = new ArrayList<>(0); List permissionDelete = new ArrayList<>(0); @@ -187,41 +178,29 @@ public class RoleServiceImpl extends BaseService implements IRoleService { LOG.debug("角色菜单权限"); for (RoleMenuBO roleMenuBO : roleMenuBOs) { - roleMenuBO.setApiPrefix(roleMenuBO.getApiPrefix()); - roleMenuBO.setResourcePrefix(roleMenuBO.getResourcePrefix()); - roleMenuBO.setRoutePrefix(roleMenuBO.getRoutePrefix()); + if(StringUtils.equals(roleMenuBO.getMenuUrl(), IMenuService.PARENT_MENU_URL)) { + roleMenuBO.setApiPrefix(null); + roleMenuBO.setResourcePrefix(null); + roleMenuBO.setRoutePrefix(null); + } if (IRoleService.ROLE_INSERT.equals(roleMenuBO.getRoleType())) { - apiSaveMenu.add(roleMenuBO); - resourceSaveMenu.add(roleMenuBO); - routeSaveMenu.add(roleMenuBO); + saveMenu.add(roleMenuBO); } else if (IRoleService.ROLE_DELETE.equals(roleMenuBO.getRoleType())) { - apiDeleteMenu.add(roleMenuBO); - resourceDeleteMenu.add(roleMenuBO); + deleteMenu.add(roleMenuBO); } else if (IRoleService.ROLE_UPDATE.equals(roleMenuBO.getRoleType())) { - apiUpdateMenu.add(roleMenuBO); - resourceUpdateMenu.add(roleMenuBO); - routeUpdateMenu.add(roleMenuBO); + updateMenu.add(roleMenuBO); } else if (IRoleService.ROLE_QUERY.equals(roleMenuBO.getRoleType())) { - apiQueryMenu.add(roleMenuBO); - resourceQueryMenu.add(roleMenuBO); - routeQueryMenu.add(roleMenuBO); + queryMenu.add(roleMenuBO); } } LOG.debug("角色接口权限"); setApiPermission(roleId, permissionInsert, permissionDelete, permissionUpdate, permissionQuery); RoleBO roleBO = new RoleBO(); roleBO.setRoleId(roleId); - roleBO.setApiSaveMenu(apiSaveMenu); - roleBO.setApiDeleteMenu(apiDeleteMenu); - roleBO.setApiUpdateMenu(apiUpdateMenu); - roleBO.setApiQueryMenu(apiQueryMenu); - roleBO.setResourceSaveMenu(resourceSaveMenu); - roleBO.setResourceDeleteMenu(resourceDeleteMenu); - roleBO.setResourceUpdateMenu(resourceUpdateMenu); - roleBO.setResourceQueryMenu(resourceQueryMenu); - roleBO.setRouteSaveMenu(routeSaveMenu); - roleBO.setRouteUpdateMenu(routeUpdateMenu); - roleBO.setRouteQueryMenu(routeQueryMenu); + roleBO.setSaveMenu(saveMenu); + roleBO.setDeleteMenu(deleteMenu); + roleBO.setUpdateMenu(updateMenu); + roleBO.setQueryMenu(queryMenu); roleBO.setPermissionInsert(permissionInsert); roleBO.setPermissionDelete(permissionDelete); roleBO.setPermissionUpdate(permissionUpdate); @@ -304,17 +283,10 @@ public class RoleServiceImpl extends BaseService implements IRoleService { @Override public void setRoleMenu(RoleBO roleBO) throws SearchException { RoleBO role = getRoleBOByRoleId(roleBO.getRoleId()); - roleBO.setApiSaveMenu(role.getApiSaveMenu()); - roleBO.setApiDeleteMenu(role.getApiDeleteMenu()); - roleBO.setApiUpdateMenu(role.getApiUpdateMenu()); - roleBO.setApiQueryMenu(role.getApiQueryMenu()); - roleBO.setResourceSaveMenu(role.getResourceSaveMenu()); - roleBO.setResourceDeleteMenu(role.getResourceDeleteMenu()); - roleBO.setResourceUpdateMenu(role.getResourceUpdateMenu()); - roleBO.setResourceQueryMenu(role.getResourceQueryMenu()); - roleBO.setRouteSaveMenu(role.getRouteSaveMenu()); - roleBO.setRouteUpdateMenu(role.getRouteUpdateMenu()); - roleBO.setRouteQueryMenu(role.getRouteQueryMenu()); + roleBO.setSaveMenu(role.getSaveMenu()); + roleBO.setDeleteMenu(role.getDeleteMenu()); + roleBO.setUpdateMenu(role.getUpdateMenu()); + roleBO.setQueryMenu(role.getQueryMenu()); roleBO.setPermissionInsert(role.getPermissionInsert()); roleBO.setPermissionDelete(role.getPermissionDelete()); roleBO.setPermissionUpdate(role.getPermissionUpdate()); diff --git a/src/main/resources/mybatis/mapper/system/role/role-mapper.xml b/src/main/resources/mybatis/mapper/system/role/role-mapper.xml index 810049b..0fa6002 100644 --- a/src/main/resources/mybatis/mapper/system/role/role-mapper.xml +++ b/src/main/resources/mybatis/mapper/system/role/role-mapper.xml @@ -40,6 +40,7 @@ + @@ -327,7 +328,8 @@ t1.*, t2.api_prefix, t2.resource_prefix, - t2.route_prefix + t2.route_prefix, + t2.menu_url FROM sys_role_menu t1 LEFT JOIN