use of org.apache.jena.permissions.model.SecuredResource in project jena by apache.
the class SecuredResourceImpl method getInstance.
/**
* Get a SecuredResource.
*
* @param securedModel
* the securedItem that provides the security context.
* @param resource
* The resource to secure.
* @return The SecuredResource
*/
public static SecuredResource getInstance(final SecuredModel securedModel, final Resource resource) {
if (securedModel == null) {
throw new IllegalArgumentException("Secured securedModel may not be null");
}
if (resource == null) {
throw new IllegalArgumentException("Resource may not be null");
}
if (resource.isLiteral()) {
throw new IllegalArgumentException("Resource may not be a literal");
}
// check that resource has a securedModel.
Resource goodResource = resource;
if (goodResource.getModel() == null) {
final Node n = resource.asNode();
if (resource.isAnon()) {
goodResource = securedModel.createResource(new AnonId(n.getBlankNodeId()));
} else {
goodResource = securedModel.createResource(n.getURI());
}
}
final ItemHolder<Resource, SecuredResource> holder = new ItemHolder<>(goodResource);
final SecuredResourceImpl checker = new SecuredResourceImpl(securedModel, holder);
// one.
if (goodResource instanceof SecuredResource) {
if (checker.isEquivalent((SecuredResource) goodResource)) {
return (SecuredResource) goodResource;
}
}
return holder.setSecuredItem(new SecuredItemInvoker(resource.getClass(), checker));
}
use of org.apache.jena.permissions.model.SecuredResource in project jena by apache.
the class SecuredResourceTest method testAnonFuncs.
@Test
public void testAnonFuncs() {
final SecuredResource anonResource = securedModel.createResource();
setSecuredRDFNode(anonResource, null);
try {
getSecuredResource().getId();
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException Exception");
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
}
Aggregations