Search in sources :

Example 1 with SecuredResource

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));
}
Also used : ItemHolder(org.apache.jena.permissions.impl.ItemHolder) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) Node(org.apache.jena.graph.Node) SecuredResource(org.apache.jena.permissions.model.SecuredResource) SecuredResource(org.apache.jena.permissions.model.SecuredResource)

Example 2 with SecuredResource

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()));
        }
    }
}
Also used : ReadDeniedException(org.apache.jena.shared.ReadDeniedException) SecuredResource(org.apache.jena.permissions.model.SecuredResource) Test(org.junit.Test)

Aggregations

SecuredResource (org.apache.jena.permissions.model.SecuredResource)2 Node (org.apache.jena.graph.Node)1 ItemHolder (org.apache.jena.permissions.impl.ItemHolder)1 SecuredItemInvoker (org.apache.jena.permissions.impl.SecuredItemInvoker)1 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)1 Test (org.junit.Test)1