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