Search in sources :

Example 1 with ReadDeniedException

use of org.apache.jena.shared.ReadDeniedException in project jena by apache.

the class SecuredRDFNodeTest method testInModel.

@Test
public void testInModel() {
    final Model m2 = ModelFactory.createDefaultModel();
    try {
        final RDFNode n2 = securedRDFNode.inModel(m2);
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        Assert.assertFalse("RDFNode should not have been secured", n2 instanceof SecuredRDFNode);
        Assert.assertEquals("Wrong securedModel returned", n2.getModel(), m2);
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    m2.removeAll();
    final SecuredModel m3 = Factory.getInstance(securityEvaluator, "http://example.com/securedGraph2", m2);
    try {
        final RDFNode n2 = securedRDFNode.inModel(m3);
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        Assert.assertTrue("RDFNode should have been secured", n2 instanceof SecuredRDFNode);
        Assert.assertEquals("Wrong securedModel returned", n2.getModel(), m3);
    } 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) SecuredModel(org.apache.jena.permissions.model.SecuredModel) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode) SecuredModel(org.apache.jena.permissions.model.SecuredModel) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode) Test(org.junit.Test)

Example 2 with ReadDeniedException

use of org.apache.jena.shared.ReadDeniedException 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)

Example 3 with ReadDeniedException

use of org.apache.jena.shared.ReadDeniedException in project jena by apache.

the class OpRewriter method visit.

@Override
public void visit(final OpBGP opBGP) throws ReadDeniedException, AuthenticationRequiredException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Starting visiting OpBGP");
    }
    Object principal = securityEvaluator.getPrincipal();
    if (!securityEvaluator.evaluate(principal, Action.Read, graphIRI)) {
        if (silentFail) {
            return;
        } else {
            throw new ReadDeniedException(SecuredItem.Util.modelPermissionMsg(graphIRI));
        }
    }
    // if the user can read any triple just add the opBGP
    if (securityEvaluator.evaluate(principal, Action.Read, graphIRI, Triple.ANY)) {
        addOp(opBGP);
    } else {
        // add security filtering to the resulting triples
        final List<Triple> newBGP = new ArrayList<>();
        final List<Node> variables = new ArrayList<>();
        // register all variables
        for (final Triple t : opBGP.getPattern().getList()) {
            newBGP.add(registerBGPTriple(t, variables));
        }
        // create the security function.
        final SecuredFunction secFunc = new SecuredFunction(graphIRI, securityEvaluator, variables, newBGP);
        // create the filter
        Op filter = OpFilter.filter(secFunc, new OpBGP(BasicPattern.wrap(newBGP)));
        // add the filter
        addOp(filter);
    }
}
Also used : Triple(org.apache.jena.graph.Triple) Op(org.apache.jena.sparql.algebra.Op) ReadDeniedException(org.apache.jena.shared.ReadDeniedException) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList)

Example 4 with ReadDeniedException

use of org.apache.jena.shared.ReadDeniedException in project jena by apache.

the class SecuredRDFListTest method testReduce.

@Test
public void testReduce() {
    final ReduceFn fn = new ReduceFn() {

        @Override
        public Object reduce(final RDFNode node, final Object accumulator) {
            return accumulator;
        }
    };
    try {
        getSecuredRDFList().reduce(fn, "Hello");
        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()));
        }
    }
    final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
    try {
        getSecuredRDFList().reduce(perms, fn, "Hello");
        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 : Action(org.apache.jena.permissions.SecurityEvaluator.Action) ReadDeniedException(org.apache.jena.shared.ReadDeniedException) ReduceFn(org.apache.jena.rdf.model.RDFList.ReduceFn) Test(org.junit.Test)

Example 5 with ReadDeniedException

use of org.apache.jena.shared.ReadDeniedException in project jena by apache.

the class SecuredRDFListTest method testApply.

@Test
public void testApply() {
    final ApplyFn fn = new ApplyFn() {

        @Override
        public void apply(final RDFNode node) {
        // do nothing
        }
    };
    try {
        getSecuredRDFList().apply(fn);
        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()));
        }
    }
    final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Read });
    try {
        getSecuredRDFList().apply(perms, fn);
        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 : Action(org.apache.jena.permissions.SecurityEvaluator.Action) ReadDeniedException(org.apache.jena.shared.ReadDeniedException) ApplyFn(org.apache.jena.rdf.model.RDFList.ApplyFn) Test(org.junit.Test)

Aggregations

ReadDeniedException (org.apache.jena.shared.ReadDeniedException)10 Test (org.junit.Test)9 Triple (org.apache.jena.graph.Triple)2 Action (org.apache.jena.permissions.SecurityEvaluator.Action)2 SecuredStatementIterator (org.apache.jena.permissions.model.impl.SecuredStatementIterator)2 ArrayList (java.util.ArrayList)1 Node (org.apache.jena.graph.Node)1 MockSecurityEvaluator (org.apache.jena.permissions.MockSecurityEvaluator)1 SecurityEvaluator (org.apache.jena.permissions.SecurityEvaluator)1 SecuredAlt (org.apache.jena.permissions.model.SecuredAlt)1 SecuredBag (org.apache.jena.permissions.model.SecuredBag)1 SecuredModel (org.apache.jena.permissions.model.SecuredModel)1 SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)1 SecuredResource (org.apache.jena.permissions.model.SecuredResource)1 OpRewriter (org.apache.jena.permissions.query.rewriter.OpRewriter)1 Alt (org.apache.jena.rdf.model.Alt)1 Bag (org.apache.jena.rdf.model.Bag)1 ApplyFn (org.apache.jena.rdf.model.RDFList.ApplyFn)1 ReduceFn (org.apache.jena.rdf.model.RDFList.ReduceFn)1 Statement (org.apache.jena.rdf.model.Statement)1