新增系统数据权限控制
This commit is contained in:
parent
b3c1b2bf65
commit
cd51281e8e
@ -0,0 +1,37 @@
|
||||
package com.cm.common.plugin.dao.authority;
|
||||
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: IAuthorityDao
|
||||
* @Description: 权限
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/12/14 11:01 上午
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Repository
|
||||
public interface IAuthorityDao {
|
||||
|
||||
/**
|
||||
* 新增人员权限
|
||||
*
|
||||
* @param params
|
||||
* @throws SaveException
|
||||
*/
|
||||
void saveAuthorityUser(Map<String, Object> params) throws SaveException;
|
||||
|
||||
/**
|
||||
* 删除人员权限
|
||||
*
|
||||
* @param params
|
||||
* @throws RemoveException
|
||||
*/
|
||||
void deleteAuthorityUser(Map<String, Object> params) throws RemoveException;
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.cm.common.plugin.enums.role;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: RoleDataAuthorityEnum
|
||||
* @Description: 数据权限
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/11/23 9:43 下午
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public enum RoleDataAuthorityEnum {
|
||||
|
||||
ALL("all"),
|
||||
DEPARTMENT("department"),
|
||||
CUSTOM("custom"),
|
||||
SELF("self");
|
||||
|
||||
private String dataAuthorityType;
|
||||
|
||||
RoleDataAuthorityEnum(String dataAuthorityType) {
|
||||
this.dataAuthorityType = dataAuthorityType;
|
||||
}
|
||||
|
||||
public String getDataAuthorityType() {
|
||||
return dataAuthorityType == null ? "" : dataAuthorityType.trim();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.cm.common.plugin.pojo.vos.authority;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: AuthorityUserVO
|
||||
* @Description: 权限
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/12/14 11:06 上午
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class AuthorityUserVO {
|
||||
|
||||
private String userId;
|
||||
private String managedUserId;
|
||||
|
||||
public String getUserId() {
|
||||
return userId == null ? "" : userId.trim();
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getManagedUserId() {
|
||||
return managedUserId == null ? "" : managedUserId.trim();
|
||||
}
|
||||
|
||||
public void setManagedUserId(String managedUserId) {
|
||||
this.managedUserId = managedUserId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"userId\":")
|
||||
.append("\"").append(userId).append("\"");
|
||||
sb.append(",\"managedUserId\":")
|
||||
.append("\"").append(managedUserId).append("\"");
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.cm.common.plugin.service.authority;
|
||||
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.plugin.pojo.vos.authority.AuthorityUserVO;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: IAuthorityService
|
||||
* @Description: 权限
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/12/14 11:00 上午
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public interface IAuthorityService {
|
||||
|
||||
/**
|
||||
* 新增人员权限
|
||||
*
|
||||
* @param authorityUserVO
|
||||
* @throws SaveException
|
||||
*/
|
||||
void saveAuthorityUser(AuthorityUserVO authorityUserVO) throws Exception;
|
||||
|
||||
/**
|
||||
* 删除人员权限
|
||||
*
|
||||
* @param userId
|
||||
* @throws RemoveException
|
||||
*/
|
||||
void deleteAuthorityUserByUserId(String userId) throws RemoveException;
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.cm.common.plugin.service.authority.impl;
|
||||
|
||||
import com.cm.common.base.AbstractService;
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.plugin.dao.authority.IAuthorityDao;
|
||||
import com.cm.common.plugin.pojo.vos.authority.AuthorityUserVO;
|
||||
import com.cm.common.plugin.service.authority.IAuthorityService;
|
||||
import com.cm.common.utils.HashMapUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: AuthorityServiceImpl
|
||||
* @Description: 权限
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/12/14 11:01 上午
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Service
|
||||
public class AuthorityServiceImpl extends AbstractService implements IAuthorityService {
|
||||
|
||||
@Autowired
|
||||
private IAuthorityDao authorityDao;
|
||||
|
||||
@Override
|
||||
public void saveAuthorityUser(AuthorityUserVO authorityUserVO) throws Exception {
|
||||
Map<String, Object> params = HashMapUtil.beanToMap(authorityUserVO);
|
||||
authorityDao.saveAuthorityUser(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAuthorityUserByUserId(String userId) throws RemoveException {
|
||||
Map<String, Object> params = getHashMap(1);
|
||||
params.put("userId", userId);
|
||||
authorityDao.deleteAuthorityUser(params);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cm.common.plugin.dao.authority.IAuthorityDao">
|
||||
|
||||
<!-- 新增人员权限 -->
|
||||
<insert id="saveAuthorityUser" parameterType="map">
|
||||
INSERT INTO authority_user(
|
||||
user_id,
|
||||
managed_user_id
|
||||
) VALUES (
|
||||
#{userId},
|
||||
#{managedUserId}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 删除人员权限 -->
|
||||
<delete id="deleteAuthorityUser" parameterType="map">
|
||||
DELETE FROM
|
||||
authority_user
|
||||
WHERE
|
||||
<if test="userId != null and userId != ''">
|
||||
user_id = #{userId}
|
||||
</if>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
@ -45,6 +45,10 @@ public abstract class AbstractController {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
String showLevel = "showLevel";
|
||||
if (StringUtils.isEmpty(params.get(showLevel))) {
|
||||
params.put(showLevel, "0");
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.cm.common.base;
|
||||
|
||||
import com.cm.common.component.SecurityComponent;
|
||||
import com.cm.common.constants.ISystemConstant;
|
||||
import com.cm.common.pojo.bos.UserInfoBO;
|
||||
import com.cm.common.pojo.dtos.ZTreeDTO;
|
||||
import com.cm.common.token.app.AppTokenManager;
|
||||
@ -15,6 +16,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -29,7 +31,7 @@ public abstract class AbstractService {
|
||||
|
||||
protected static Logger LOG = LoggerFactory.getLogger(AbstractService.class);
|
||||
@Autowired
|
||||
private SecurityComponent securityComponent;
|
||||
protected SecurityComponent securityComponent;
|
||||
@Autowired
|
||||
private HttpSession httpSession;
|
||||
|
||||
@ -152,4 +154,28 @@ public abstract class AbstractService {
|
||||
protected Map<String, Object> getHashMap(int initSize) {
|
||||
return new HashMap<>(initSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否管理员
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected boolean isAdmin() {
|
||||
if (ISystemConstant.ADMIN.equalsIgnoreCase(securityComponent.getCurrentUsername())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取基础部门ID列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected List<String> listBaseDepartmentIds() {
|
||||
if (isAdmin()) {
|
||||
return null;
|
||||
}
|
||||
return securityComponent.getCurrentUser().getBaseDepartmentIds();
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,9 @@ public class SecurityComponent {
|
||||
userInfoBO.setUserId(userBO.getUserId());
|
||||
userInfoBO.setUserUsername(userBO.getUsername());
|
||||
userInfoBO.setUserPhone(userBO.getUserPhone());
|
||||
userInfoBO.setDataAuthority(userBO.getDataAuthority());
|
||||
userInfoBO.setDataAuthorityUserIds(userBO.getDataAuthorityUserIds());
|
||||
userInfoBO.setBaseDepartmentIds(userBO.getBaseDepartmentIds());
|
||||
}
|
||||
if (user instanceof UserInfoBO) {
|
||||
userInfoBO = (UserInfoBO) user;
|
||||
@ -62,7 +65,8 @@ public class SecurityComponent {
|
||||
Collection<? extends GrantedAuthority> grantedAuthorities = authentication.getAuthorities();
|
||||
List<String> roleIds = new ArrayList<>();
|
||||
for (GrantedAuthority grantedAuthority : grantedAuthorities) {
|
||||
RoleGrantedAuthority roleGrantedAuthority = (RoleGrantedAuthority) grantedAuthority;;
|
||||
RoleGrantedAuthority roleGrantedAuthority = (RoleGrantedAuthority) grantedAuthority;
|
||||
;
|
||||
roleIds.add(roleGrantedAuthority.getRoleId());
|
||||
}
|
||||
return roleIds;
|
||||
|
@ -84,5 +84,20 @@ public interface ISystemConstant {
|
||||
* 参数id
|
||||
*/
|
||||
String PARAMS_ID = "id";
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
String DATA_CREATOR = "data_creator";
|
||||
/**
|
||||
* 创建人列
|
||||
*/
|
||||
String DATA_AUTHORITY = "data_authority";
|
||||
/**
|
||||
* 树根节点ID
|
||||
*/
|
||||
String TREE_ROOT_ID = "0";
|
||||
/**
|
||||
* admin
|
||||
*/
|
||||
String ADMIN = "admin";
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ public class DepartmentBO implements Serializable {
|
||||
private static final long serialVersionUID = -8160484188600622923L;
|
||||
private String departmentId;
|
||||
private String departmentName;
|
||||
private String departmentCode;
|
||||
private String departmentSummary;
|
||||
|
||||
public String getDepartmentId() {
|
||||
@ -32,6 +33,14 @@ public class DepartmentBO implements Serializable {
|
||||
this.departmentName = departmentName;
|
||||
}
|
||||
|
||||
public String getDepartmentCode() {
|
||||
return departmentCode == null ? "" : departmentCode.trim();
|
||||
}
|
||||
|
||||
public void setDepartmentCode(String departmentCode) {
|
||||
this.departmentCode = departmentCode;
|
||||
}
|
||||
|
||||
public String getDepartmentSummary() {
|
||||
return departmentSummary == null ? "" : departmentSummary.trim();
|
||||
}
|
||||
@ -47,6 +56,8 @@ public class DepartmentBO implements Serializable {
|
||||
.append("\"").append(departmentId).append("\"");
|
||||
sb.append(",\"departmentName\":")
|
||||
.append("\"").append(departmentName).append("\"");
|
||||
sb.append(",\"departmentCode\":")
|
||||
.append("\"").append(departmentCode).append("\"");
|
||||
sb.append(",\"departmentSummary\":")
|
||||
.append("\"").append(departmentSummary).append("\"");
|
||||
sb.append('}');
|
||||
|
@ -15,6 +15,7 @@ public class RoleBO {
|
||||
private String roleId;
|
||||
private String roleName;
|
||||
private String roleSummary;
|
||||
private String roleDataAuthority;
|
||||
private List<RoleMenuBO> apiSaveMenu = new ArrayList<>();
|
||||
private List<RoleMenuBO> apiDeleteMenu = new ArrayList<>();
|
||||
private List<RoleMenuBO> apiUpdateMenu = new ArrayList<>();
|
||||
@ -51,6 +52,14 @@ public class RoleBO {
|
||||
this.roleSummary = roleSummary;
|
||||
}
|
||||
|
||||
public String getRoleDataAuthority() {
|
||||
return roleDataAuthority == null ? "" : roleDataAuthority.trim();
|
||||
}
|
||||
|
||||
public void setRoleDataAuthority(String roleDataAuthority) {
|
||||
this.roleDataAuthority = roleDataAuthority;
|
||||
}
|
||||
|
||||
public List<RoleMenuBO> getApiSaveMenu() {
|
||||
return apiSaveMenu;
|
||||
}
|
||||
@ -148,6 +157,8 @@ public class RoleBO {
|
||||
.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\":")
|
||||
|
@ -18,6 +18,9 @@ public class UserBO extends User {
|
||||
private String userId;
|
||||
private String userName;
|
||||
private String userPhone;
|
||||
private String dataAuthority;
|
||||
private List<String> baseDepartmentIds;
|
||||
private List<String> dataAuthorityUserIds;
|
||||
private List<RoleBO> roles;
|
||||
private List<GroupBO> groups;
|
||||
private List<DepartmentBO> departments;
|
||||
@ -58,6 +61,30 @@ public class UserBO extends User {
|
||||
this.userPhone = userPhone;
|
||||
}
|
||||
|
||||
public List<String> getBaseDepartmentIds() {
|
||||
return baseDepartmentIds;
|
||||
}
|
||||
|
||||
public void setBaseDepartmentIds(List<String> baseDepartmentIds) {
|
||||
this.baseDepartmentIds = baseDepartmentIds;
|
||||
}
|
||||
|
||||
public String getDataAuthority() {
|
||||
return dataAuthority == null ? "" : dataAuthority.trim();
|
||||
}
|
||||
|
||||
public void setDataAuthority(String dataAuthority) {
|
||||
this.dataAuthority = dataAuthority;
|
||||
}
|
||||
|
||||
public List<String> getDataAuthorityUserIds() {
|
||||
return dataAuthorityUserIds;
|
||||
}
|
||||
|
||||
public void setDataAuthorityUserIds(List<String> dataAuthorityUserIds) {
|
||||
this.dataAuthorityUserIds = dataAuthorityUserIds;
|
||||
}
|
||||
|
||||
public List<RoleBO> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
@ -91,6 +118,12 @@ public class UserBO extends User {
|
||||
.append("\"").append(userName).append("\"");
|
||||
sb.append(",\"userPhone\":")
|
||||
.append("\"").append(userPhone).append("\"");
|
||||
sb.append(",\"dataAuthority\":")
|
||||
.append("\"").append(dataAuthority).append("\"");
|
||||
sb.append(",\"baseDepartmentIds\":")
|
||||
.append(baseDepartmentIds);
|
||||
sb.append(",\"dataAuthorityUserIds\":")
|
||||
.append(dataAuthorityUserIds);
|
||||
sb.append(",\"roles\":")
|
||||
.append(roles);
|
||||
sb.append(",\"groups\":")
|
||||
|
@ -15,6 +15,9 @@ public class UserInfoBO {
|
||||
private String userUsername;
|
||||
private String userName;
|
||||
private String userPhone;
|
||||
private String dataAuthority;
|
||||
private List<String> dataAuthorityUserIds;
|
||||
private List<String> baseDepartmentIds;
|
||||
private List<DepartmentBO> departments;
|
||||
|
||||
public String getUserId() {
|
||||
@ -49,6 +52,30 @@ public class UserInfoBO {
|
||||
this.userPhone = userPhone;
|
||||
}
|
||||
|
||||
public String getDataAuthority() {
|
||||
return dataAuthority == null ? "" : dataAuthority.trim();
|
||||
}
|
||||
|
||||
public void setDataAuthority(String dataAuthority) {
|
||||
this.dataAuthority = dataAuthority;
|
||||
}
|
||||
|
||||
public List<String> getDataAuthorityUserIds() {
|
||||
return dataAuthorityUserIds;
|
||||
}
|
||||
|
||||
public void setDataAuthorityUserIds(List<String> dataAuthorityUserIds) {
|
||||
this.dataAuthorityUserIds = dataAuthorityUserIds;
|
||||
}
|
||||
|
||||
public List<String> getBaseDepartmentIds() {
|
||||
return baseDepartmentIds;
|
||||
}
|
||||
|
||||
public void setBaseDepartmentIds(List<String> baseDepartmentIds) {
|
||||
this.baseDepartmentIds = baseDepartmentIds;
|
||||
}
|
||||
|
||||
public List<DepartmentBO> getDepartments() {
|
||||
return departments;
|
||||
}
|
||||
@ -68,6 +95,12 @@ public class UserInfoBO {
|
||||
.append("\"").append(userName).append("\"");
|
||||
sb.append(",\"userPhone\":")
|
||||
.append("\"").append(userPhone).append("\"");
|
||||
sb.append(",\"dataAuthority\":")
|
||||
.append("\"").append(dataAuthority).append("\"");
|
||||
sb.append(",\"dataAuthorityUserIds\":")
|
||||
.append(dataAuthorityUserIds);
|
||||
sb.append(",\"baseDepartmentIds\":")
|
||||
.append(baseDepartmentIds);
|
||||
sb.append(",\"departments\":")
|
||||
.append(departments);
|
||||
sb.append('}');
|
||||
|
Loading…
Reference in New Issue
Block a user