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;
}
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;
}
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());
}
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;
}
Aggregations