Search in sources :

Example 1 with XXPolicyRefConditionDao

use of org.apache.ranger.db.XXPolicyRefConditionDao in project ranger by apache.

the class PatchForMigratingOldRegimePolicyJson_J10046 method addPolicyConditionDefRef.

private void addPolicyConditionDefRef(String serviceType, Long policyId, Set<String> conditions) throws Exception {
    logger.info("==> addPolicyConditionDefRef(id=" + policyId + ")");
    // insert policy-id, conditionName into Ref table
    Map<String, Long> serviceDefConditionNameIDMap = conditionNameIdMap.get(serviceType);
    if (serviceDefConditionNameIDMap == null) {
        serviceDefConditionNameIDMap = new HashMap<>();
        conditionNameIdMap.put(serviceType, serviceDefConditionNameIDMap);
        XXServiceDef dbServiceDef = daoMgr.getXXServiceDef().findByName(serviceType);
        for (XXPolicyConditionDef conditionDef : daoMgr.getXXPolicyConditionDef().findByServiceDefId(dbServiceDef.getId())) {
            serviceDefConditionNameIDMap.put(conditionDef.getName(), conditionDef.getId());
        }
    }
    XXPolicyRefConditionDao policyRefConditionDao = daoMgr.getXXPolicyRefCondition();
    for (String condition : conditions) {
        Long conditionDefId = serviceDefConditionNameIDMap.get(condition);
        if (conditionDefId == null) {
            throw new Exception(condition + ": unknown condition in policy [id=" + policyId + "; serviceType=" + serviceType + "]. Known conditions are: " + serviceDefConditionNameIDMap.keySet());
        }
        XXPolicyRefCondition policyRefCondition = new XXPolicyRefCondition();
        policyRefCondition.setPolicyId(policyId);
        policyRefCondition.setConditionName(condition);
        policyRefCondition.setConditionDefId(conditionDefId);
        policyRefConditionDao.create(policyRefCondition);
    }
    logger.info("<== addPolicyConditionDefRef(id=" + policyId + ")");
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXPolicyConditionDef(org.apache.ranger.entity.XXPolicyConditionDef) XXPolicyRefCondition(org.apache.ranger.entity.XXPolicyRefCondition) XXPolicyRefConditionDao(org.apache.ranger.db.XXPolicyRefConditionDao)

Example 2 with XXPolicyRefConditionDao

use of org.apache.ranger.db.XXPolicyRefConditionDao in project ranger by apache.

the class PatchForUpdatingPolicyJson_J10019 method addPolicyConditionDefRef.

private void addPolicyConditionDefRef(String serviceType, Long policyId, Set<String> conditions) throws Exception {
    logger.info("==> addPolicyConditionDefRef(id=" + policyId + ")");
    // insert policy-id, conditionName into Ref table
    Map<String, Long> serviceDefConditionNameIDMap = conditionNameIdMap.get(serviceType);
    if (serviceDefConditionNameIDMap == null) {
        serviceDefConditionNameIDMap = new HashMap<>();
        conditionNameIdMap.put(serviceType, serviceDefConditionNameIDMap);
        XXServiceDef dbServiceDef = daoMgr.getXXServiceDef().findByName(serviceType);
        for (XXPolicyConditionDef conditionDef : daoMgr.getXXPolicyConditionDef().findByServiceDefId(dbServiceDef.getId())) {
            serviceDefConditionNameIDMap.put(conditionDef.getName(), conditionDef.getId());
        }
    }
    XXPolicyRefConditionDao policyRefConditionDao = daoMgr.getXXPolicyRefCondition();
    for (String condition : conditions) {
        Long conditionDefId = serviceDefConditionNameIDMap.get(condition);
        if (conditionDefId == null) {
            throw new Exception(condition + ": unknown condition in policy [id=" + policyId + "; serviceType=" + serviceType + "]. Known conditions are: " + serviceDefConditionNameIDMap.keySet());
        }
        XXPolicyRefCondition policyRefCondition = new XXPolicyRefCondition();
        policyRefCondition.setPolicyId(policyId);
        policyRefCondition.setConditionName(condition);
        policyRefCondition.setConditionDefId(conditionDefId);
        policyRefConditionDao.create(policyRefCondition);
    }
    logger.info("<== addPolicyConditionDefRef(id=" + policyId + ")");
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXPolicyConditionDef(org.apache.ranger.entity.XXPolicyConditionDef) XXPolicyRefCondition(org.apache.ranger.entity.XXPolicyRefCondition) XXPolicyRefConditionDao(org.apache.ranger.db.XXPolicyRefConditionDao)

Aggregations

XXPolicyRefConditionDao (org.apache.ranger.db.XXPolicyRefConditionDao)2 XXPolicyConditionDef (org.apache.ranger.entity.XXPolicyConditionDef)2 XXPolicyRefCondition (org.apache.ranger.entity.XXPolicyRefCondition)2 XXServiceDef (org.apache.ranger.entity.XXServiceDef)2