⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entitypermissionchecker.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        //Iterator iterType = targetOperationList.iterator();        //while (iterType.hasNext()) {        //    String op = (String)iterType.next();        //    condList.add(new EntityExpr(lcEntityName + "OperationId", EntityOperator.EQUALS, op));        //}        //EntityCondition opCond = new EntityConditionList(condList, EntityOperator.OR);                EntityCondition opCond = new EntityExpr(lcEntityName + "OperationId", EntityOperator.IN, targetOperationList);                List targetOperationEntityList = delegator.findByConditionCache(modelOperationEntity.getEntityName(), opCond, null, null);        Map entities = new HashMap();        String pkFieldName = modelEntity.getFirstPkFieldName();            //TODO: privilegeEnumId test        /*        if (hasPrivilegeOp && hasPrivilegeField) {            int privilegeEnumSeq = -1;                        if ( UtilValidate.isNotEmpty(privilegeEnumId)) {                GenericValue privEnum = delegator.findByPrimaryKeyCache("Enumeration", UtilMisc.toMap("enumId", privilegeEnumId));                if (privEnum != null) {                    String sequenceId = privEnum.getString("sequenceId");                       try {                        privilegeEnumSeq = Integer.parseInt(sequenceId);                    } catch(NumberFormatException e) {                        // just leave it at -1                       }                }            }            boolean thisPassed = true;             Iterator iter = entityIdList.iterator();            while (iter.hasNext()) {                GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, iter.next(), entities);                if (entity == null) continue;                                   String entityId = entity.getString(pkFieldName);                String targetPrivilegeEnumId = entity.getString("privilegeEnumId");                if (UtilValidate.isNotEmpty(targetPrivilegeEnumId)) {                    int targetPrivilegeEnumSeq = -1;                    GenericValue privEnum = delegator.findByPrimaryKeyCache("Enumeration", UtilMisc.toMap("enumId", privilegeEnumId));                    if (privEnum != null) {                        String sequenceId = privEnum.getString("sequenceId");                           try {                            targetPrivilegeEnumSeq = Integer.parseInt(sequenceId);                        } catch(NumberFormatException e) {                            // just leave it at -1                           }                        if (targetPrivilegeEnumSeq > privilegeEnumSeq) {                            return false;                           }                    }                }                entities.put(entityId, entity);            }        }        */                // check permission for each id in passed list until success.        // Note that "quickCheck" id come first in the list        // Check with no roles or purposes on the chance that the permission fields contain _NA_ s.        List alreadyCheckedIds = new ArrayList();        Map purposes = new HashMap();        Map roles = new HashMap();        Iterator iter = entityIdList.iterator();        //List purposeList = null;        //List roleList = null;        while (iter.hasNext()) {               GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, iter.next(), entities);             if (entity == null) continue;                               String statusId = null;            if (hasStatusOp && hasStatusField) {                statusId = entity.getString("statusId");            }                        int privilegeEnumSeq = -1;            if (hasPrivilegeOp && hasPrivilegeField) {                privilegeEnumId = entity.getString("privilegeEnumId");                privilegeEnumSeq = getPrivilegeEnumSeq(delegator, privilegeEnumId);            }                           passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId);            if (passed) {                break;            }       }                if (passed) {            return true;        }                if (hasPurposeOp) {            // Check with just purposes next.            iter = entityIdList.iterator();            while (iter.hasNext()) {                GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, iter.next(), entities);                if (entity == null) continue;                                 String entityId = entity.getString(pkFieldName);                purposeList = getRelatedPurposes(entity, null);                String statusId = null;                if (hasStatusOp && hasStatusField) {                    statusId = entity.getString("statusId");                }                                if (purposeList.size() > 0) {                    passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId);                }                if (passed){                    break;                }                purposes.put(entityId, purposeList);            }        }                if (passed)            return true;                if (userLogin == null)            return false;            // Check with roles.        iter = entityIdList.iterator();        while (iter.hasNext()) {            GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, iter.next(), entities);            if (entity == null) continue;            String entityId = entity.getString(pkFieldName);            List tmpPurposeList = (List)purposes.get(entityId);            if (purposeList != null ) {                if (tmpPurposeList != null) {                    purposeList.addAll(tmpPurposeList);                }            } else {                 purposeList = tmpPurposeList;            }                            List tmpRoleList = getUserRoles(entity, userLogin, delegator);            if (roleList != null ) {                if (tmpRoleList != null) {                    roleList.addAll(tmpRoleList);                }            } else {                 roleList = tmpRoleList;            }                String statusId = null;            if (hasStatusOp && hasStatusField) {                statusId = entity.getString("statusId");            }                           passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId);            if (passed) {                break;            }            roles.put(entityId, roleList);        }                if (passed)            return true;                // Follow ownedEntityIds        if (modelEntity.getField("owner" + entityName + "Id") != null) {            iter = entityIdList.iterator();            while (iter.hasNext()) {                GenericValue entity = getNextEntity(delegator, entityName, pkFieldName, iter.next(), entities);                if (entity == null) continue;                                String entityId = entity.getString(pkFieldName);                List ownedContentIdList = new ArrayList();                getEntityOwners(delegator, entity, ownedContentIdList, "Content", "ownerContentId");                    List ownedContentRoleIds = getUserRolesFromList(delegator, ownedContentIdList, partyId, "contentId", "partyId", "roleTypeId", "ContentRole");                String statusId = null;                if (hasStatusOp && hasStatusField) {                    statusId = entity.getString("statusId");                }                                   purposeList = (List)purposes.get(entityId);                passed = hasMatch(entityName, targetOperationEntityList, ownedContentRoleIds, hasPurposeOp, purposeList, hasStatusOp, statusId);                if (passed) break;                               /*                    String ownedEntityId = entity.getString("owner" + entityName + "Id");                   GenericValue ownedEntity = delegator.findByPrimaryKeyCache(entityName,UtilMisc.toMap(pkFieldName, ownedEntityId));                   while (ownedEntity != null) {                       if (!alreadyCheckedIds.contains(ownedEntityId)) {                        // Decided to let the original purposes only be used in permission checking                        //                         //purposeList = (List)purposes.get(entityId);                        //purposeList = getRelatedPurposes(ownedEntity, purposeList);                        roleList = getUserRoles(ownedEntity, userLogin, delegator);                                    String statusId = null;                        if (hasStatusOp && hasStatusField) {                            statusId = entity.getString("statusId");                        }                                                   passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId);                        if (passed)                            break;                        alreadyCheckedIds.add(ownedEntityId);                       //purposes.put(ownedEntityId, purposeList);                        //roles.put(ownedEntityId, roleList);                           ownedEntityId = ownedEntity.getString("owner" + entityName + "Id");                           ownedEntity = delegator.findByPrimaryKeyCache(entityName,UtilMisc.toMap(pkFieldName, ownedEntityId));                       } else {                          ownedEntity = null;                       }                   }                   if (passed)                       break;                       */            }        }                        /* seems like repeat        // Check parents        iter = entityIdList.iterator();        while (iter.hasNext()) {            String entityId = (String)iter.next();               GenericValue entity = (GenericValue)entities.get(entityId);            purposeList = (List)purposes.get(entityId);            roleList = getUserRoles(entity, userLogin, delegator);                String statusId = null;            if (hasStatusOp && hasStatusField) {                statusId = entity.getString("statusId");            }            String targetPrivilegeEnumId = null;            if (hasPrivilegeOp && hasPrivilegeField) {                targetPrivilegeEnumId = entity.getString("privilegeEnumId");            }                           passed = hasMatch(entityName, targetOperationEntityList, roleList, hasPurposeOp, purposeList, hasStatusOp, statusId);            if (passed)                break;            alreadyCheckedIds.add(entityId);        }        */                return passed;    }    public static boolean checkPermissionMethod(GenericDelegator delegator, String partyId,  String entityName, List entityIdList, AuxiliaryValueGetter auxiliaryValueGetter, RelatedRoleGetter relatedRoleGetter, PermissionConditionGetter permissionConditionGetter) throws GenericEntityException {            permissionConditionGetter.init(delegator);        if (Debug.verboseOn()) Debug.logVerbose(permissionConditionGetter.dumpAsText(), module);        boolean passed = false;            String lcEntityName = entityName.toLowerCase();        String userLoginId = null;        boolean checkAncestors = false;        boolean hasRoleOperation =  checkHasRoleOperations(partyId, permissionConditionGetter, delegator);        if( hasRoleOperation ) {            return true;        }        ModelEntity modelEntity = delegator.getModelEntity(entityName);                if (relatedRoleGetter != null) {            if (UtilValidate.isNotEmpty(partyId)) {                relatedRoleGetter.setList(UtilMisc.toList("LOGGEDIN"));               }        }                // check permission for each id in passed list until success.        // Note that "quickCheck" id come first in the list        // Check with no roles or purposes on the chance that the permission fields contain _NA_ s.        String pkFieldName = modelEntity.getFirstPkFieldName();        if (Debug.infoOn()) {        String entityIdString = "ENTITIES: ";        for (int i=0; i < entityIdList.size(); i++) {            Object obj = entityIdList.get(i);            if (obj instanceof GenericValue) {                String s = ((GenericValue)obj).getString(pkFieldName);                entityIdString += s + "  ";            } else {                entityIdString += obj + "  ";            }        }            //if (Debug.infoOn()) Debug.logInfo(entityIdString, module);        }                List alreadyCheckedIds = new ArrayList();        Map entities = new HashMap();        Iterator iter = entityIdList.iterator();        //List purposeList = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -