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();
}
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();
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
Aggregations