use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.
the class RangerServiceDefServiceBase method populateXXToRangerAccessTypeDef.
public RangerAccessTypeDef populateXXToRangerAccessTypeDef(XXAccessTypeDef xObj) {
RangerAccessTypeDef vObj = new RangerAccessTypeDef();
vObj.setItemId(xObj.getItemId());
vObj.setName(xObj.getName());
vObj.setLabel(xObj.getLabel());
vObj.setRbKeyLabel(xObj.getRbkeylabel());
List<String> impliedGrants = daoMgr.getXXAccessTypeDefGrants().findImpliedGrantsByATDId(xObj.getId());
vObj.setImpliedGrants(impliedGrants);
return vObj;
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.
the class TestRangerValidator method test_getImpliedGrants.
@Test
public void test_getImpliedGrants() {
// passing in null gets back a null
Collection<String> result = _validator.getImpliedGrants(null);
Assert.assertNull(result);
// null or empty implied grant collection gets back an empty collection
RangerAccessTypeDef accessTypeDef = mock(RangerAccessTypeDef.class);
when(accessTypeDef.getImpliedGrants()).thenReturn(null);
result = _validator.getImpliedGrants(accessTypeDef);
Assert.assertTrue(result.isEmpty());
List<String> impliedGrants = new ArrayList<>();
when(accessTypeDef.getImpliedGrants()).thenReturn(impliedGrants);
result = _validator.getImpliedGrants(accessTypeDef);
Assert.assertTrue(result.isEmpty());
// null/empty values come back as is
impliedGrants = Arrays.asList(new String[] { null, "", " ", " " });
when(accessTypeDef.getImpliedGrants()).thenReturn(impliedGrants);
result = _validator.getImpliedGrants(accessTypeDef);
Assert.assertEquals(4, result.size());
// non-empty values get lower cased
impliedGrants = Arrays.asList(new String[] { "a", "B", "C ", " d " });
when(accessTypeDef.getImpliedGrants()).thenReturn(impliedGrants);
result = _validator.getImpliedGrants(accessTypeDef);
Assert.assertEquals(4, result.size());
Assert.assertTrue(result.contains("a"));
Assert.assertTrue(result.contains("b"));
Assert.assertTrue(result.contains("c "));
Assert.assertTrue(result.contains(" d "));
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.
the class ValidationTestUtils method createAccessTypeDefs.
List<RangerAccessTypeDef> createAccessTypeDefs(Object[][] data) {
if (data == null) {
return null;
}
List<RangerAccessTypeDef> result = new ArrayList<>();
if (data.length == 0) {
return result;
}
for (Object[] entry : data) {
Long itemId = (Long) entry[0];
String accessType = (String) entry[1];
String[] impliedAccessArray = (String[]) entry[2];
List<String> impliedAccesses = null;
if (impliedAccessArray != null) {
impliedAccesses = Arrays.asList(impliedAccessArray);
}
RangerAccessTypeDef aTypeDef = mock(RangerAccessTypeDef.class);
when(aTypeDef.getName()).thenReturn(accessType);
when(aTypeDef.getImpliedGrants()).thenReturn(impliedAccesses);
when(aTypeDef.getItemId()).thenReturn(itemId);
result.add(aTypeDef);
}
return result;
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.
the class TestServiceREST method test17updatePolicyFalse.
@Test
public void test17updatePolicyFalse() throws Exception {
RangerPolicy rangerPolicy = rangerPolicy();
String userName = "admin";
Set<String> userGroupsList = new HashSet<String>();
userGroupsList.add("group1");
userGroupsList.add("group2");
List<RangerAccessTypeDef> rangerAccessTypeDefList = new ArrayList<RangerServiceDef.RangerAccessTypeDef>();
RangerAccessTypeDef rangerAccessTypeDefObj = new RangerAccessTypeDef();
rangerAccessTypeDefObj.setLabel("Read");
rangerAccessTypeDefObj.setName("read");
rangerAccessTypeDefObj.setRbKeyLabel(null);
rangerAccessTypeDefList.add(rangerAccessTypeDefObj);
XXServiceDef xServiceDef = serviceDef();
XXService xService = xService();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn(userName);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.findByName(Mockito.anyString())).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
RangerPolicy dbRangerPolicy = serviceREST.updatePolicy(rangerPolicy);
Assert.assertNull(dbRangerPolicy);
Mockito.verify(validatorFactory).getPolicyValidator(svcStore);
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.
the class TestServiceREST method rangerServiceDef.
public RangerServiceDef rangerServiceDef() {
List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>();
List<RangerAccessTypeDef> accessTypes = new ArrayList<RangerAccessTypeDef>();
List<RangerPolicyConditionDef> policyConditions = new ArrayList<RangerPolicyConditionDef>();
List<RangerContextEnricherDef> contextEnrichers = new ArrayList<RangerContextEnricherDef>();
List<RangerEnumDef> enums = new ArrayList<RangerEnumDef>();
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setId(Id);
rangerServiceDef.setImplClass("RangerServiceHdfs");
rangerServiceDef.setLabel("HDFS Repository");
rangerServiceDef.setDescription("HDFS Repository");
rangerServiceDef.setRbKeyDescription(null);
rangerServiceDef.setUpdatedBy("Admin");
rangerServiceDef.setUpdateTime(new Date());
rangerServiceDef.setConfigs(configs);
rangerServiceDef.setResources(resources);
rangerServiceDef.setAccessTypes(accessTypes);
rangerServiceDef.setPolicyConditions(policyConditions);
rangerServiceDef.setContextEnrichers(contextEnrichers);
rangerServiceDef.setEnums(enums);
return rangerServiceDef;
}
Aggregations