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