Search in sources :

Example 6 with ReadDeniedException

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

the class OpRewriterTest method testBGPNoReadAccess.

@Test
public void testBGPNoReadAccess() {
    SecurityEvaluator securityEvaluator = new MockSecurityEvaluator(true, true, false, true, true, true);
    rewriter = new OpRewriter(securityEvaluator, "http://example.com/dummy");
    Triple[] triples = { new Triple(NodeFactory.createVariable("foo"), RDF.type.asNode(), NodeFactory.createURI("http://example.com/class")), new Triple(NodeFactory.createVariable("foo"), NodeFactory.createBlankNode(), NodeFactory.createVariable("bar")), new Triple(NodeFactory.createVariable("bar"), NodeFactory.createBlankNode(), NodeFactory.createVariable("baz")) };
    try {
        rewriter.visit(new OpBGP(BasicPattern.wrap(Arrays.asList(triples))));
        Assert.fail("Should have thrown AccessDeniedException");
    } catch (ReadDeniedException e) {
    // expected
    }
}
Also used : Triple(org.apache.jena.graph.Triple) ReadDeniedException(org.apache.jena.shared.ReadDeniedException) MockSecurityEvaluator(org.apache.jena.permissions.MockSecurityEvaluator) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) SecurityEvaluator(org.apache.jena.permissions.SecurityEvaluator) MockSecurityEvaluator(org.apache.jena.permissions.MockSecurityEvaluator) OpRewriter(org.apache.jena.permissions.query.rewriter.OpRewriter) Test(org.junit.Test)

Example 7 with ReadDeniedException

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

the class SecuredResourceTest method testListProperties.

@Test
public void testListProperties() {
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties();
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        assertTrue(iter.hasNext());
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p);
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if (hasP()) {
            assertTrue(iter.hasNext());
        } else {
            assertFalse(iter.hasNext());
        }
    } 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) SecuredStatementIterator(org.apache.jena.permissions.model.impl.SecuredStatementIterator) Test(org.junit.Test)

Example 8 with ReadDeniedException

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

the class SecuredResourceTest method testListPropertiesWithLang.

@Test
public void testListPropertiesWithLang() {
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p2, "");
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if (hasP2()) {
            assertTrue(iter.hasNext());
            Statement stmt = iter.next();
            assertEquals("yeehaw", stmt.getObject().asLiteral().getString());
        }
        assertFalse(iter.hasNext());
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p2, "us");
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if (hasP2()) {
            assertTrue(iter.hasNext());
            Statement stmt = iter.next();
            assertEquals("yeehaw yall", stmt.getObject().asLiteral().getString());
        }
        assertFalse(iter.hasNext());
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p2, "uk");
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if (hasP2()) {
            assertTrue(iter.hasNext());
            Statement stmt = iter.next();
            assertEquals("whohoo", stmt.getObject().asLiteral().getString());
        }
        assertFalse(iter.hasNext());
    } 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 : Statement(org.apache.jena.rdf.model.Statement) ReadDeniedException(org.apache.jena.shared.ReadDeniedException) SecuredStatementIterator(org.apache.jena.permissions.model.impl.SecuredStatementIterator) Test(org.junit.Test)

Example 9 with ReadDeniedException

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

the class SecuredSeqTest method testGetBag.

@Test
public void testGetBag() {
    try {
        final Bag a = getSecuredSeq().getBag(1);
        Assert.assertTrue("Should be a secured Bag", a instanceof SecuredBag);
        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) SecuredBag(org.apache.jena.permissions.model.SecuredBag) Bag(org.apache.jena.rdf.model.Bag) SecuredBag(org.apache.jena.permissions.model.SecuredBag) Test(org.junit.Test)

Example 10 with ReadDeniedException

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

the class SecuredSeqTest method testGetAlt.

@Test
public void testGetAlt() {
    try {
        final Alt a = getSecuredSeq().getAlt(1);
        Assert.assertTrue("Should be a secured Alt", a instanceof SecuredAlt);
        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) SecuredAlt(org.apache.jena.permissions.model.SecuredAlt) Alt(org.apache.jena.rdf.model.Alt) SecuredAlt(org.apache.jena.permissions.model.SecuredAlt) 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