Search in sources :

Example 21 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.

the class TestPublicAPIsv2 method test25deletePolicyByName.

@Test
public void test25deletePolicyByName() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerPolicy rangerPolicy = rangerPolicy();
    String policyName = rangerPolicy.getName();
    RangerService rangerService = rangerService();
    String serviceName = rangerService.getName();
    List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
    policies.add(rangerPolicy);
    Mockito.when(serviceREST.getPolicies((SearchFilter) Mockito.any())).thenReturn(policies);
    Mockito.doNothing().when(serviceREST).deletePolicy(Id);
    publicAPIsv2.deletePolicyByName(serviceName, policyName, request);
    Mockito.verify(serviceREST).getPolicies((SearchFilter) Mockito.any());
    Mockito.verify(serviceREST).deletePolicy(Id);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 22 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.

the class TestServiceREST method test43revoke.

@Test
public void test43revoke() {
    RangerPolicy existingPolicy = rangerPolicy();
    List<RangerPolicyItem> policyItem = new ArrayList<RangerPolicyItem>();
    existingPolicy.setPolicyItems(policyItem);
    Map<String, RangerPolicyResource> policyResources = new HashMap<String, RangerPolicyResource>();
    RangerPolicyResource rangerPolicyResource = new RangerPolicyResource("/tmp");
    rangerPolicyResource.setIsExcludes(true);
    rangerPolicyResource.setIsRecursive(true);
    policyResources.put("path", rangerPolicyResource);
    existingPolicy.setResources(policyResources);
    RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("read", true));
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("write", true));
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("delete", true));
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("lock", true));
    rangerPolicyItem.getGroups().add("group1");
    rangerPolicyItem.getGroups().add("group2");
    rangerPolicyItem.getUsers().add("user1");
    rangerPolicyItem.getUsers().add("user2");
    rangerPolicyItem.setDelegateAdmin(true);
    existingPolicy.getPolicyItems().add(rangerPolicyItem);
    rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("read", true));
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("write", true));
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("delete", true));
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("lock", true));
    rangerPolicyItem.getGroups().add("group3");
    rangerPolicyItem.getUsers().add("user3");
    rangerPolicyItem.setDelegateAdmin(true);
    existingPolicy.getPolicyItems().add(rangerPolicyItem);
    rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("delete", true));
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("lock", true));
    rangerPolicyItem.getGroups().add("group1");
    rangerPolicyItem.getGroups().add("group2");
    rangerPolicyItem.getUsers().add("user1");
    rangerPolicyItem.getUsers().add("user2");
    rangerPolicyItem.setDelegateAdmin(false);
    existingPolicy.getAllowExceptions().add(rangerPolicyItem);
    rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("delete", true));
    rangerPolicyItem.getGroups().add("group2");
    rangerPolicyItem.getUsers().add("user2");
    rangerPolicyItem.setDelegateAdmin(false);
    existingPolicy.getDenyPolicyItems().add(rangerPolicyItem);
    rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("index", true));
    rangerPolicyItem.getGroups().add("public");
    rangerPolicyItem.getUsers().add("user");
    rangerPolicyItem.setDelegateAdmin(false);
    existingPolicy.getDenyPolicyItems().add(rangerPolicyItem);
    GrantRevokeRequest revokeRequestObj = new GrantRevokeRequest();
    Map<String, String> resource = new HashMap<String, String>();
    resource.put("path", "/tmp");
    revokeRequestObj.setResource(resource);
    revokeRequestObj.getUsers().add("user1");
    revokeRequestObj.getGroups().add("group1");
    revokeRequestObj.getAccessTypes().add("delete");
    revokeRequestObj.getAccessTypes().add("index");
    revokeRequestObj.setDelegateAdmin(true);
    revokeRequestObj.setEnableAudit(true);
    revokeRequestObj.setIsRecursive(true);
    revokeRequestObj.setGrantor("test43Revoke");
    String existingPolicyStr = existingPolicy.toString();
    System.out.println("existingPolicy=" + existingPolicyStr);
    ServiceRESTUtil.processRevokeRequest(existingPolicy, revokeRequestObj);
    String resultPolicyStr = existingPolicy.toString();
    System.out.println("resultPolicy=" + resultPolicyStr);
    assert (true);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) HashMap(java.util.HashMap) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) ArrayList(java.util.ArrayList) RangerPolicyItemAccess(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess) VXString(org.apache.ranger.view.VXString) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) GrantRevokeRequest(org.apache.ranger.plugin.util.GrantRevokeRequest) Test(org.junit.Test)

