代码优化

master
星期八 6 years ago
parent 6fa176c3a6
commit a25aaf417b
  1. 8
      src/main/java/com/lq/code/interceptor/shiro/ShiroRealm.java
  2. 36
      src/main/java/com/lq/code/util/Constant.java

@ -4,6 +4,7 @@ import com.lq.cms.service.SysRoleResourcePermissionService;
import com.lq.cms.service.SysRoleService;
import com.lq.cms.service.SysUserService;
import com.lq.cms.vo.PermissionVo;
import com.lq.code.util.Constant;
import com.lq.code.util.StringUtil;
import com.lq.entity.SysRole;
import com.lq.entity.SysUser;
@ -23,6 +24,7 @@ import java.util.List;
*/
public class ShiroRealm extends AuthorizingRealm {
@Autowired
private SysUserService sysUserService;
@Autowired
@ -50,16 +52,16 @@ public class ShiroRealm extends AuthorizingRealm {
info.addRole(sysRoleName);
List<PermissionVo> list = null;
//admin默认获取全部权限
if (StringUtil.isNotNull(sysRoleName)&&"admin".equals(sysRoleName)){
if (StringUtil.isNotNull(sysRoleName)&& Constant.ROLE_ADMIN.equals(sysRoleName)){
list = sysRoleResourcePermissionService.findAllPermissonVo();
}else {
list = sysRoleResourcePermissionService.findByRoleId(sysRole.getId());
}
//每个角色拥有的权限
for (PermissionVo vo:list){
info.addStringPermission(vo.getMenuUrl()+":"+vo.getPermissionName());
info.addStringPermission(vo.getMenuUrl()+Constant.PERSSION_MARK+vo.getPermissionName());
}
if ("admin".equals(sysRoleName)){
if (Constant.ROLE_ADMIN.equals(sysRoleName)){
break;
}

@ -0,0 +1,36 @@
package com.lq.code.util;
/**
* @Author: qi
* @Description:
* @Date: Create in 11:20 AM 2019/3/23
*/
public interface Constant {
/**
* 权限-新增
*/
String PERMISSION_INSERT = "INSERT";
/**
* 权限-更新
*/
String PERMISSION_UPDATE = "UPDATE";
/**
* 权限-查询
*/
String PERMISSION_SELECT="SELECT";
/**
* 权限-删除
*/
String PERMISSION_DELETE = "DELETE";
/**
* 权限-描述切割符号
*/
String PERSSION_MARK = ":";
/**
* 超级管理员
*/
String ROLE_ADMIN = "admin";
}
Loading…
Cancel
Save