zoukankan      html  css  js  c++  java
  • 权限 粒度化 到 系统 部门 部门及子部门 个人用户

    AuthOperater 负责检查权限
    1. //
    2. // Source code recreated from a .class file by IntelliJ IDEA
    3. // (powered by Fernflower decompiler)
    4. //
    5. package cn.com.do1.component.systemmgr.auth;
    6. import cn.com.do1.common.util.string.StringUtil;
    7. import cn.com.do1.component.systemmgr.auth.AuthQuickDac;
    8. import cn.com.do1.component.systemmgr.auth.UserAuth;
    9. import cn.com.do1.component.systemmgr.util.CollectionUtils;
    10. import cn.com.do1.component.systemmgr.util.SystemRoleCacheMgr;
    11. import cn.com.do1.component.systemmgr.util.Constants.ACCESS_LEVEL;
    12. import cn.com.do1.dqdp.core.DqdpAppContext;
    13. import java.util.ArrayList;
    14. import java.util.Collections;
    15. import java.util.Iterator;
    16. import java.util.List;
    17. import java.util.Map;
    18. import org.springframework.security.core.GrantedAuthority;
    19. import org.springframework.security.core.userdetails.UserDetails;
    20. public class AuthOperater {
    21. public AuthOperater() {
    22. }
    23. //查询 权限code的级别
    24. public static int ckCurrentUserPerAccessLevel(String permissionCode) throws Exception {
    25. if(permissionCode == null) {
    26. throw new Exception("权限代码不能为空!");
    27. } else if(UserAuth.isSuperUser()) {
    28. return ACCESS_LEVEL.ALL.value();
    29. } else {
    30. String[] roleIds = UserAuth.getSessionPerson().getRoleIds().split(",");
    31. ArrayList accessLevList = new ArrayList();
    32. String[] var6 = roleIds;
    33. int var5 = roleIds.length;
    34. for(int var4 = 0; var4 < var5; ++var4) {
    35. String roleid = var6[var4];
    36. List perlist = SystemRoleCacheMgr.getOPermissByRoleId(roleid);
    37. Iterator var9 = perlist.iterator();
    38. while(var9.hasNext()) {
    39. Map per = (Map)var9.next();
    40. if(per.get("PERMISSION_CODE").toString().equalsIgnoreCase(permissionCode)) {
    41. accessLevList.add(Integer.valueOf(per.get("ACCESS_LEVEL").toString()));
    42. }
    43. }
    44. }
    45. if(accessLevList.size() <= 0) {
    46. return ACCESS_LEVEL.NOT_HAS.value();
    47. } else {
    48. return ((Integer)Collections.min(accessLevList)).intValue();
    49. }
    50. }
    51. }
    52. //检查当前用户是否包含权限code
    53. public static boolean ckCurrentUserHasPer(String permissionCode) throws Exception {
    54. if(permissionCode == null) {
    55. return false;
    56. } else if(UserAuth.isSuperUser()) {
    57. return true;
    58. } else {
    59. UserDetails userDetails = DqdpAppContext.getCurrentUser();
    60. Iterator var3 = userDetails.getAuthorities().iterator();
    61. while(var3.hasNext()) {
    62. GrantedAuthority grantedAuthority = (GrantedAuthority)var3.next();
    63. try {
    64. if("all".equals(permissionCode) || StringUtil.isInContainer(permissionCode.split(","), grantedAuthority.getAuthority())) {
    65. return true;
    66. }
    67. } catch (Exception var4) {
    68. return false;
    69. }
    70. }
    71. return false;
    72. }
    73. }
    74. //检查用户针对改权限拥有的级别所有的部门id
    75. public static String ckUserModuelPreDepts(String permissionCode) throws Exception {
    76. int accessCode = ckCurrentUserPerAccessLevel(permissionCode);
    77. if(accessCode != ACCESS_LEVEL.NOT_HAS.value() && accessCode != ACCESS_LEVEL.USER.value()) {
    78. if(accessCode != ACCESS_LEVEL.ALL.value() && accessCode != ACCESS_LEVEL.SYSTEM_USER.value()) {
    79. ArrayList deptList = null;
    80. if(accessCode == ACCESS_LEVEL.DEPT.value()) {
    81. deptList = (ArrayList)AuthQuickDac.getContext().searchUserDeptLevelOrg(UserAuth.getSessionUser().getId().toLowerCase());
    82. }
    83. if(accessCode == ACCESS_LEVEL.DEPT_AND_CHILDREN.value()) {
    84. deptList = (ArrayList)AuthQuickDac.getContext().searchUserDChildLevOrg(UserAuth.getSessionUser().getId().toLowerCase());
    85. }
    86. deptList = (ArrayList)CollectionUtils.replaceList(deptList);
    87. return CollectionUtils.listToString(deptList);
    88. } else {
    89. return "all";
    90. }
    91. } else {
    92. return null;
    93. }
    94. }
    95. }
    AuthQuickDac 负责查询权限粒度

    1. //
    2. // Source code recreated from a .class file by IntelliJ IDEA
    3. // (powered by Fernflower decompiler)
    4. //
    5. package cn.com.do1.component.systemmgr.auth;
    6. import cn.com.do1.common.dac.QuickDAC;
    7. import cn.com.do1.component.systemmgr.org.model.TbDqdpOrgPO;
    8. import cn.com.do1.component.systemmgr.user.model.TbUserRoleDeptRefPO;
    9. import cn.com.do1.component.systemmgr.util.CollectionUtils;
    10. import cn.com.do1.component.systemmgr.util.SystemCacheUtils;
    11. import cn.com.do1.dqdp.core.DqdpAppContext;
    12. import java.sql.SQLException;
    13. import java.util.ArrayList;
    14. import java.util.Iterator;
    15. import java.util.List;
    16. import java.util.Map;
    17. import java.util.concurrent.TimeUnit;
    18. import java.util.concurrent.locks.ReentrantLock;
    19. import javax.sql.DataSource;
    20. import org.slf4j.Logger;
    21. import org.slf4j.LoggerFactory;
    22. public class AuthQuickDac {
    23. private static final Logger logger = LoggerFactory.getLogger(AuthQuickDac.class);
    24. private static ReentrantLock lock = new ReentrantLock(true);
    25. private static ThreadLocal<Integer> executeCount = new ThreadLocal();
    26. private static AuthQuickDac authQuickDac;
    27. private DataSource ds;
    28. private AuthQuickDac() {
    29. executeCount.set(Integer.valueOf(5));
    30. this.ds = (DataSource)DqdpAppContext.getSpringContext().getBean("dataSource");
    31. }
    32. public static AuthQuickDac getContext() {
    33. try {
    34. lock.lock();
    35. if(authQuickDac == null) {
    36. authQuickDac = new AuthQuickDac();
    37. }
    38. } finally {
    39. lock.unlock();
    40. }
    41. return authQuickDac;
    42. }
    43. private boolean getLook() {
    44. try {
    45. if(lock.tryLock(30L, TimeUnit.MILLISECONDS)) {
    46. executeCount.set(Integer.valueOf(0));
    47. logger.info("获取锁成功");
    48. return true;
    49. } else {
    50. logger.info("在指定的时间内未能获取到锁");
    51. if(5 <= ((Integer)executeCount.get()).intValue()) {
    52. logger.info("系统连续5次获取锁失败");
    53. return false;
    54. } else {
    55. executeCount.set(Integer.valueOf(((Integer)executeCount.get()).intValue() + 1));
    56. return this.getLook();
    57. }
    58. }
    59. } catch (InterruptedException var2) {
    60. logger.error(var2.getMessage(), var2);
    61. return false;
    62. }
    63. }
    64. public List searchUserDeptLevelOrg(String userid) {
    65. if(!this.getLook()) {
    66. return null;
    67. } else {
    68. QuickDAC quickDAC = null;
    69. try {
    70. quickDAC = new QuickDAC(this.ds.getConnection());
    71. quickDAC.preparedSql("select * from TB_USER_ROLE_DEPT_REF where USER_ID=:userid");
    72. quickDAC.setPreValue("userid", userid);
    73. List e = quickDAC.getList(TbUserRoleDeptRefPO.class);
    74. ArrayList depss = new ArrayList();
    75. if(e.size() > 0) {
    76. Iterator var6 = e.iterator();
    77. while(var6.hasNext()) {
    78. TbUserRoleDeptRefPO tbUserRoleDeptRefPO = (TbUserRoleDeptRefPO)var6.next();
    79. depss.add(tbUserRoleDeptRefPO.getOrgId());
    80. }
    81. }
    82. ArrayList var8 = depss;
    83. return var8;
    84. } catch (Exception var11) {
    85. logger.error(var11.getMessage(), var11);
    86. } finally {
    87. lock.unlock();
    88. quickDAC.destoryWithoutConnection();
    89. }
    90. return null;
    91. }
    92. }
    93. public List searchUserDChildLevOrg(String userid) {
    94. if(!this.getLook()) {
    95. return null;
    96. } else {
    97. QuickDAC quickDAC = null;
    98. try {
    99. quickDAC = new QuickDAC(this.ds.getConnection());
    100. quickDAC.preparedSql("select * from TB_USER_ROLE_DEPT_REF where USER_ID=:userid");
    101. quickDAC.setPreValue("userid", userid);
    102. List e = quickDAC.getList(TbUserRoleDeptRefPO.class);
    103. ArrayList depss = new ArrayList();
    104. Iterator orgid = e.iterator();
    105. while(orgid.hasNext()) {
    106. TbUserRoleDeptRefPO list = (TbUserRoleDeptRefPO)orgid.next();
    107. depss.add(list.getOrgId());
    108. }
    109. depss = (ArrayList)CollectionUtils.replaceList(depss);
    110. ArrayList list1 = new ArrayList();
    111. if(depss.size() > 0) {
    112. Iterator var7 = depss.iterator();
    113. while(var7.hasNext()) {
    114. String orgid1 = (String)var7.next();
    115. if(SystemCacheUtils.getOrgByOrgId(orgid1).get("IS_PARENT").toString().equalsIgnoreCase("0")) {
    116. Map org = SystemCacheUtils.getOrgByOrgId(orgid1);
    117. CollectionUtils.addListToList(list1, this.searchOrgByLRVal(quickDAC, org.get("LEFTVALUE").toString(), org.get("RIGHTVALUE").toString()));
    118. }
    119. }
    120. }
    121. CollectionUtils.addListToList(list1, depss);
    122. ArrayList var10 = list1;
    123. return var10;
    124. } catch (Exception var13) {
    125. logger.error(var13.getMessage(), var13);
    126. } finally {
    127. lock.unlock();
    128. quickDAC.destoryWithoutConnection();
    129. }
    130. return null;
    131. }
    132. }
    133. private List searchOrgByLRVal(QuickDAC qac, String leftVal, String rightVal) throws SQLException {
    134. qac.preparedSql("select * from TB_DQDP_ORGANIZATION where LEFTVALUE >:leftval and RIGHTVALUE <:rightval");
    135. qac.setPreValue("leftval", leftVal);
    136. qac.setPreValue("rightval", rightVal);
    137. List list = qac.getList(TbDqdpOrgPO.class);
    138. ArrayList orgs = new ArrayList();
    139. if(list.size() > 0) {
    140. Iterator var7 = list.iterator();
    141. while(var7.hasNext()) {
    142. TbDqdpOrgPO tbDqdpOrgPO = (TbDqdpOrgPO)var7.next();
    143. orgs.add(tbDqdpOrgPO.getOrganizationId());
    144. }
    145. }
    146. return orgs;
    147. }
    148. }




  • 相关阅读:
    HttpClientUtil
    JacksonUtils
    spring-security oauth2.0简单集成
    python连接mysql
    钉钉机器人消息体
    Android Studio gradle
    Android Studio从Eclipse导项目
    Docker
    Unity WebGL
    主席树
  • 原文地址:https://www.cnblogs.com/signheart/p/35171d5442c61100204cf7b54183cf45.html
Copyright © 2011-2022 走看看