Search in sources :

Example 1 with UpdateDeniedException

use of org.apache.jena.shared.UpdateDeniedException in project jena by apache.

the class SecuredModelImpl method add.

/**
 * @sec.graph Update
 * @sec.triple Create all the statements as triples.
 * @throws UpdateDeniedException
 * @throws AddDeniedException
 * @throws AuthenticationRequiredException if user is not authenticated and is
 *                                         required to be.
 */
@Override
public SecuredModel add(final StmtIterator iter) throws UpdateDeniedException, AddDeniedException, AuthenticationRequiredException {
    checkUpdate();
    StmtIterator updateFrom = iter;
    if (!canCreate(Triple.ANY)) {
        // checkCreate will throw exception on first failure
        List<Statement> stmt = iter.filterKeep(s -> {
            checkCreate(s);
            return true;
        }).toList();
        // now just add the list to the base
        updateFrom = new StmtIteratorImpl(stmt.iterator());
    }
    holder.getBaseItem().add(updateFrom);
    return holder.getSecuredItem();
}
Also used : Arrays(java.util.Arrays) AuthenticationRequiredException(org.apache.jena.shared.AuthenticationRequiredException) Lock(org.apache.jena.shared.Lock) RDF(org.apache.jena.vocabulary.RDF) NodeFactory(org.apache.jena.graph.NodeFactory) URL(java.net.URL) NsIteratorImpl(org.apache.jena.rdf.model.impl.NsIteratorImpl) SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph) RDFNode(org.apache.jena.rdf.model.RDFNode) Model(org.apache.jena.rdf.model.Model) AnonId(org.apache.jena.rdf.model.AnonId) WrappedIterator(org.apache.jena.util.iterator.WrappedIterator) ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) AddDeniedException(org.apache.jena.shared.AddDeniedException) Map(java.util.Map) SecuredAlt(org.apache.jena.permissions.model.SecuredAlt) UpdateDeniedException(org.apache.jena.shared.UpdateDeniedException) ModelChangedListener(org.apache.jena.rdf.model.ModelChangedListener) SecuredItem(org.apache.jena.permissions.SecuredItem) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode) StmtIterator(org.apache.jena.rdf.model.StmtIterator) ResourceF(org.apache.jena.rdf.model.ResourceF) WrappedIOException(org.apache.jena.shared.WrappedIOException) Predicate(java.util.function.Predicate) Triple(org.apache.jena.graph.Triple) RDFWriterI(org.apache.jena.rdf.model.RDFWriterI) Reader(java.io.Reader) NsIterator(org.apache.jena.rdf.model.NsIterator) List(java.util.List) Selector(org.apache.jena.rdf.model.Selector) SecuredBag(org.apache.jena.permissions.model.SecuredBag) CollectionGraph(org.apache.jena.graph.impl.CollectionGraph) Writer(java.io.Writer) DeleteDeniedException(org.apache.jena.shared.DeleteDeniedException) RDFDatatype(org.apache.jena.datatypes.RDFDatatype) SecuredPrefixMapping(org.apache.jena.permissions.graph.SecuredPrefixMapping) ModelFactory(org.apache.jena.rdf.model.ModelFactory) RSIterator(org.apache.jena.rdf.model.RSIterator) SecuredReifiedStatement(org.apache.jena.permissions.model.SecuredReifiedStatement) RDFReaderI(org.apache.jena.rdf.model.RDFReaderI) SecuredRDFList(org.apache.jena.permissions.model.SecuredRDFList) RDFReaderF(org.apache.jena.rdf.model.RDFReaderF) SecuredSeq(org.apache.jena.permissions.model.SecuredSeq) AccessDeniedException(org.apache.jena.shared.AccessDeniedException) HashMap(java.util.HashMap) SecuredItemImpl(org.apache.jena.permissions.impl.SecuredItemImpl) SecuredProperty(org.apache.jena.permissions.model.SecuredProperty) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Statement(org.apache.jena.rdf.model.Statement) Calendar(java.util.Calendar) NiceIterator(org.apache.jena.util.iterator.NiceIterator) Resource(org.apache.jena.rdf.model.Resource) StmtIteratorImpl(org.apache.jena.rdf.model.impl.StmtIteratorImpl) PropertyNotFoundException(org.apache.jena.shared.PropertyNotFoundException) ResourceFactory(org.apache.jena.rdf.model.ResourceFactory) OutputStream(java.io.OutputStream) SecurityEvaluator(org.apache.jena.permissions.SecurityEvaluator) SecuredResource(org.apache.jena.permissions.model.SecuredResource) Iterator(java.util.Iterator) ReadDeniedException(org.apache.jena.shared.ReadDeniedException) IOException(java.io.IOException) SecuredLiteral(org.apache.jena.permissions.model.SecuredLiteral) PrefixMapping(org.apache.jena.shared.PrefixMapping) SecuredModel(org.apache.jena.permissions.model.SecuredModel) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) Node(org.apache.jena.graph.Node) Literal(org.apache.jena.rdf.model.Literal) RDFReaderFImpl(org.apache.jena.rdf.model.impl.RDFReaderFImpl) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement) ItemHolder(org.apache.jena.permissions.impl.ItemHolder) ExtendedIterator(org.apache.jena.util.iterator.ExtendedIterator) Collections(java.util.Collections) Property(org.apache.jena.rdf.model.Property) InputStream(java.io.InputStream) StmtIterator(org.apache.jena.rdf.model.StmtIterator) ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) SecuredReifiedStatement(org.apache.jena.permissions.model.SecuredReifiedStatement) Statement(org.apache.jena.rdf.model.Statement) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement) StmtIteratorImpl(org.apache.jena.rdf.model.impl.StmtIteratorImpl)

