Search in sources :

Example 1 with RangerAccessTypeDef

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;
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)

Example 2 with RangerAccessTypeDef

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 "));
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with RangerAccessTypeDef

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;
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) ArrayList(java.util.ArrayList)

Example 4 with RangerAccessTypeDef

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);
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with RangerAccessTypeDef

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;
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) ArrayList(java.util.ArrayList) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) RangerPolicyConditionDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef) Date(java.util.Date) RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerContextEnricherDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Aggregations

RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)33 ArrayList (java.util.ArrayList)22 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)17 RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)13 RangerContextEnricherDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef)11 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)11 RangerPolicyConditionDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef)11 RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)11 Date (java.util.Date)10 Test (org.junit.Test)9 XXServiceDef (org.apache.ranger.entity.XXServiceDef)8 VXString (org.apache.ranger.view.VXString)7 HashSet (java.util.HashSet)6 XXAccessTypeDef (org.apache.ranger.entity.XXAccessTypeDef)5 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)5 XXServiceDao (org.apache.ranger.db.XXServiceDao)4 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)4 XXService (org.apache.ranger.entity.XXService)4 RangerDataMaskDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerDataMaskDef)3 RangerDataMaskTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerDataMaskTypeDef)3