Search in sources :

Example 1 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class TestAssetREST method testGrantPermissionWebApplicationException.

@Test
public void testGrantPermissionWebApplicationException() {
    RangerPolicy policy = rangerPolicy(Id);
    RangerService service = rangerService(Id);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    GrantRevokeRequest grantRequestObj = new GrantRevokeRequest();
    grantRequestObj.setAccessTypes(null);
    grantRequestObj.setDelegateAdmin(true);
    grantRequestObj.setEnableAudit(true);
    grantRequestObj.setGrantor("read");
    grantRequestObj.setIsRecursive(true);
    WebApplicationException webApplicationException = new WebApplicationException();
    Mockito.when(serviceUtil.toGrantRevokeRequest(vXPolicy)).thenReturn(grantRequestObj);
    try {
        Mockito.when(serviceREST.grantAccess(vXPolicy.getRepositoryName(), grantRequestObj, request)).thenThrow(webApplicationException);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
    try {
        assetREST.grantPermission(request, vXPolicy);
        fail("Exception not thrown");
    } catch (WebApplicationException e) {
        Assert.assertTrue(true);
    }
    Mockito.verify(serviceUtil).toGrantRevokeRequest(vXPolicy);
    try {
        Mockito.verify(serviceREST).grantAccess(vXPolicy.getRepositoryName(), grantRequestObj, request);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) VXPolicy(org.apache.ranger.view.VXPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) GrantRevokeRequest(org.apache.ranger.plugin.util.GrantRevokeRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 2 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class TestAssetREST method testRevokePermissionWebApplicationException.

@Test
public void testRevokePermissionWebApplicationException() {
    RangerPolicy policy = rangerPolicy(Id);
    RangerService service = rangerService(Id);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    GrantRevokeRequest grantRequestObj = new GrantRevokeRequest();
    grantRequestObj.setAccessTypes(null);
    grantRequestObj.setDelegateAdmin(true);
    grantRequestObj.setEnableAudit(true);
    grantRequestObj.setGrantor("read");
    grantRequestObj.setIsRecursive(true);
    WebApplicationException webApplicationException = new WebApplicationException();
    Mockito.when(serviceUtil.toGrantRevokeRequest(vXPolicy)).thenReturn(grantRequestObj);
    try {
        Mockito.when(serviceREST.revokeAccess(vXPolicy.getRepositoryName(), grantRequestObj, request)).thenThrow(webApplicationException);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
    try {
        assetREST.revokePermission(request, vXPolicy);
        fail("Exception not thrown");
    } catch (WebApplicationException e) {
        Assert.assertTrue(true);
    }
    Mockito.verify(serviceUtil).toGrantRevokeRequest(vXPolicy);
    try {
        Mockito.verify(serviceREST).revokeAccess(vXPolicy.getRepositoryName(), grantRequestObj, request);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) VXPolicy(org.apache.ranger.view.VXPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) GrantRevokeRequest(org.apache.ranger.plugin.util.GrantRevokeRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 3 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class TestPublicAPIs method vXPolicy.

private VXPolicy vXPolicy(RangerPolicy policy, RangerService service) {
    VXPolicy ret = new VXPolicy();
    ret.setPolicyName(StringUtils.trim(policy.getName()));
    ret.setDescription(policy.getDescription());
    ret.setRepositoryName(policy.getService());
    ret.setIsEnabled(policy.getIsEnabled() ? true : false);
    ret.setRepositoryType(service.getType());
    ret.setIsAuditEnabled(policy.getIsAuditEnabled());
    return ret;
}
Also used : VXPolicy(org.apache.ranger.view.VXPolicy)

Example 4 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class TestPublicAPIs method test12countPolicies.

@Test
public void test12countPolicies() throws Exception {
    VXLong vXLong = new VXLong();
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerService service = rangerService();
    RangerPolicy policy = rangerPolicy();
    List<RangerPolicy> policyList = new ArrayList<RangerPolicy>();
    policyList.add(policy);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    List<VXPolicy> vXPolicies = new ArrayList<VXPolicy>();
    vXPolicies.add(vXPolicy);
    VXPolicyList vXPolicyList = new VXPolicyList(vXPolicies);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    filter.setStartIndex(0);
    filter.setMaxRows(10);
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields)).thenReturn(filter);
    Mockito.when(serviceREST.getPolicies(filter)).thenReturn(policyList);
    Mockito.when(serviceUtil.rangerPolicyListToPublic(policyList, filter)).thenReturn(vXPolicyList);
    VXPolicyList dbVXPolicyList = publicAPIs.searchPolicies(request);
    vXLong.setValue(dbVXPolicyList.getResultSize());
    Assert.assertNotNull(vXLong);
    Assert.assertEquals(vXLong.getValue(), 1);
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, policyService.sortFields);
    Mockito.verify(serviceREST).getPolicies(filter);
    Mockito.verify(serviceUtil).rangerPolicyListToPublic(policyList, filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXLong(org.apache.ranger.view.VXLong) VXPolicyList(org.apache.ranger.view.VXPolicyList) ArrayList(java.util.ArrayList) VXPolicy(org.apache.ranger.view.VXPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 5 with VXPolicy

use of org.apache.ranger.view.VXPolicy in project ranger by apache.

the class XPolicyService method mapToVXPolicyList.

public VXPolicyList mapToVXPolicyList(VXResourceList vXResourceList) {
    List<VXPolicy> policyList = new ArrayList<VXPolicy>();
    for (VXResource vXAsset : vXResourceList.getVXResources()) {
        VXPolicy vXRepo = mapXAToPublicObject(vXAsset);
        policyList.add(vXRepo);
    }
    VXPolicyList vXPolicyList = new VXPolicyList(policyList);
    return vXPolicyList;
}
Also used : VXPolicyList(org.apache.ranger.view.VXPolicyList) VXPolicy(org.apache.ranger.view.VXPolicy) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource)

Aggregations

VXPolicy (org.apache.ranger.view.VXPolicy)16 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)11 RangerService (org.apache.ranger.plugin.model.RangerService)10 Test (org.junit.Test)9 WebApplicationException (javax.ws.rs.WebApplicationException)5 ArrayList (java.util.ArrayList)4 GrantRevokeRequest (org.apache.ranger.plugin.util.GrantRevokeRequest)4 VXPolicyList (org.apache.ranger.view.VXPolicyList)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 RESTResponse (org.apache.ranger.admin.client.datatype.RESTResponse)2 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)2 VXPermObj (org.apache.ranger.view.VXPermObj)2 VXResource (org.apache.ranger.view.VXResource)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InvalidNameException (javax.naming.InvalidNameException)1 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)1 XXPolicy (org.apache.ranger.entity.XXPolicy)1 RangerServiceNotFoundException (org.apache.ranger.plugin.util.RangerServiceNotFoundException)1 VXAuditMap (org.apache.ranger.view.VXAuditMap)1