Search in sources :

Example 1 with ListIndexException

use of org.apache.jena.rdf.model.ListIndexException in project jena by apache.

the class SecuredRDFListImpl method getHead.

/**
 * @sec.graph Read - if {@link SecurityEvaluator#isHardReadError()} is true and
 *            the user does not have read access then a
 *            {@link ListIndexException} is thrown. The head may be shifted from
 *            the underlying list by permission constraints.
 * @sec.triple Read for triple containing value.
 * @throws ReadDeniedException
 * @throws EmptyListException
 * @throws AuthenticationRequiredException if user is not authenticated and is
 *                                         required to be.
 */
@Override
public RDFNode getHead() throws ReadDeniedException, AuthenticationRequiredException {
    if (checkSoftRead()) {
        Statement s = holder.getBaseItem().getRequiredProperty(RDF.first);
        checkRead(s);
        return SecuredRDFNodeImpl.getInstance(getModel(), s.getObject());
    }
    throw new ListIndexException();
}
Also used : Statement(org.apache.jena.rdf.model.Statement) ListIndexException(org.apache.jena.rdf.model.ListIndexException)

Example 2 with ListIndexException

use of org.apache.jena.rdf.model.ListIndexException in project jena by apache.

the class SecuredRDFListImpl method getTail.

/**
 * @sec.graph Read - if {@link SecurityEvaluator#isHardReadError()} is true and
 *            the user does not have read access then a
 *            {@link ListIndexException} is thrown. The tail may be shifted from
 *            the underlying list by permission constraints.
 * @sec.triple Read for triple containing value.
 * @throws ReadDeniedException
 * @throws EmptyListException
 * @throws ListIndexException
 * @throws InvalidListException
 * @throws AuthenticationRequiredException if user is not authenticated and is
 *                                         required to be.
 */
@Override
public SecuredRDFList getTail() throws ReadDeniedException, AuthenticationRequiredException {
    if (checkSoftRead()) {
        Statement s = holder.getBaseItem().getRequiredProperty(RDF.rest);
        checkRead(s);
        return SecuredRDFListImpl.getInstance(getModel(), s.getObject().as(RDFList.class));
    }
    throw new ListIndexException();
}
Also used : SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) RDFList(org.apache.jena.rdf.model.RDFList) Statement(org.apache.jena.rdf.model.Statement) ListIndexException(org.apache.jena.rdf.model.ListIndexException)

Example 3 with ListIndexException

use of org.apache.jena.rdf.model.ListIndexException in project jena by apache.

the class SecuredRDFListTest method testGetTail.

@Test
public void testGetTail() {
    try {
        RDFList actual = getSecuredRDFList().getTail();
        if (!shouldRead()) {
            fail("Should have thrown ReadDeniedException");
        }
        if (!securityEvaluator.evaluate(Action.Read)) {
            fail("Should have thrown ListIndexException");
        }
        Iterator<RDFNode> actualI = actual.asJavaList().iterator();
        Iterator<RDFNode> expectedI = getBaseRDFNode().as(RDFList.class).getTail().asJavaList().iterator();
        while (expectedI.hasNext()) {
            assertEquals(expectedI.next(), actualI.next());
        }
        assertFalse(actualI.hasNext());
    } catch (final ReadDeniedException e) {
        if (shouldRead()) {
            fail("Should not have thrown ReadDeniedException");
        }
    } catch (final ListIndexException e) {
        if (((RDFList) getBaseRDFNode()).size() > 0 && securityEvaluator.evaluate(Action.Read)) {
            fail("Should not have thrown ListIndexException");
        }
    }
}
Also used : RDFList(org.apache.jena.rdf.model.RDFList) ReadDeniedException(org.apache.jena.shared.ReadDeniedException) ListIndexException(org.apache.jena.rdf.model.ListIndexException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Example 4 with ListIndexException

use of org.apache.jena.rdf.model.ListIndexException in project jena by apache.

the class SecuredRDFListTest method testGet.

@Test
public void testGet() {
    try {
        RDFNode actual = getSecuredRDFList().get(0);
        if (!securityEvaluator.evaluate(Action.Read)) {
            if (securityEvaluator.isHardReadError()) {
                fail("Should have thrown ReadDeniedException");
            } else {
                fail("Should have thrown ListIndexException");
            }
        }
        assertEquals(resource1, actual);
        assertEquals(securedModel, actual.getModel());
    } catch (final ReadDeniedException e) {
        if (shouldRead()) {
            fail(String.format("Should not have thrown ReadDeniedException: %s - %s", e, e.getTriple()));
        }
    } catch (final ListIndexException e) {
        boolean expected = !securityEvaluator.isHardReadError();
        if (!expected) {
            fail("Should not have thrown ListIndexException");
        }
    }
}
Also used : ReadDeniedException(org.apache.jena.shared.ReadDeniedException) ListIndexException(org.apache.jena.rdf.model.ListIndexException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Example 5 with ListIndexException

use of org.apache.jena.rdf.model.ListIndexException in project jena by apache.

the class SecuredRDFListTest method testReplace.

@Test
public void testReplace() {
    try {
        RDFNode result = getSecuredRDFList().replace(1, newResource1);
        if (!shouldRead() || !securityEvaluator.evaluate(Action.Update)) {
            fail("Should have thrown AccessDeniedException");
        }
        assertEquals(resource2, result);
        List<RDFNode> lst = ((RDFList) getBaseRDFNode()).asJavaList();
        Iterator<RDFNode> iter = lst.iterator();
        assertEquals(resource1, iter.next());
        assertEquals(newResource1, iter.next());
        assertEquals(resource3, iter.next());
        assertEquals(resource4, iter.next());
        assertFalse(iter.hasNext());
    } catch (final AccessDeniedException e) {
        if (shouldRead() && securityEvaluator.evaluate(Action.Update) && securityEvaluator.evaluate(Action.Delete)) {
            fail("Should not have thrown AccessDeniedException");
        }
    } catch (final ListIndexException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            fail("Should not have thrown ListIndexException");
        }
    }
}
Also used : AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFList(org.apache.jena.rdf.model.RDFList) ListIndexException(org.apache.jena.rdf.model.ListIndexException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Aggregations

ListIndexException (org.apache.jena.rdf.model.ListIndexException)6 RDFList (org.apache.jena.rdf.model.RDFList)4 RDFNode (org.apache.jena.rdf.model.RDFNode)4 Test (org.junit.Test)3 SecuredRDFList (org.apache.jena.permissions.model.SecuredRDFList)2 Statement (org.apache.jena.rdf.model.Statement)2 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)2 Triple (org.apache.jena.graph.Triple)1 SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)1 AccessDeniedException (org.apache.jena.shared.AccessDeniedException)1