Search in sources :

Example 11 with RangerPolicyEngine

use of org.apache.ranger.plugin.policyengine.RangerPolicyEngine in project ranger by apache.

the class TestPolicyEngine method runTests.

private void runTests(InputStreamReader reader, String testName) {
    try {
        PolicyEngineTestCase testCase = gsonBuilder.fromJson(reader, PolicyEngineTestCase.class);
        assertTrue("invalid input: " + testName, testCase != null && testCase.serviceDef != null && testCase.policies != null && testCase.tests != null);
        ServicePolicies servicePolicies = new ServicePolicies();
        servicePolicies.setServiceName(testCase.serviceName);
        servicePolicies.setServiceDef(testCase.serviceDef);
        servicePolicies.setPolicies(testCase.policies);
        RangerPolicyEngineOptions policyEngineOptions = new RangerPolicyEngineOptions();
        RangerPolicyEngine policyEngine = new RangerPolicyEngineImpl(testName, servicePolicies, policyEngineOptions);
        RangerAccessResultProcessor auditHandler = new RangerDefaultAuditHandler();
        for (TestData test : testCase.tests) {
            RangerAccessResult expected = test.result;
            RangerAccessRequest request = test.request;
            policyEngine.preProcess(request);
            RangerAccessResult result = policyEngine.evaluatePolicies(request, RangerPolicy.POLICY_TYPE_ACCESS, auditHandler);
            assertNotNull("result was null! - " + test.name, result);
            assertEquals("isAllowed mismatched! - " + test.name, expected.getIsAllowed(), result.getIsAllowed());
            assertEquals("isAudited mismatched! - " + test.name, expected.getIsAudited(), result.getIsAudited());
            assertEquals("policyId mismatched! - " + test.name, expected.getPolicyId(), result.getPolicyId());
        }
    } catch (Throwable excp) {
        excp.printStackTrace();
    }
}
Also used : RangerPolicyEngineImpl(org.apache.ranger.plugin.policyengine.RangerPolicyEngineImpl) RangerAccessResultProcessor(org.apache.ranger.plugin.policyengine.RangerAccessResultProcessor) ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) TestData(org.apache.ranger.authorization.hbase.TestPolicyEngine.PolicyEngineTestCase.TestData) RangerAccessResult(org.apache.ranger.plugin.policyengine.RangerAccessResult) RangerPolicyEngine(org.apache.ranger.plugin.policyengine.RangerPolicyEngine) RangerDefaultAuditHandler(org.apache.ranger.plugin.audit.RangerDefaultAuditHandler) RangerAccessRequest(org.apache.ranger.plugin.policyengine.RangerAccessRequest) RangerPolicyEngineOptions(org.apache.ranger.plugin.policyengine.RangerPolicyEngineOptions)

Example 12 with RangerPolicyEngine

use of org.apache.ranger.plugin.policyengine.RangerPolicyEngine in project ranger by apache.

the class RangerBasePlugin method setPolicies.

public void setPolicies(ServicePolicies policies) {
    // guard against catastrophic failure during policy engine Initialization or
    try {
        RangerPolicyEngine oldPolicyEngine = this.policyEngine;
        if (policies == null) {
            policies = getDefaultSvcPolicies();
        }
        if (policies == null) {
            this.policyEngine = null;
        } else {
            RangerPolicyEngine policyEngine = new RangerPolicyEngineImpl(appId, policies, policyEngineOptions);
            policyEngine.setUseForwardedIPAddress(useForwardedIPAddress);
            policyEngine.setTrustedProxyAddresses(trustedProxyAddresses);
            this.policyEngine = policyEngine;
        }
        if (oldPolicyEngine != null && !oldPolicyEngine.preCleanup()) {
            LOG.error("preCleanup() failed on the previous policy engine instance !!");
        }
    } catch (Exception e) {
        LOG.error("setPolicies: policy engine initialization failed!  Leaving current policy engine as-is. Exception : ", e);
    }
}
Also used : RangerPolicyEngineImpl(org.apache.ranger.plugin.policyengine.RangerPolicyEngineImpl) RangerPolicyEngine(org.apache.ranger.plugin.policyengine.RangerPolicyEngine)

Aggregations

RangerPolicyEngine (org.apache.ranger.plugin.policyengine.RangerPolicyEngine)12 VXString (org.apache.ranger.view.VXString)6 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)4 XXService (org.apache.ranger.entity.XXService)3 RangerPolicyEngineImpl (org.apache.ranger.plugin.policyengine.RangerPolicyEngineImpl)3 ArrayList (java.util.ArrayList)2 XXServiceDef (org.apache.ranger.entity.XXServiceDef)2 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 Timer (java.util.Timer)1 TreeMap (java.util.TreeMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1