Search in sources :

Example 1 with RDFList

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

Example 2 with RDFList

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));
}
Also used : ItemHolder(org.apache.jena.permissions.impl.ItemHolder) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) RDFList(org.apache.jena.rdf.model.RDFList) SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList)

Example 3 with RDFList

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();
    }
}
Also used : SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) RDFList(org.apache.jena.rdf.model.RDFList) Statement(org.apache.jena.rdf.model.Statement) EmptyListException(org.apache.jena.rdf.model.EmptyListException)

Example 4 with RDFList

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);
    });
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Assembler(org.apache.jena.assembler.Assembler) Collection(java.util.Collection) RDFList(org.apache.jena.rdf.model.RDFList) NodeFmtLib(org.apache.jena.riot.out.NodeFmtLib) Set(java.util.Set) Multimap(org.apache.jena.ext.com.google.common.collect.Multimap) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Collectors(java.util.stream.Collectors) Mode(org.apache.jena.assembler.Mode) ArrayList(java.util.ArrayList) RDFNode(org.apache.jena.rdf.model.RDFNode) List(java.util.List) ArrayListMultimap(org.apache.jena.ext.com.google.common.collect.ArrayListMultimap) GraphList(org.apache.jena.sparql.util.graph.GraphList) Util(org.apache.jena.rdf.model.impl.Util) Node(org.apache.jena.graph.Node) Quad(org.apache.jena.sparql.core.Quad) Resource(org.apache.jena.rdf.model.Resource) GraphUtils(org.apache.jena.sparql.util.graph.GraphUtils) Log(org.apache.jena.atlas.logging.Log) GNode(org.apache.jena.sparql.util.graph.GNode) AssemblerBase(org.apache.jena.assembler.assemblers.AssemblerBase) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) RDFList(org.apache.jena.rdf.model.RDFList) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) GNode(org.apache.jena.sparql.util.graph.GNode) ArrayList(java.util.ArrayList)

Example 5 with RDFList

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

Aggregations

RDFList (org.apache.jena.rdf.model.RDFList)13 RDFNode (org.apache.jena.rdf.model.RDFNode)8 SecuredRDFList (org.apache.jena.permissions.model.SecuredRDFList)6 Test (org.junit.Test)5 AccessDeniedException (org.apache.jena.shared.AccessDeniedException)4 Triple (org.apache.jena.graph.Triple)3 EmptyListException (org.apache.jena.rdf.model.EmptyListException)3 ListIndexException (org.apache.jena.rdf.model.ListIndexException)3 SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)2 Statement (org.apache.jena.rdf.model.Statement)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Assembler (org.apache.jena.assembler.Assembler)1 Mode (org.apache.jena.assembler.Mode)1 AssemblerBase (org.apache.jena.assembler.assemblers.AssemblerBase)1 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)1