Search in sources :

Example 1 with OpRewriter

use of org.apache.jena.permissions.query.rewriter.OpRewriter in project jena by apache.

the class OpRewriterTest method testBGP.

@Test
public void testBGP() {
    SecurityEvaluator securityEvaluator = new MockSecurityEvaluator(true, true, true, true, true, true);
    rewriter = new OpRewriter(securityEvaluator, "http://example.com/dummy");
    rewriter.visit(new OpBGP(BasicPattern.wrap(Arrays.asList(triples))));
    Op op = rewriter.getResult();
    Assert.assertTrue("Should have been an OpFilter", op instanceof OpFilter);
    OpFilter filter = (OpFilter) op;
    ExprList eLst = filter.getExprs();
    Assert.assertEquals(1, eLst.size());
    Assert.assertTrue("Should have been a SecuredFunction", eLst.get(0) instanceof SecuredFunction);
    op = filter.getSubOp();
    Assert.assertTrue("Should have been a OpBGP", op instanceof OpBGP);
    BasicPattern basicPattern = ((OpBGP) op).getPattern();
    Assert.assertEquals(3, basicPattern.size());
    Triple t = basicPattern.get(0);
    Assert.assertEquals(NodeFactory.createVariable("foo"), t.getSubject());
    Assert.assertEquals(RDF.type.asNode(), t.getPredicate());
    Assert.assertEquals(NodeFactory.createURI("http://example.com/class"), t.getObject());
    t = basicPattern.get(1);
    Assert.assertEquals(NodeFactory.createVariable("foo"), t.getSubject());
    Assert.assertTrue("Should have been blank", t.getPredicate().isBlank());
    Assert.assertEquals(NodeFactory.createVariable("bar"), t.getObject());
    t = basicPattern.get(2);
    Assert.assertEquals(NodeFactory.createVariable("bar"), t.getSubject());
    Assert.assertTrue("Should have been blank", t.getPredicate().isBlank());
    Assert.assertEquals(NodeFactory.createVariable("baz"), t.getObject());
}
Also used : Triple(org.apache.jena.graph.Triple) Op(org.apache.jena.sparql.algebra.Op) SecuredFunction(org.apache.jena.permissions.query.rewriter.SecuredFunction) ExprList(org.apache.jena.sparql.expr.ExprList) 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) BasicPattern(org.apache.jena.sparql.core.BasicPattern) OpFilter(org.apache.jena.sparql.algebra.op.OpFilter) OpRewriter(org.apache.jena.permissions.query.rewriter.OpRewriter) Test(org.junit.Test)

Example 2 with OpRewriter

use of org.apache.jena.permissions.query.rewriter.OpRewriter 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 3 with OpRewriter

use of org.apache.jena.permissions.query.rewriter.OpRewriter in project jena by apache.

the class SecuredQueryEngine method modifyOp.

@Override
protected Op modifyOp(final Op op) {
    final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
    LOG.debug("Before: {}", op);
    op.visit(rewriter);
    Op result = rewriter.getResult();
    result = result == null ? op : result;
    LOG.debug("After: {}", result);
    result = super.modifyOp(result);
    LOG.debug("After Optimize: {}", result);
    return result;
}
Also used : Op(org.apache.jena.sparql.algebra.Op) OpRewriter(org.apache.jena.permissions.query.rewriter.OpRewriter)

Aggregations

OpRewriter (org.apache.jena.permissions.query.rewriter.OpRewriter)3 Triple (org.apache.jena.graph.Triple)2 MockSecurityEvaluator (org.apache.jena.permissions.MockSecurityEvaluator)2 SecurityEvaluator (org.apache.jena.permissions.SecurityEvaluator)2 Op (org.apache.jena.sparql.algebra.Op)2 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)2 Test (org.junit.Test)2 SecuredFunction (org.apache.jena.permissions.query.rewriter.SecuredFunction)1 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)1 OpFilter (org.apache.jena.sparql.algebra.op.OpFilter)1 BasicPattern (org.apache.jena.sparql.core.BasicPattern)1 ExprList (org.apache.jena.sparql.expr.ExprList)1