Java Code Examples for org.apache.ranger.plugin.util.ServicePolicies#setServiceName()
The following examples show how to use
org.apache.ranger.plugin.util.ServicePolicies#setServiceName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestServiceREST.java From ranger with Apache License 2.0 | 5 votes |
public ServicePolicies servicePolicies() { ServicePolicies sp = new ServicePolicies(); sp.setAuditMode("auditMode"); RangerPolicy rangerPolicy = rangerPolicy(); List<RangerPolicy> rpolList = new ArrayList<RangerPolicy>(); rpolList.add(rangerPolicy); sp.setPolicies(rpolList); sp.setPolicyVersion(1l); sp.setServiceName("serviceName"); sp.setServiceId(1l); return sp; }
Example 2
Source File: TestServiceREST.java From ranger with Apache License 2.0 | 5 votes |
@Test public void test28getPoliciesWithServiceAdmin() throws Exception { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); SearchFilter filter = new SearchFilter(); XXService xs = Mockito.mock(XXService.class); xs.setType(3L); XXGroupUserDao xGroupDao = Mockito.mock(XXGroupUserDao.class); ServiceREST spySVCRest = Mockito.spy(serviceREST); List<RangerPolicy> policies = new ArrayList<RangerPolicy>(); ServicePolicies svcPolicies = new ServicePolicies(); svcPolicies.setPolicies(policies); svcPolicies.setServiceName("HDFS_1-1-20150316062453"); RangerPolicy rPol=rangerPolicy(); policies.add(rPol); filter.setParam(SearchFilter.POLICY_NAME, "policyName"); filter.setParam(SearchFilter.SERVICE_NAME, "serviceName"); Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter); Mockito.when(svcStore.getPolicies(filter)).thenReturn(policies); /*here we are setting serviceAdminRole, so we will get the required policy with serviceAdmi role*/ Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupDao); Mockito.when(svcStore.isServiceAdminUser(rPol.getService(), null)).thenReturn(true); Mockito.doReturn(policyAdmin).when(spySVCRest).getPolicyAdminForDelegatedAdmin("HDFS_1-1-20150316062453"); RangerPolicyList dbRangerPolicy = spySVCRest.getPolicies(request); Assert.assertNotNull(dbRangerPolicy); Assert.assertEquals(dbRangerPolicy.getListSize(), 1); Mockito.verify(searchUtil).getSearchFilter(request, policyService.sortFields); Mockito.verify(svcStore).getPolicies(filter); Mockito.verify(svcStore).isServiceAdminUser(rPol.getService(), null); }
Example 3
Source File: TestServiceREST.java From ranger with Apache License 2.0 | 4 votes |
@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(); }