Search in sources :

Example 1 with XXPolicyResourceMap

use of org.apache.ranger.entity.XXPolicyResourceMap in project ranger by apache.

the class ServiceDBStore method deleteExistingPolicyResources.

private Boolean deleteExistingPolicyResources(RangerPolicy policy) {
    if (policy == null) {
        return false;
    }
    List<XXPolicyResource> resources = daoMgr.getXXPolicyResource().findByPolicyId(policy.getId());
    XXPolicyResourceDao resDao = daoMgr.getXXPolicyResource();
    for (XXPolicyResource resource : resources) {
        List<XXPolicyResourceMap> resMapList = daoMgr.getXXPolicyResourceMap().findByPolicyResId(resource.getId());
        XXPolicyResourceMapDao resMapDao = daoMgr.getXXPolicyResourceMap();
        for (XXPolicyResourceMap resMap : resMapList) {
            resMapDao.remove(resMap);
        }
        resDao.remove(resource);
    }
    return true;
}
Also used : XXPolicyResource(org.apache.ranger.entity.XXPolicyResource) XXPolicyResourceDao(org.apache.ranger.db.XXPolicyResourceDao) XXPolicyResourceMap(org.apache.ranger.entity.XXPolicyResourceMap) XXPolicyResourceMapDao(org.apache.ranger.db.XXPolicyResourceMapDao)

Example 2 with XXPolicyResourceMap

use of org.apache.ranger.entity.XXPolicyResourceMap in project ranger by apache.

the class ServiceDBStore method createNewResourcesForPolicy.

private void createNewResourcesForPolicy(RangerPolicy policy, XXPolicy xPolicy, Map<String, RangerPolicyResource> resources) throws Exception {
    for (Entry<String, RangerPolicyResource> resource : resources.entrySet()) {
        RangerPolicyResource policyRes = resource.getValue();
        XXResourceDef xResDef = daoMgr.getXXResourceDef().findByNameAndPolicyId(resource.getKey(), policy.getId());
        if (xResDef == null) {
            throw new Exception(resource.getKey() + ": is not a valid resource-type. policy='" + policy.getName() + "' service='" + policy.getService() + "'");
        }
        XXPolicyResource xPolRes = new XXPolicyResource();
        xPolRes = rangerAuditFields.populateAuditFields(xPolRes, xPolicy);
        xPolRes.setIsExcludes(policyRes.getIsExcludes());
        xPolRes.setIsRecursive(policyRes.getIsRecursive());
        xPolRes.setPolicyId(policy.getId());
        xPolRes.setResDefId(xResDef.getId());
        xPolRes = daoMgr.getXXPolicyResource().create(xPolRes);
        List<String> values = policyRes.getValues();
        if (CollectionUtils.isNotEmpty(values)) {
            Set<String> uniqueValues = new LinkedHashSet<String>(values);
            int i = 0;
            if (CollectionUtils.isNotEmpty(uniqueValues)) {
                for (String uniqValue : uniqueValues) {
                    if (!StringUtils.isEmpty(uniqValue)) {
                        XXPolicyResourceMap xPolResMap = new XXPolicyResourceMap();
                        xPolResMap = (XXPolicyResourceMap) rangerAuditFields.populateAuditFields(xPolResMap, xPolRes);
                        xPolResMap.setResourceId(xPolRes.getId());
                        xPolResMap.setValue(uniqValue);
                        xPolResMap.setOrder(i);
                        xPolResMap = daoMgr.getXXPolicyResourceMap().create(xPolResMap);
                        i++;
                    }
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XXPolicyResource(org.apache.ranger.entity.XXPolicyResource) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) XXPolicyResourceMap(org.apache.ranger.entity.XXPolicyResourceMap) VXString(org.apache.ranger.view.VXString) XXResourceDef(org.apache.ranger.entity.XXResourceDef) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) JSONException(org.codehaus.jettison.json.JSONException)

Example 3 with XXPolicyResourceMap

use of org.apache.ranger.entity.XXPolicyResourceMap in project ranger by apache.

the class ServiceDBStore method deleteXXPolicyResource.

public void deleteXXPolicyResource(XXPolicyResource xPolRes) {
    List<XXPolicyResourceMap> polResMapList = daoMgr.getXXPolicyResourceMap().findByPolicyResId(xPolRes.getId());
    XXPolicyResourceMapDao polResMapDao = daoMgr.getXXPolicyResourceMap();
    for (XXPolicyResourceMap xxPolResMap : polResMapList) {
        polResMapDao.remove(xxPolResMap);
    }
    daoMgr.getXXPolicyResource().remove(xPolRes);
}
Also used : XXPolicyResourceMap(org.apache.ranger.entity.XXPolicyResourceMap) XXPolicyResourceMapDao(org.apache.ranger.db.XXPolicyResourceMapDao)

Aggregations

XXPolicyResourceMap (org.apache.ranger.entity.XXPolicyResourceMap)3 XXPolicyResourceMapDao (org.apache.ranger.db.XXPolicyResourceMapDao)2 XXPolicyResource (org.apache.ranger.entity.XXPolicyResource)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 LinkedHashSet (java.util.LinkedHashSet)1 XXPolicyResourceDao (org.apache.ranger.db.XXPolicyResourceDao)1 XXResourceDef (org.apache.ranger.entity.XXResourceDef)1 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)1 VXString (org.apache.ranger.view.VXString)1 JSONException (org.codehaus.jettison.json.JSONException)1