use of org.apache.jena.permissions.model.SecuredRDFNode 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.SecuredRDFNode in project jena by apache.
the class SecuredRDFListImpl method replace.
@Override
public SecuredRDFNode replace(final int i, final RDFNode value) throws UpdateDeniedException, AuthenticationRequiredException, ListIndexException {
checkUpdate();
final SecuredNodeMap map = new SecuredNodeMap(listFirst());
final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator(Action.Read).mapWith(new SecuredListMap());
int idx = 0;
try {
while (iter.hasNext()) {
if (i == idx) {
final SecuredRDFList list = iter.next();
final SecuredRDFNode retval = map.apply(list);
final Triple t = new Triple(list.asNode(), listFirst().asNode(), retval.asNode());
final Triple t2 = new Triple(list.asNode(), listFirst().asNode(), value.asNode());
checkUpdate(t, t2);
final RDFList base = (RDFList) list.getBaseItem();
base.getRequiredProperty(listFirst()).changeObject(value);
return retval;
} else {
idx++;
iter.next();
}
}
throw new ListIndexException();
} finally {
iter.close();
}
}
Aggregations