Search in sources :

Example 1 with XXPolicyRefAccessTypeDao

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

the class PatchForMigratingOldRegimePolicyJson_J10046 method addAccessDefRef.

private void addAccessDefRef(String serviceType, Long policyId, Set<String> accesses) throws Exception {
    logger.info("==> addAccessDefRef(id=" + policyId + ")");
    // insert policy-id, accessName into Ref table
    Map<String, Long> serviceDefAccessTypeIDMap = accessTypeIdMap.get(serviceType);
    if (serviceDefAccessTypeIDMap == null) {
        serviceDefAccessTypeIDMap = new HashMap<>();
        accessTypeIdMap.put(serviceType, serviceDefAccessTypeIDMap);
        XXServiceDef dbServiceDef = daoMgr.getXXServiceDef().findByName(serviceType);
        for (XXAccessTypeDef accessTypeDef : daoMgr.getXXAccessTypeDef().findByServiceDefId(dbServiceDef.getId())) {
            serviceDefAccessTypeIDMap.put(accessTypeDef.getName(), accessTypeDef.getId());
        }
    }
    XXPolicyRefAccessTypeDao policyRefAccessTypeDao = daoMgr.getXXPolicyRefAccessType();
    for (String access : accesses) {
        Long accessTypeDefId = serviceDefAccessTypeIDMap.get(access);
        if (accessTypeDefId == null) {
            throw new Exception(access + ": unknown accessType in policy [id=" + policyId + "; serviceType=" + serviceType + "]. Known accessTypes: " + serviceDefAccessTypeIDMap.keySet());
        }
        XXPolicyRefAccessType policyRefAccessType = new XXPolicyRefAccessType();
        policyRefAccessType.setPolicyId(policyId);
        policyRefAccessType.setAccessTypeName(access);
        policyRefAccessType.setAccessDefId(accessTypeDefId);
        policyRefAccessTypeDao.create(policyRefAccessType);
    }
    logger.info("<== addAccessDefRef(id=" + policyId + ")");
}
Also used : XXPolicyRefAccessType(org.apache.ranger.entity.XXPolicyRefAccessType) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) XXPolicyRefAccessTypeDao(org.apache.ranger.db.XXPolicyRefAccessTypeDao)

Example 2 with XXPolicyRefAccessTypeDao

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

the class PatchForUpdatingPolicyJson_J10019 method addAccessDefRef.

private void addAccessDefRef(String serviceType, Long policyId, Set<String> accesses) throws Exception {
    logger.info("==> addAccessDefRef(id=" + policyId + ")");
    // insert policy-id, accessName into Ref table
    Map<String, Long> serviceDefAccessTypeIDMap = accessTypeIdMap.get(serviceType);
    if (serviceDefAccessTypeIDMap == null) {
        serviceDefAccessTypeIDMap = new HashMap<>();
        accessTypeIdMap.put(serviceType, serviceDefAccessTypeIDMap);
        XXServiceDef dbServiceDef = daoMgr.getXXServiceDef().findByName(serviceType);
        for (XXAccessTypeDef accessTypeDef : daoMgr.getXXAccessTypeDef().findByServiceDefId(dbServiceDef.getId())) {
            serviceDefAccessTypeIDMap.put(accessTypeDef.getName(), accessTypeDef.getId());
        }
    }
    XXPolicyRefAccessTypeDao policyRefAccessTypeDao = daoMgr.getXXPolicyRefAccessType();
    for (String access : accesses) {
        Long accessTypeDefId = serviceDefAccessTypeIDMap.get(access);
        if (accessTypeDefId == null) {
            throw new Exception(access + ": unknown accessType in policy [id=" + policyId + "; serviceType=" + serviceType + "]. Known accessTypes: " + serviceDefAccessTypeIDMap.keySet());
        }
        XXPolicyRefAccessType policyRefAccessType = new XXPolicyRefAccessType();
        policyRefAccessType.setPolicyId(policyId);
        policyRefAccessType.setAccessTypeName(access);
        policyRefAccessType.setAccessDefId(accessTypeDefId);
        policyRefAccessTypeDao.create(policyRefAccessType);
    }
    logger.info("<== addAccessDefRef(id=" + policyId + ")");
}
Also used : XXPolicyRefAccessType(org.apache.ranger.entity.XXPolicyRefAccessType) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) XXPolicyRefAccessTypeDao(org.apache.ranger.db.XXPolicyRefAccessTypeDao)

Aggregations

XXPolicyRefAccessTypeDao (org.apache.ranger.db.XXPolicyRefAccessTypeDao)2 XXAccessTypeDef (org.apache.ranger.entity.XXAccessTypeDef)2 XXPolicyRefAccessType (org.apache.ranger.entity.XXPolicyRefAccessType)2 XXServiceDef (org.apache.ranger.entity.XXServiceDef)2