Search in sources :

Example 21 with RangerAccessTypeDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.

the class ValidationTestUtils method createAccessTypeDefs.

List<RangerAccessTypeDef> createAccessTypeDefs(String[] names) {
    // fail if null is passed in!
    Assert.assertFalse(names == null);
    List<RangerAccessTypeDef> defs = new ArrayList<RangerServiceDef.RangerAccessTypeDef>();
    for (String name : names) {
        RangerAccessTypeDef def = mock(RangerAccessTypeDef.class);
        when(def.getName()).thenReturn(name);
        defs.add(def);
    }
    return defs;
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList)

Example 22 with RangerAccessTypeDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.

the class TestRangerValidator method test_getAccessTypes.

@Test
public void test_getAccessTypes() {
    // passing in null service def
    Set<String> accessTypes = _validator.getAccessTypes((RangerServiceDef) null);
    Assert.assertTrue(accessTypes.isEmpty());
    // that has null or empty access type def
    RangerServiceDef serviceDef = mock(RangerServiceDef.class);
    when(serviceDef.getAccessTypes()).thenReturn(null);
    accessTypes = _validator.getAccessTypes(serviceDef);
    Assert.assertTrue(accessTypes.isEmpty());
    List<RangerAccessTypeDef> accessTypeDefs = new ArrayList<>();
    when(serviceDef.getAccessTypes()).thenReturn(accessTypeDefs);
    accessTypes = _validator.getAccessTypes(serviceDef);
    Assert.assertTrue(accessTypes.isEmpty());
    // having null accesstypedefs
    accessTypeDefs.add(null);
    accessTypes = _validator.getAccessTypes(serviceDef);
    Assert.assertTrue(accessTypes.isEmpty());
    // access type defs with null empty blank names are skipped, spaces within names are preserved
    String[] names = new String[] { null, "", "a", "  ", "b ", "		", " C", "	D	" };
    accessTypeDefs.addAll(_utils.createAccessTypeDefs(names));
    accessTypes = _validator.getAccessTypes(serviceDef);
    Assert.assertEquals(4, accessTypes.size());
    Assert.assertTrue(accessTypes.contains("a"));
    Assert.assertTrue(accessTypes.contains("b "));
    Assert.assertTrue(accessTypes.contains(" C"));
    Assert.assertTrue(accessTypes.contains("	D	"));
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 23 with RangerAccessTypeDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.

the class TestServiceREST method test16createPolicyFalse.

@Test
public void test16createPolicyFalse() throws Exception {
    RangerPolicy rangerPolicy = rangerPolicy();
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
    RangerPolicy rangPolicy = new RangerPolicy();
    policies.add(rangPolicy);
    String userName = "admin";
    Set<String> userGroupsList = new HashSet<String>();
    userGroupsList.add("group1");
    userGroupsList.add("group2");
    ServicePolicies servicePolicies = new ServicePolicies();
    servicePolicies.setServiceId(Id);
    servicePolicies.setServiceName("Hdfs_1");
    servicePolicies.setPolicyVersion(1L);
    servicePolicies.setPolicyUpdateTime(new Date());
    servicePolicies.setServiceDef(rangerServiceDef);
    servicePolicies.setPolicies(policies);
    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);
    Mockito.when(svcStore.createPolicy((RangerPolicy) Mockito.any())).thenReturn(rangPolicy);
    RangerPolicy dbRangerPolicy = serviceREST.createPolicy(rangerPolicy, null);
    Assert.assertNotNull(dbRangerPolicy);
    Mockito.verify(bizUtil, Mockito.times(2)).isAdmin();
    Mockito.verify(validatorFactory).getPolicyValidator(svcStore);
    Mockito.verify(daoManager).getXXService();
    Mockito.verify(daoManager).getXXServiceDef();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXServiceDao(org.apache.ranger.db.XXServiceDao) Date(java.util.Date) RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) XXService(org.apache.ranger.entity.XXService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with RangerAccessTypeDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.

the class TestServiceREST method test18deletePolicyFalse.

@Test
public void test18deletePolicyFalse() throws Exception {
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
    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(svcStore.getPolicy(Id)).thenReturn(rangerPolicy);
    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);
    serviceREST.deletePolicy(rangerPolicy.getId());
    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 25 with RangerAccessTypeDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.

the class TestServiceREST method test19getPolicyFalse.

@Test
public void test19getPolicyFalse() throws Exception {
    RangerPolicy rangerPolicy = rangerPolicy();
    Mockito.when(svcStore.getPolicy(rangerPolicy.getId())).thenReturn(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(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.getPolicy(rangerPolicy.getId());
    Assert.assertNotNull(dbRangerPolicy);
    Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId());
    Mockito.verify(svcStore).getPolicy(rangerPolicy.getId());
}
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)

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