Search in sources :

Example 6 with SecuredModel

use of org.apache.jena.permissions.model.SecuredModel in project jena by apache.

the class QueryEngineTest method testSelectAllType.

@Test
public void testSelectAllType() {
    final SecurityEvaluator eval = new MockSecurityEvaluator(true, true, true, true, true, true) {

        @Override
        public boolean evaluate(Object principal, final Action action, final Node graphIRI, final Triple triple) {
            if (triple.getSubject().isURI() && triple.getSubject().getURI().equals("http://example.com/resource/1")) {
                return false;
            }
            return super.evaluate(principal, action, graphIRI, triple);
        }
    };
    final SecuredModel model = Factory.getInstance(eval, "http://example.com/securedModel", baseModel);
    try {
        String query = "SELECT ?s ?p ?o WHERE " + " { ?s ?p ?o } ";
        try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
            final ResultSet results = qexec.execSelect();
            int count = 0;
            for (; results.hasNext(); ) {
                count++;
                results.nextSolution();
            }
            // 2x 3 values + type triple
            Assert.assertEquals(8, count);
        }
        query = "SELECT ?s ?p ?o WHERE " + " { GRAPH ?g {?s ?p ?o } }";
        try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
            final ResultSet results = qexec.execSelect();
            int count = 0;
            for (; results.hasNext(); ) {
                count++;
                results.nextSolution();
            }
            // 2x 3 values + type triple
            // no named graphs so no results.
            Assert.assertEquals(0, count);
        }
    } finally {
        model.close();
    }
}
Also used : Triple(org.apache.jena.graph.Triple) MockSecurityEvaluator(org.apache.jena.permissions.MockSecurityEvaluator) Node(org.apache.jena.graph.Node) ResultSet(org.apache.jena.query.ResultSet) SecurityEvaluator(org.apache.jena.permissions.SecurityEvaluator) MockSecurityEvaluator(org.apache.jena.permissions.MockSecurityEvaluator) SecuredModel(org.apache.jena.permissions.model.SecuredModel) QueryExecution(org.apache.jena.query.QueryExecution) Test(org.junit.Test)

Example 7 with SecuredModel

use of org.apache.jena.permissions.model.SecuredModel in project jena by apache.

the class SecuredAssemblerTest method testCreationWithArgs.

@Test
public void testCreationWithArgs() throws Exception {
    Resource r = model.createResource("http://apache.org/jena/permissions/test#secModel2");
    Object o = assembler.open(r);
    Assert.assertTrue(o instanceof Model);
    Assert.assertTrue(o instanceof SecuredModel);
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Model(org.apache.jena.rdf.model.Model) SecuredModel(org.apache.jena.permissions.model.SecuredModel) SecuredModel(org.apache.jena.permissions.model.SecuredModel) Test(org.junit.Test)

Aggregations

SecuredModel (org.apache.jena.permissions.model.SecuredModel)7 Test (org.junit.Test)7 MockSecurityEvaluator (org.apache.jena.permissions.MockSecurityEvaluator)3 SecurityEvaluator (org.apache.jena.permissions.SecurityEvaluator)3 QueryExecution (org.apache.jena.query.QueryExecution)3 ResultSet (org.apache.jena.query.ResultSet)3 Node (org.apache.jena.graph.Node)2 Triple (org.apache.jena.graph.Triple)2 Model (org.apache.jena.rdf.model.Model)2 Resource (org.apache.jena.rdf.model.Resource)2 SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)1 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)1