Example 23 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy 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 24 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.

the class TestServiceREST method test22getServicePoliciesById.

@Test
public void test22getServicePoliciesById() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerPolicy rangerPolicy = rangerPolicy();
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
    RangerPolicyList dbRangerPolicy = serviceREST.getServicePolicies(rangerPolicy.getId(), request);
    Assert.assertNotNull(dbRangerPolicy);
    Mockito.verify(searchUtil).getSearchFilter(request, policyService.sortFields);
    Mockito.verify(svcStore).getServicePolicies(Id, filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) Test(org.junit.Test)

Example 25 with RangerPolicy

use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.

the class TestServiceREST method test40applyPolicy.

@Test
public void test40applyPolicy() {
    RangerPolicy existingPolicy = rangerPolicy();
    RangerPolicy appliedPolicy = rangerPolicy();
    List<RangerPolicyItem> policyItem = new ArrayList<RangerPolicyItem>();
    existingPolicy.setPolicyItems(policyItem);
    appliedPolicy.setPolicyItems(null);
    Map<String, RangerPolicyResource> policyResources = new HashMap<String, RangerPolicyResource>();
    RangerPolicyResource rangerPolicyResource = new RangerPolicyResource("/tmp");
    rangerPolicyResource.setIsExcludes(true);
    rangerPolicyResource.setIsRecursive(true);
    policyResources.put("path", rangerPolicyResource);
    existingPolicy.setResources(policyResources);
    appliedPolicy.setResources(policyResources);
    RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("read", true));
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("write", true));
    rangerPolicyItem.getGroups().add("group1");
    rangerPolicyItem.getGroups().add("group2");
    rangerPolicyItem.getUsers().add("user1");
    rangerPolicyItem.getUsers().add("user2");
    rangerPolicyItem.setDelegateAdmin(true);
    existingPolicy.getPolicyItems().add(rangerPolicyItem);
    rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.getAccesses().add(new RangerPolicyItemAccess("delete", true));
    rangerPolicyItem.getGroups().add("group1");
    rangerPolicyItem.getGroups().add("public");
    rangerPolicyItem.getUsers().add("user1");
    rangerPolicyItem.getUsers().add("finance");
    rangerPolicyItem.setDelegateAdmin(false);
    appliedPolicy.getPolicyItems().add(rangerPolicyItem);
    String existingPolicyStr = existingPolicy.toString();
    System.out.println("existingPolicy=" + existingPolicyStr);
    ServiceRESTUtil.processApplyPolicy(existingPolicy, appliedPolicy);
    String resultPolicyStr = existingPolicy.toString();
    System.out.println("resultPolicy=" + resultPolicyStr);
    assert (true);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) HashMap(java.util.HashMap) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) ArrayList(java.util.ArrayList) RangerPolicyItemAccess(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess) VXString(org.apache.ranger.view.VXString) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) Test(org.junit.Test)

Aggregations

RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)196 ArrayList (java.util.ArrayList)78 Test (org.junit.Test)73 RangerService (org.apache.ranger.plugin.model.RangerService)52 VXString (org.apache.ranger.view.VXString)48 HashMap (java.util.HashMap)38 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)36 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)33 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)30 WebApplicationException (javax.ws.rs.WebApplicationException)29 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)27 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)26 Path (javax.ws.rs.Path)23 Produces (javax.ws.rs.Produces)22 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)20 Date (java.util.Date)19 IOException (java.io.IOException)18 XXService (org.apache.ranger.entity.XXService)18 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)16 RangerPolicyList (org.apache.ranger.view.RangerPolicyList)15