Example 2 with UpdateDeniedException

use of org.apache.jena.shared.UpdateDeniedException in project jena by apache.

the class SecuredModelTest method testGetAnyReifiedStmt_none.

@Test
public void testGetAnyReifiedStmt_none() {
    // first with create.
    try {
        Resource r = securedModel.getAnyReifiedStatement(baseModel.listStatements().next());
        Assert.assertNotNull(r);
        if (!securityEvaluator.evaluate(Action.Update)) {
            Assert.fail("Should have thrown UpdateDeniedException Exception");
        }
        if (!securityEvaluator.evaluate(Action.Create)) {
            Assert.fail("Should have thrown AddDeniedException Exception");
        }
    } catch (final UpdateDeniedException e) {
        if (securityEvaluator.evaluate(Action.Update)) {
            Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    } catch (final AddDeniedException e) {
        if (securityEvaluator.evaluate(Action.Create)) {
            Assert.fail(String.format("Should not have thrown AddDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : Resource(org.apache.jena.rdf.model.Resource) UpdateDeniedException(org.apache.jena.shared.UpdateDeniedException) AddDeniedException(org.apache.jena.shared.AddDeniedException) Test(org.junit.Test) SecuredPrefixMappingTest(org.apache.jena.permissions.graph.SecuredPrefixMappingTest)

Example 3 with UpdateDeniedException

use of org.apache.jena.shared.UpdateDeniedException in project jena by apache.

the class SecuredModelTest method testGetAnyReifiedStmt_one.

@Test
public void testGetAnyReifiedStmt_one() {
    final Statement st = baseModel.listStatements().next();
    ReifiedStatement s = baseModel.createReifiedStatement(st);
    try {
        Resource r = securedModel.getAnyReifiedStatement(st);
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.assertEquals(s.getURI(), r.getURI());
        }
        if (!securityEvaluator.evaluate(Action.Update) && !securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown UpdateDeniedException Exception");
        }
        if (!securityEvaluator.evaluate(Action.Create) && !securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown AddDeniedException Exception");
        }
    } catch (final UpdateDeniedException e) {
        if (securityEvaluator.evaluate(Action.Update)) {
            Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    } catch (final AddDeniedException e) {
        if (securityEvaluator.evaluate(Action.Create)) {
            Assert.fail(String.format("Should not have thrown AddDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) UpdateDeniedException(org.apache.jena.shared.UpdateDeniedException) AddDeniedException(org.apache.jena.shared.AddDeniedException) Test(org.junit.Test) SecuredPrefixMappingTest(org.apache.jena.permissions.graph.SecuredPrefixMappingTest)

Example 4 with UpdateDeniedException

use of org.apache.jena.shared.UpdateDeniedException in project jena by apache.

the class SecuredPrefixMappingTest method testWithDefaultMappings.

@Test
public void testWithDefaultMappings() {
    PrefixMapping pm = new PrefixMappingImpl();
    pm.setNsPrefix("example", "http://example.com");
    try {
        // make sure that it must update
        securedMapping.withDefaultMappings(pm);
        if (!securityEvaluator.evaluate(principal, Action.Update, securedMapping.getModelNode())) {
            Assert.fail("Should have thrown UpdateDeniedException");
        }
    } catch (final UpdateDeniedException e) {
        if (securityEvaluator.evaluate(principal, Action.Update, securedMapping.getModelNode())) {
            Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : PrefixMapping(org.apache.jena.shared.PrefixMapping) UpdateDeniedException(org.apache.jena.shared.UpdateDeniedException) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl) Test(org.junit.Test)

Aggregations

UpdateDeniedException (org.apache.jena.shared.UpdateDeniedException)3 Test (org.junit.Test)3 SecuredPrefixMappingTest (org.apache.jena.permissions.graph.SecuredPrefixMappingTest)2 Resource (org.apache.jena.rdf.model.Resource)2 AddDeniedException (org.apache.jena.shared.AddDeniedException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Predicate (java.util.function.Predicate)1