修改权限

This commit is contained in:
wanggeng888 2021-06-22 17:20:49 +08:00
parent 94c88f8eea
commit 43d3fb7ae0
5 changed files with 45 additions and 106 deletions

View File

@ -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()));

View File

@ -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<String> 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<String> 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<String> 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<String> 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;
}
}

View File

@ -23,6 +23,8 @@ import java.util.Map;
**/
public interface IMenuService {
String PARENT_MENU_URL = "javascript:void(0);";
/**
* 菜单列表
*

View File

@ -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<RoleMenuBO> roleMenuBOs = listRoleMenuDetail(params);
List<RoleMenuBO> apiSaveMenu = new ArrayList<>(0);
List<RoleMenuBO> apiDeleteMenu = new ArrayList<>(0);
List<RoleMenuBO> apiUpdateMenu = new ArrayList<>(0);
List<RoleMenuBO> apiQueryMenu = new ArrayList<>(0);
List<RoleMenuBO> resourceSaveMenu = new ArrayList<>(0);
List<RoleMenuBO> resourceDeleteMenu = new ArrayList<>(0);
List<RoleMenuBO> resourceUpdateMenu = new ArrayList<>(0);
List<RoleMenuBO> resourceQueryMenu = new ArrayList<>(0);
List<RoleMenuBO> routeSaveMenu = new ArrayList<>(0);
List<RoleMenuBO> routeUpdateMenu = new ArrayList<>(0);
List<RoleMenuBO> routeQueryMenu = new ArrayList<>(0);
List<RoleMenuBO> saveMenu = new ArrayList<>(0);
List<RoleMenuBO> deleteMenu = new ArrayList<>(0);
List<RoleMenuBO> updateMenu = new ArrayList<>(0);
List<RoleMenuBO> queryMenu = new ArrayList<>(0);
List<PermissionBO> permissionInsert = new ArrayList<>(0);
List<PermissionBO> 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());

View File

@ -40,6 +40,7 @@
<result property="apiPrefix" column="api_prefix"/>
<result property="resourcePrefix" column="resource_prefix"/>
<result property="routePrefix" column="route_prefix"/>
<result property="menuUrl" column="menu_url"/>
</resultMap>
<resultMap id="roleZTreeDTO" type="com.cm.common.pojo.dtos.ZTreeDTO">
@ -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