use of org.apache.jena.shared.ReadDeniedException in project jena by apache.
the class OpRewriterTest method testBGPNoReadAccess.
@Test
public void testBGPNoReadAccess() {
SecurityEvaluator securityEvaluator = new MockSecurityEvaluator(true, true, false, true, true, true);
rewriter = new OpRewriter(securityEvaluator, "http://example.com/dummy");
Triple[] triples = { new Triple(NodeFactory.createVariable("foo"), RDF.type.asNode(), NodeFactory.createURI("http://example.com/class")), new Triple(NodeFactory.createVariable("foo"), NodeFactory.createBlankNode(), NodeFactory.createVariable("bar")), new Triple(NodeFactory.createVariable("bar"), NodeFactory.createBlankNode(), NodeFactory.createVariable("baz")) };
try {
rewriter.visit(new OpBGP(BasicPattern.wrap(Arrays.asList(triples))));
Assert.fail("Should have thrown AccessDeniedException");
} catch (ReadDeniedException e) {
// expected
}
}
use of org.apache.jena.shared.ReadDeniedException in project jena by apache.
the class SecuredResourceTest method testListProperties.
@Test
public void testListProperties() {
try {
SecuredStatementIterator iter = getSecuredResource().listProperties();
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException Exception");
}
assertTrue(iter.hasNext());
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
try {
SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p);
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException Exception");
}
if (hasP()) {
assertTrue(iter.hasNext());
} else {
assertFalse(iter.hasNext());
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
}
use of org.apache.jena.shared.ReadDeniedException in project jena by apache.
the class SecuredResourceTest method testListPropertiesWithLang.
@Test
public void testListPropertiesWithLang() {
try {
SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p2, "");
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException Exception");
}
if (hasP2()) {
assertTrue(iter.hasNext());
Statement stmt = iter.next();
assertEquals("yeehaw", stmt.getObject().asLiteral().getString());
}
assertFalse(iter.hasNext());
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
try {
SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p2, "us");
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException Exception");
}
if (hasP2()) {
assertTrue(iter.hasNext());
Statement stmt = iter.next();
assertEquals("yeehaw yall", stmt.getObject().asLiteral().getString());
}
assertFalse(iter.hasNext());
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
try {
SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p2, "uk");
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException Exception");
}
if (hasP2()) {
assertTrue(iter.hasNext());
Statement stmt = iter.next();
assertEquals("whohoo", stmt.getObject().asLiteral().getString());
}
assertFalse(iter.hasNext());
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
}
use of org.apache.jena.shared.ReadDeniedException in project jena by apache.
the class SecuredSeqTest method testGetBag.
@Test
public void testGetBag() {
try {
final Bag a = getSecuredSeq().getBag(1);
Assert.assertTrue("Should be a secured Bag", a instanceof SecuredBag);
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException 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()));
}
}
}
use of org.apache.jena.shared.ReadDeniedException in project jena by apache.
the class SecuredSeqTest method testGetAlt.
@Test
public void testGetAlt() {
try {
final Alt a = getSecuredSeq().getAlt(1);
Assert.assertTrue("Should be a secured Alt", a instanceof SecuredAlt);
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException 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()));
}
}
}
Aggregations