Search in sources :

Example 6 with XXAccessTypeDef

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

the class ServiceDBStore method createNewPolicyItemForPolicy.

private XXPolicyItem createNewPolicyItemForPolicy(RangerPolicy policy, XXPolicy xPolicy, RangerPolicyItem policyItem, XXServiceDef xServiceDef, int itemOrder, int policyItemType) throws Exception {
    XXPolicyItem xPolicyItem = new XXPolicyItem();
    xPolicyItem = rangerAuditFields.populateAuditFields(xPolicyItem, xPolicy);
    xPolicyItem.setDelegateAdmin(policyItem.getDelegateAdmin());
    xPolicyItem.setItemType(policyItemType);
    xPolicyItem.setIsEnabled(Boolean.TRUE);
    xPolicyItem.setComments(null);
    xPolicyItem.setPolicyId(policy.getId());
    xPolicyItem.setOrder(itemOrder);
    xPolicyItem = daoMgr.getXXPolicyItem().create(xPolicyItem);
    List<RangerPolicyItemAccess> accesses = policyItem.getAccesses();
    for (int i = 0; i < accesses.size(); i++) {
        RangerPolicyItemAccess access = accesses.get(i);
        XXAccessTypeDef xAccTypeDef = daoMgr.getXXAccessTypeDef().findByNameAndServiceId(access.getType(), xPolicy.getService());
        if (xAccTypeDef == null) {
            throw new Exception(access.getType() + ": is not a valid access-type. policy='" + policy.getName() + "' service='" + policy.getService() + "'");
        }
        XXPolicyItemAccess xPolItemAcc = new XXPolicyItemAccess();
        xPolItemAcc = (XXPolicyItemAccess) rangerAuditFields.populateAuditFields(xPolItemAcc, xPolicyItem);
        xPolItemAcc.setIsAllowed(access.getIsAllowed());
        xPolItemAcc.setType(xAccTypeDef.getId());
        xPolItemAcc.setPolicyitemid(xPolicyItem.getId());
        xPolItemAcc.setOrder(i);
        daoMgr.getXXPolicyItemAccess().create(xPolItemAcc);
    }
    List<String> users = policyItem.getUsers();
    for (int i = 0; i < users.size(); i++) {
        String user = users.get(i);
        if (StringUtils.isBlank(user)) {
            continue;
        }
        XXUser xUser = daoMgr.getXXUser().findByUserName(user);
        if (xUser == null) {
            throw new Exception(user + ": user does not exist. policy='" + policy.getName() + "' service='" + policy.getService() + "' user='" + user + "'");
        }
        XXPolicyItemUserPerm xUserPerm = new XXPolicyItemUserPerm();
        xUserPerm = rangerAuditFields.populateAuditFields(xUserPerm, xPolicyItem);
        xUserPerm.setUserId(xUser.getId());
        xUserPerm.setPolicyItemId(xPolicyItem.getId());
        xUserPerm.setOrder(i);
        xUserPerm = daoMgr.getXXPolicyItemUserPerm().create(xUserPerm);
    }
    List<String> groups = policyItem.getGroups();
    for (int i = 0; i < groups.size(); i++) {
        String group = groups.get(i);
        if (StringUtils.isBlank(group)) {
            continue;
        }
        XXGroup xGrp = daoMgr.getXXGroup().findByGroupName(group);
        if (xGrp == null) {
            throw new Exception(group + ": group does not exist. policy='" + policy.getName() + "' service='" + policy.getService() + "' group='" + group + "'");
        }
        XXPolicyItemGroupPerm xGrpPerm = new XXPolicyItemGroupPerm();
        xGrpPerm = rangerAuditFields.populateAuditFields(xGrpPerm, xPolicyItem);
        xGrpPerm.setGroupId(xGrp.getId());
        xGrpPerm.setPolicyItemId(xPolicyItem.getId());
        xGrpPerm.setOrder(i);
        xGrpPerm = daoMgr.getXXPolicyItemGroupPerm().create(xGrpPerm);
    }
    List<RangerPolicyItemCondition> conditions = policyItem.getConditions();
    for (RangerPolicyItemCondition condition : conditions) {
        XXPolicyConditionDef xPolCond = daoMgr.getXXPolicyConditionDef().findByServiceDefIdAndName(xServiceDef.getId(), condition.getType());
        if (xPolCond == null) {
            throw new Exception(condition.getType() + ": is not a valid condition-type. policy='" + xPolicy.getName() + "' service='" + xPolicy.getService() + "'");
        }
        for (int i = 0; i < condition.getValues().size(); i++) {
            String value = condition.getValues().get(i);
            XXPolicyItemCondition xPolItemCond = new XXPolicyItemCondition();
            xPolItemCond = rangerAuditFields.populateAuditFields(xPolItemCond, xPolicyItem);
            xPolItemCond.setPolicyItemId(xPolicyItem.getId());
            xPolItemCond.setType(xPolCond.getId());
            xPolItemCond.setValue(value);
            xPolItemCond.setOrder(i);
            daoMgr.getXXPolicyItemCondition().create(xPolItemCond);
        }
    }
    return xPolicyItem;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXPolicyItemGroupPerm(org.apache.ranger.entity.XXPolicyItemGroupPerm) XXPolicyItemUserPerm(org.apache.ranger.entity.XXPolicyItemUserPerm) VXString(org.apache.ranger.view.VXString) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) JSONException(org.codehaus.jettison.json.JSONException) XXPolicyItemCondition(org.apache.ranger.entity.XXPolicyItemCondition) XXPolicyItem(org.apache.ranger.entity.XXPolicyItem) XXPolicyItemAccess(org.apache.ranger.entity.XXPolicyItemAccess) XXGroup(org.apache.ranger.entity.XXGroup) XXPolicyConditionDef(org.apache.ranger.entity.XXPolicyConditionDef) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) RangerPolicyItemAccess(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess) RangerPolicyItemCondition(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemCondition)

