Search in sources :

Example 1 with PropertyNotFoundException

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

the class SecuredResourceImpl method getRequiredProperty.

/**
	 * Get a property value of this resource.
	 * 
	 * <p>
	 * The securedModel associated with the resource instance is searched for
	 * statements whose subject is this resource and whose predicate is p. If
	 * such a statement is found, it is returned. If several such statements are
	 * found, any one may be returned. If no such statements are found, an
	 * exception is thrown.
	 * </p>
	 * 
	 * @param p
	 *            The property sought.
	 * @return some (this, p, ?O) statement if one exists
	 * @throws PropertyNotFoundException
	 *             if no such statement found
	 * @throws ReadDeniedException
	 * @throws AuthenticationRequiredException
	 */
@Override
public SecuredStatement getRequiredProperty(final Property p) throws PropertyNotFoundException, ReadDeniedException, AuthenticationRequiredException {
    checkRead();
    final ExtendedIterator<Statement> iter = holder.getBaseItem().listProperties(p).filterKeep(new PermStatementFilter(Action.Read, this));
    try {
        if (iter.hasNext()) {
            return org.apache.jena.permissions.model.impl.SecuredStatementImpl.getInstance(getModel(), iter.next());
        } else {
            throw new PropertyNotFoundException(p);
        }
    } finally {
        iter.close();
    }
}
Also used : PermStatementFilter(org.apache.jena.permissions.utils.PermStatementFilter) PropertyNotFoundException(org.apache.jena.shared.PropertyNotFoundException) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement)

Example 2 with PropertyNotFoundException

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

the class SecuredStatementImpl method getProperty.

/**
 * @sec.graph Read
 * @sec.triple Read
 * @throws ReadDeniedException
 * @throws AuthenticationRequiredException if user is not authenticated and is
 *                                         required to be.
 */
@Override
public SecuredStatement getProperty(final Property p) throws AuthenticationRequiredException {
    checkRead();
    checkRead(holder.getBaseItem().asTriple());
    final StmtIterator s = holder.getBaseItem().getModel().listStatements(holder.getBaseItem().getObject().asResource(), p, (RDFNode) null);
    final SecuredStatementIterator iter = new SecuredStatementIterator(getModel(), s);
    try {
        if (iter.hasNext()) {
            return SecuredStatementImpl.getInstance(getModel(), iter.next());
        }
        throw new PropertyNotFoundException(p);
    } finally {
        iter.close();
    }
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) PropertyNotFoundException(org.apache.jena.shared.PropertyNotFoundException)

Example 3 with PropertyNotFoundException

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

the class SecuredStatementTest method testGetStatementProperty.

@Test
public void testGetStatementProperty() {
    Resource resource = baseModel.getAnyReifiedStatement(baseStatement);
    resource.addProperty(p, o);
    Statement expected = baseStatement.getStatementProperty(p);
    try {
        Statement actual = securedStatement.getStatementProperty(p);
        if (!securityEvaluator.evaluate(Action.Read)) {
            // securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown PropertyNotFoundException Exception");
        }
        assertEquals(expected, actual);
    } catch (final PropertyNotFoundException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            fail("Should not have thrown PropertyNotFoundException Exception");
        }
    }
}
Also used : PropertyNotFoundException(org.apache.jena.shared.PropertyNotFoundException) Statement(org.apache.jena.rdf.model.Statement) ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test)

Example 4 with PropertyNotFoundException

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

the class SecuredModelTest method _testRequiredPropertyWithLang.

private void _testRequiredPropertyWithLang(Supplier<Statement> supplier, String expected) {
    try {
        Statement stmt = supplier.get();
        assertNotNull(stmt);
        if (securedModel.canRead()) {
            assertEquals(expected, stmt.getObject().asLiteral().getString());
        } else {
            if (securityEvaluator.isHardReadError()) {
                fail("Should have thrown ReadDeniedException Exception");
            }
            fail("Should have thrown PropertyNotFoundException Exception");
        }
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    } catch (PropertyNotFoundException e) {
        if (securityEvaluator.isHardReadError() || securedModel.canRead()) {
            fail("Should not have thrown PropertyNotFoundException");
        }
    }
}
Also used : PropertyNotFoundException(org.apache.jena.shared.PropertyNotFoundException) ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) Statement(org.apache.jena.rdf.model.Statement) ReadDeniedException(org.apache.jena.shared.ReadDeniedException)

Example 5 with PropertyNotFoundException

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

the class SecuredResourceTest method testGetRequiredProperty.

private void testGetRequiredProperty(Supplier<Statement> supplier, RDFNode expected) {
    try {
        Statement actual = supplier.get();
        if (!shouldRead()) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if ((expected == null) || (!securityEvaluator.evaluate(Action.Read) && !securityEvaluator.isHardReadError())) {
            fail("Should have thrown PropertyNotFoundException");
        }
        assertEquals(expected, actual.getObject());
    } catch (final ReadDeniedException e) {
        if (shouldRead()) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    } catch (final PropertyNotFoundException e) {
        if (expected != null && !securityEvaluator.evaluate(Action.Read) && securityEvaluator.isHardReadError()) {
            Assert.fail(String.format("Should not have thrown PropertyNotFound Exception: %s", e));
        }
    }
}
Also used : PropertyNotFoundException(org.apache.jena.shared.PropertyNotFoundException) Statement(org.apache.jena.rdf.model.Statement) ReadDeniedException(org.apache.jena.shared.ReadDeniedException)

Aggregations

PropertyNotFoundException (org.apache.jena.shared.PropertyNotFoundException)7 Statement (org.apache.jena.rdf.model.Statement)3 SecuredStatement (org.apache.jena.permissions.model.SecuredStatement)2 PermStatementFilter (org.apache.jena.permissions.utils.PermStatementFilter)2 ReifiedStatement (org.apache.jena.rdf.model.ReifiedStatement)2 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)2 Resource (org.apache.jena.rdf.model.Resource)1 StmtIterator (org.apache.jena.rdf.model.StmtIterator)1 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)1 Test (org.junit.Test)1