use of org.apache.jena.rdf.model.RDFList in project jena by apache.
the class SecuredRDFListImpl method remove.
/**
* @sec.graph Update
* @sec.triple Delete for triple containing value.
* @throws UpdateDeniedException
* @throws DeleteDeniedException
* @throws EmptyListException
* @throws ListIndexException
* @throws InvalidListException
* @throws AuthenticationRequiredException if user is not authenticated and is
* required to be.
*/
@Override
public RDFList remove(final RDFNode val) throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
checkUpdate();
if (!canDelete(new Triple(Node.ANY, RDF.first.asNode(), val.asNode()))) {
RDFList cell = null;
final ExtendedIterator<RDFList> iter = getFilteredRDFListIterator(Action.Delete);
while (iter.hasNext()) {
cell = iter.next();
if (val.equals(valueMapper.apply(cell))) {
return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell));
}
}
throw new DeleteDeniedException(SecuredItem.Util.triplePermissionMsg(getModelNode()));
}
return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem().remove(val));
}
use of org.apache.jena.rdf.model.RDFList in project jena by apache.
the class SecuredRDFListImpl method getInstance.
/**
* Get an instance of SecuredProperty
*
* @param securedModel the Secured Model to use.
* @param rdfList The rdfList to secure
* @return The SecuredProperty
*/
public static <T extends RDFList> SecuredRDFList getInstance(final SecuredModel securedModel, final T rdfList) {
if (securedModel == null) {
throw new IllegalArgumentException("Secured securedModel may not be null");
}
if (rdfList == null) {
throw new IllegalArgumentException("RDFList may not be null");
}
// check that property has a securedModel.
RDFList goodList = rdfList;
if (goodList.getModel() == null) {
goodList = securedModel.createList(rdfList.asJavaList().iterator());
}
final ItemHolder<RDFList, SecuredRDFList> holder = new ItemHolder<>(goodList);
final SecuredRDFListImpl checker = new SecuredRDFListImpl(securedModel, holder);
// one.
if (goodList instanceof SecuredRDFList) {
if (checker.isEquivalent((SecuredRDFList) goodList)) {
return (SecuredRDFList) goodList;
}
}
return holder.setSecuredItem(new SecuredItemInvoker(rdfList.getClass(), checker));
}
use of org.apache.jena.rdf.model.RDFList in project jena by apache.
the class SecuredRDFListImpl method removeHead.
/**
* @sec.graph Update
* @sec.triple Delete for the head triple.
* @throws UpdateDeniedException
* @throws DeleteDeniedException
* @throws EmptyListException
* @throws ListIndexException
* @throws InvalidListException
* @throws AuthenticationRequiredException if user is not authenticated and is
* required to be.
*/
@Override
public SecuredRDFList removeHead() throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
checkUpdate();
final ExtendedIterator<RDFList> iter = getFilteredRDFListIterator(Action.Read);
try {
if (!iter.hasNext()) {
throw new EmptyListException("Attempted to delete the head of a nil list");
}
final RDFList cell = iter.next();
final Statement s = cell.getRequiredProperty(RDF.first);
checkDelete(s);
return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell));
} finally {
iter.close();
}
}
use of org.apache.jena.rdf.model.RDFList in project jena by apache.
the class AssemblerSecurityRegistry method parseStruct.
/**
* Format:: access:entry [ :user "user2"; :graphs (<http://host/graphname3> ) ]
*/
private void parseStruct(Multimap<String, Node> map, Resource root, Resource r) {
if (!GraphUtils.exactlyOneProperty(r, VocabSecurity.pUser))
throw new AssemblerException(root, "Expected exactly one access:user property for " + r);
if (!GraphUtils.exactlyOneProperty(r, VocabSecurity.pGraphs))
throw new AssemblerException(root, "Expected exactly one access:graphs property for " + r);
String user = GraphUtils.getStringValue(r, VocabSecurity.pUser);
r.listProperties(VocabSecurity.pGraphs).mapWith(s -> s.getObject()).forEachRemaining(x -> {
List<Node> graphs = new ArrayList<>();
if (x.isURIResource()) {
// System.out.printf("S: user %s : access : %s\n", user, x.asNode());
graphs.add(x.asNode());
} else {
// List?
RDFList list = x.as(RDFList.class);
list.iterator().forEachRemaining(rn -> {
graphs.add(rn.asNode());
});
}
accessEntries(root, map, user, graphs);
});
}
use of org.apache.jena.rdf.model.RDFList 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");
}
}
}
Aggregations