use of org.apache.jena.shared.AccessDeniedException in project jena by apache.
the class SecuredModelTest method testAsStatement_NotExists.
@Test
public void testAsStatement_NotExists() {
// check a triple that does not exist -- must have update to add it.
Triple t = new Triple(s.asNode(), p2.asNode(), o.asNode());
try {
Statement stmt = securedModel.asStatement(t);
assertEquals(securedModel, stmt.getModel());
if (securedModel.canRead(t)) {
assertEquals(s, stmt.getSubject());
assertEquals(p2, stmt.getPredicate());
assertEquals(o, stmt.getObject());
}
if (!securityEvaluator.evaluate(Action.Read) && !securityEvaluator.evaluate(Action.Update)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securedModel.canUpdate() && securedModel.canCreate(t)) {
Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
}
use of org.apache.jena.shared.AccessDeniedException in project jena by apache.
the class SecuredModelTest method testReadEmpty.
@Test
public void testReadEmpty() throws Exception {
final Set<Action> createAndUpdate = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
final String XML_INPUT = "<rdf:RDF" + " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' " + " xmlns:rt='http://example.com/readTest#' " + " xmlns:j.0='http://example.com/readTest#3' > " + " <rdf:Description rdf:about='http://example.com/readTest#1'> " + " <rdf:type rdf:resource='http://example.com/readTest#3'/>" + " </rdf:Description>" + "</rdf:RDF>";
final String TTL_INPUT = "@prefix rt: <http://example.com/readTest#> . rt:1 a rt:3 .";
final String base = "http://example.com/test";
final String lang = "TURTLE";
try {
final URL url = SecuredModelTest.class.getResource("./test.xml");
securedModel.read(url.toString());
if (!securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
} finally {
baseModel.removeAll();
}
try {
final InputStream in = new ByteArrayInputStream(XML_INPUT.getBytes());
securedModel.read(in, base);
if (!securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
} finally {
baseModel.removeAll();
}
try {
final Reader reader = new StringReader(XML_INPUT);
securedModel.read(reader, base);
if (!securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
} finally {
baseModel.removeAll();
}
try {
final URL url = SecuredModelTest.class.getResource("./test.ttl");
securedModel.read(url.toString(), lang);
if (!securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
} finally {
baseModel.removeAll();
}
try {
final InputStream in = new ByteArrayInputStream(TTL_INPUT.getBytes());
securedModel.read(in, base, lang);
if (!securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
} finally {
baseModel.removeAll();
}
try {
final Reader reader = new StringReader(TTL_INPUT);
securedModel.read(reader, base, lang);
if (!securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
} finally {
baseModel.removeAll();
}
try {
final URL url = SecuredModelTest.class.getResource("./test.ttl");
securedModel.read(url.toString(), base, lang);
if (!securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
} finally {
baseModel.removeAll();
}
}
use of org.apache.jena.shared.AccessDeniedException in project jena by apache.
the class SecuredAltTest method testSetDefaultObject.
@Test
public void testSetDefaultObject() {
Object o = 2;
Literal expected = ResourceFactory.createTypedLiteral(o);
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredAlt().setDefault(o);
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException");
}
RDFNode actual = alt.getDefault();
assertEquals(expected, actual);
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
try {
getSecuredAlt().setDefault(o);
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException on update");
}
RDFNode actual = alt.getDefault();
assertEquals(expected, actual);
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
Assert.fail("Should not have thrown AccessDeniedException on Update");
}
}
}
use of org.apache.jena.shared.AccessDeniedException in project jena by apache.
the class SecuredAltTest method testSetDefaultStringAndLang.
@Test
public void testSetDefaultStringAndLang() {
final Literal expected = ResourceFactory.createLangLiteral("dos", "es");
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredAlt().setDefault("dos", "es");
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException");
}
Literal actual = alt.getDefaultLiteral();
assertEquals(expected, actual);
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
try {
getSecuredAlt().setDefault("dos", "es");
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException on update");
}
Literal actual = alt.getDefaultLiteral();
assertEquals(expected, actual);
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
Assert.fail("Should not have thrown AccessDeniedException on Update");
}
}
}
use of org.apache.jena.shared.AccessDeniedException in project jena by apache.
the class SecuredContainerTest method testRemove.
@Test
public void testRemove() {
getBaseRDFNode().as(Container.class).add("SomeItem");
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Delete });
final Statement s = baseModel.listStatements().next();
try {
getSecuredContainer().remove(s);
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException: %s - %s", e, e.getTriple()));
}
}
}
Aggregations