Search in sources :

Example 1 with SecuredRDFNode

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()));
        }
    }
}
Also used : ReadDeniedException(org.apache.jena.shared.ReadDeniedException) SecuredModel(org.apache.jena.permissions.model.SecuredModel) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode) SecuredModel(org.apache.jena.permissions.model.SecuredModel) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode) Test(org.junit.Test)

Example 2 with SecuredRDFNode

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();
    }
}
Also used : Triple(org.apache.jena.graph.Triple) SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode)

Aggregations

SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)2 Triple (org.apache.jena.graph.Triple)1 SecuredModel (org.apache.jena.permissions.model.SecuredModel)1 SecuredRDFList (org.apache.jena.permissions.model.SecuredRDFList)1 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)1 Test (org.junit.Test)1