Example 7 with XXAccessTypeDef

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

the class RangerBaseModelService method getAccessTypeName.

protected String getAccessTypeName(Long accessTypeDefId) {
    String ret = null;
    XXAccessTypeDef accessTypeDef = accessTypeDefId == null ? null : daoMgr.getXXAccessTypeDef().getById(accessTypeDefId);
    if (accessTypeDef != null) {
        ret = accessTypeDef.getName();
    }
    return ret;
}
Also used : XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef)

Example 8 with XXAccessTypeDef

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

the class TestRangerServiceDefServiceBase method test7populateRangerAccessTypeDefToXX.

@Test
public void test7populateRangerAccessTypeDefToXX() {
    RangerAccessTypeDef rangerAccessTypeDefObj = new RangerAccessTypeDef();
    rangerAccessTypeDefObj.setLabel("Read");
    rangerAccessTypeDefObj.setName("read");
    rangerAccessTypeDefObj.setRbKeyLabel(null);
    XXAccessTypeDef accessTypeDefObj = new XXAccessTypeDef();
    accessTypeDefObj.setAddedByUserId(Id);
    accessTypeDefObj.setCreateTime(new Date());
    accessTypeDefObj.setDefid(Id);
    accessTypeDefObj.setId(Id);
    accessTypeDefObj.setLabel("Read");
    accessTypeDefObj.setName("read");
    accessTypeDefObj.setOrder(null);
    accessTypeDefObj.setRbkeylabel(null);
    accessTypeDefObj.setUpdatedByUserId(Id);
    accessTypeDefObj.setUpdateTime(new Date());
    XXServiceDef serviceDefObj = new XXServiceDef();
    serviceDefObj.setAddedByUserId(Id);
    serviceDefObj.setCreateTime(new Date());
    serviceDefObj.setDescription("HDFS Repository");
    serviceDefObj.setGuid("1427365526516_835_0");
    serviceDefObj.setId(Id);
    Mockito.when((XXAccessTypeDef) rangerAuditFields.populateAuditFields(accessTypeDefObj, serviceDefObj)).thenReturn(accessTypeDefObj);
    XXAccessTypeDef dbAccessTypeDef = rangerServiceDefService.populateRangerAccessTypeDefToXX(rangerAccessTypeDefObj, accessTypeDefObj, serviceDefObj, 1);
    Assert.assertNotNull(dbAccessTypeDef);
    Assert.assertEquals(dbAccessTypeDef, accessTypeDefObj);
    Assert.assertEquals(dbAccessTypeDef.getName(), accessTypeDefObj.getName());
    Assert.assertEquals(dbAccessTypeDef.getLabel(), accessTypeDefObj.getLabel());
    Assert.assertEquals(dbAccessTypeDef.getRbkeylabel(), accessTypeDefObj.getRbkeylabel());
    Assert.assertEquals(dbAccessTypeDef.getDefid(), accessTypeDefObj.getDefid());
    Assert.assertEquals(dbAccessTypeDef.getId(), accessTypeDefObj.getId());
    Assert.assertEquals(dbAccessTypeDef.getCreateTime(), accessTypeDefObj.getCreateTime());
    Assert.assertEquals(dbAccessTypeDef.getOrder(), accessTypeDefObj.getOrder());
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) Date(java.util.Date) Test(org.junit.Test)

