Search in sources :

Example 41 with RangerService

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

the class TestRangerValidator method test_getService.

@Test
public void test_getService() {
    try {
        // if service store returns null or throws an exception then service is deemed invalid
        when(_store.getServiceByName("return null")).thenReturn(null);
        when(_store.getServiceByName("throw")).thenThrow(new Exception());
        RangerService service = mock(RangerService.class);
        when(_store.getServiceByName("good-service")).thenReturn(service);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Unexpected exception during mocking!");
    }
    Assert.assertNull(_validator.getService("return null"));
    Assert.assertNull(_validator.getService("throw"));
    Assert.assertFalse(_validator.getService("good-service") == null);
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 42 with RangerService

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

the class ServicePredicateUtil method addPredicateForTagSeviceId.

private Predicate addPredicateForTagSeviceId(final String tagServiceId, List<Predicate> predicates) {
    if (StringUtils.isEmpty(tagServiceId)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerService) {
                RangerService service = (RangerService) object;
                if (!StringUtils.isEmpty(service.getTagService())) {
                    RangerService tagService = null;
                    try {
                        tagService = serviceStore.getServiceByName(service.getTagService());
                    } catch (Exception excp) {
                    }
                    ret = tagService != null && tagService.getId() != null && StringUtils.equals(tagServiceId, tagService.getId().toString());
                }
            } else {
                ret = true;
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) Predicate(org.apache.commons.collections.Predicate)

Example 43 with RangerService

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

the class ServicePredicateUtil method addPredicateForServiceType.

private Predicate addPredicateForServiceType(final String serviceType, List<Predicate> predicates) {
    if (StringUtils.isEmpty(serviceType)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerPolicy) {
                RangerPolicy policy = (RangerPolicy) object;
                ret = StringUtils.equals(serviceType, getServiceType(policy.getService()));
            } else if (object instanceof RangerService) {
                RangerService service = (RangerService) object;
                ret = StringUtils.equals(serviceType, service.getType());
            } else if (object instanceof RangerServiceDef) {
                RangerServiceDef serviceDef = (RangerServiceDef) object;
                ret = StringUtils.equals(serviceType, serviceDef.getName());
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerService(org.apache.ranger.plugin.model.RangerService) Predicate(org.apache.commons.collections.Predicate)

Example 44 with RangerService

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

the class ServicePredicateUtil method addPredicateForServiceId.

private Predicate addPredicateForServiceId(final String serviceId, List<Predicate> predicates) {
    if (StringUtils.isEmpty(serviceId)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerPolicy) {
                RangerPolicy policy = (RangerPolicy) object;
                Long svcId = getServiceId(policy.getService());
                if (svcId != null) {
                    ret = StringUtils.equals(serviceId, svcId.toString());
                }
            } else if (object instanceof RangerService) {
                RangerService service = (RangerService) object;
                if (service.getId() != null) {
                    ret = StringUtils.equals(serviceId, service.getId().toString());
                }
            } else {
                ret = true;
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) Predicate(org.apache.commons.collections.Predicate)

Example 45 with RangerService

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

the class ServicePredicateUtil method addPredicateForTagSeviceName.

private Predicate addPredicateForTagSeviceName(final String tagServiceName, List<Predicate> predicates) {
    if (StringUtils.isEmpty(tagServiceName)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerService) {
                RangerService service = (RangerService) object;
                ret = StringUtils.equals(tagServiceName, service.getTagService());
            } else {
                ret = true;
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) Predicate(org.apache.commons.collections.Predicate)

Aggregations

RangerService (org.apache.ranger.plugin.model.RangerService)163 Test (org.junit.Test)85 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)52 ArrayList (java.util.ArrayList)39 WebApplicationException (javax.ws.rs.WebApplicationException)30 XXServiceDef (org.apache.ranger.entity.XXServiceDef)26 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)24 VXString (org.apache.ranger.view.VXString)24 XXService (org.apache.ranger.entity.XXService)23 Path (javax.ws.rs.Path)22 Produces (javax.ws.rs.Produces)21 Date (java.util.Date)20 HashMap (java.util.HashMap)16 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 IOException (java.io.IOException)12 GET (javax.ws.rs.GET)12 XXTrxLog (org.apache.ranger.entity.XXTrxLog)12 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)12