use of org.apache.jena.permissions.model.SecuredModel in project jena by apache.
the class QueryEngineTest method testOpenQueryType.
@Test
public void testOpenQueryType() {
final SecurityEvaluator eval = new MockSecurityEvaluator(true, true, true, true, true, true);
final SecuredModel model = Factory.getInstance(eval, "http://example.com/securedModel", baseModel);
try {
final String query = "prefix fn: <http://www.w3.org/2005/xpath-functions#> " + " SELECT ?foo ?bar WHERE " + " { ?foo a <http://example.com/class> ; " + "?bar [] ." + " } ";
try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
final ResultSet results = qexec.execSelect();
int count = 0;
for (; results.hasNext(); ) {
count++;
results.nextSolution();
}
Assert.assertEquals(8, count);
}
} finally {
model.close();
}
}
use of org.apache.jena.permissions.model.SecuredModel in project jena by apache.
the class QueryEngineTest method testRestrictedQueryType.
@Test
public void testRestrictedQueryType() {
final SecurityEvaluator eval = new MockSecurityEvaluator(true, true, true, true, true, true) {
@Override
public boolean evaluate(final 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 {
final String query = "prefix fn: <http://www.w3.org/2005/xpath-functions#> " + " SELECT ?foo ?bar WHERE " + " { ?foo a <http://example.com/class> ; " + "?bar [] ." + " } ";
try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
final ResultSet results = qexec.execSelect();
int count = 0;
for (; results.hasNext(); ) {
count++;
results.nextSolution();
}
Assert.assertEquals(4, count);
}
} finally {
model.close();
}
}
use of org.apache.jena.permissions.model.SecuredModel in project jena by apache.
the class SecuredAssemblerTest method testCreation.
@Test
public void testCreation() throws Exception {
Resource r = model.createResource("http://apache.org/jena/permissions/test#secModel");
Object o = assembler.open(r);
Assert.assertTrue(o instanceof Model);
Assert.assertTrue(o instanceof SecuredModel);
}
use of org.apache.jena.permissions.model.SecuredModel 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()));
}
}
}
use of org.apache.jena.permissions.model.SecuredModel in project jena by apache.
the class SecuredRDFNodeTest method testGetModel.
@Test
public void testGetModel() {
final Model m2 = securedRDFNode.getModel();
Assert.assertTrue("Model should have been secured", m2 instanceof SecuredModel);
}
Aggregations