Example 9 with XXAccessTypeDef

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

the class PatchForAtlasServiceDefUpdate_J10013 method checkIfHasOlderServiceDef.

/*
	 * This method shall check whether atlas service def resources and access types
	 * are matching with older service def resources and access types or not.
	 * returns true if all resources and access types matches with older service def
	 * resources and access types.
	 */
private boolean checkIfHasOlderServiceDef(XXServiceDef serviceDef) {
    boolean result = true;
    Set<String> atlasResources = new HashSet<>(Arrays.asList("entity", "type", "operation", "taxonomy", "term"));
    XXResourceDefDao resourceDefDao = daoMgr.getXXResourceDef();
    List<XXResourceDef> xxResourceDefs = resourceDefDao.findByServiceDefId(serviceDef.getId());
    for (XXResourceDef xxResourceDef : xxResourceDefs) {
        if (!atlasResources.contains(xxResourceDef.getName())) {
            result = false;
            break;
        }
    }
    if (result) {
        Set<String> atlasAccessTypes = new HashSet<>(Arrays.asList("read", "create", "update", "delete", "all"));
        XXAccessTypeDefDao accessTypeDefDao = daoMgr.getXXAccessTypeDef();
        List<XXAccessTypeDef> xxAccessTypeDefs = accessTypeDefDao.findByServiceDefId(serviceDef.getId());
        for (XXAccessTypeDef xxAccessTypeDef : xxAccessTypeDefs) {
            if (!atlasAccessTypes.contains(xxAccessTypeDef.getName())) {
                result = false;
                break;
            }
        }
    }
    return result;
}
Also used : XXResourceDefDao(org.apache.ranger.db.XXResourceDefDao) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) XXAccessTypeDefDao(org.apache.ranger.db.XXAccessTypeDefDao) XXResourceDef(org.apache.ranger.entity.XXResourceDef) HashSet(java.util.HashSet)

Aggregations

XXAccessTypeDef (org.apache.ranger.entity.XXAccessTypeDef)9 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)5 XXPolicyConditionDef (org.apache.ranger.entity.XXPolicyConditionDef)4 XXResourceDef (org.apache.ranger.entity.XXResourceDef)4 XXAccessTypeDefDao (org.apache.ranger.db.XXAccessTypeDefDao)3 XXAccessTypeDefGrantsDao (org.apache.ranger.db.XXAccessTypeDefGrantsDao)3 XXContextEnricherDefDao (org.apache.ranger.db.XXContextEnricherDefDao)3 XXDataMaskTypeDefDao (org.apache.ranger.db.XXDataMaskTypeDefDao)3 XXEnumDefDao (org.apache.ranger.db.XXEnumDefDao)3 XXPolicyConditionDefDao (org.apache.ranger.db.XXPolicyConditionDefDao)3 XXResourceDefDao (org.apache.ranger.db.XXResourceDefDao)3 XXServiceConfigDefDao (org.apache.ranger.db.XXServiceConfigDefDao)3 XXContextEnricherDef (org.apache.ranger.entity.XXContextEnricherDef)3 XXDataMaskTypeDef (org.apache.ranger.entity.XXDataMaskTypeDef)3 XXEnumDef (org.apache.ranger.entity.XXEnumDef)3 XXEnumElementDef (org.apache.ranger.entity.XXEnumElementDef)3 XXPolicyItemCondition (org.apache.ranger.entity.XXPolicyItemCondition)3 XXServiceConfigDef (org.apache.ranger.entity.XXServiceConfigDef)3 XXServiceDef (org.apache.ranger.entity.XXServiceDef)3 VXString (org.apache.ranger.view.VXString)3