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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations