use of org.apache.jena.shared.ReadDeniedException in project jena by apache.
the class SecuredRDFNodeTest method testInModel.
@Test
public void testInModel() {
final Model m2 = ModelFactory.createDefaultModel();
try {
final RDFNode n2 = securedRDFNode.inModel(m2);
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException Exception");
}
Assert.assertFalse("RDFNode should not have been secured", n2 instanceof SecuredRDFNode);
Assert.assertEquals("Wrong securedModel returned", n2.getModel(), m2);
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
m2.removeAll();
final SecuredModel m3 = Factory.getInstance(securityEvaluator, "http://example.com/securedGraph2", m2);
try {
final RDFNode n2 = securedRDFNode.inModel(m3);
if (!securityEvaluator.evaluate(Action.Read)) {
Assert.fail("Should have thrown ReadDeniedException Exception");
}
Assert.assertTrue("RDFNode should have been secured", n2 instanceof SecuredRDFNode);
Assert.assertEquals("Wrong securedModel returned", n2.getModel(), m3);
} 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 testAnonFuncs.
@Test
public void testAnonFuncs() {
final SecuredResource anonResource = securedModel.createResource();
setSecuredRDFNode(anonResource, null);
try {
getSecuredResource().getId();
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 OpRewriter method visit.
@Override
public void visit(final OpBGP opBGP) throws ReadDeniedException, AuthenticationRequiredException {
if (LOG.isDebugEnabled()) {
LOG.debug("Starting visiting OpBGP");
}
Object principal = securityEvaluator.getPrincipal();
if (!securityEvaluator.evaluate(principal, Action.Read, graphIRI)) {
if (silentFail) {
return;
} else {
throw new ReadDeniedException(SecuredItem.Util.modelPermissionMsg(graphIRI));
}
}
// if the user can read any triple just add the opBGP
if (securityEvaluator.evaluate(principal, Action.Read, graphIRI, Triple.ANY)) {
addOp(opBGP);
} else {
// add security filtering to the resulting triples
final List<Triple> newBGP = new ArrayList<>();
final List<Node> variables = new ArrayList<>();
// register all variables
for (final Triple t : opBGP.getPattern().getList()) {
newBGP.add(registerBGPTriple(t, variables));
}
// create the security function.
final SecuredFunction secFunc = new SecuredFunction(graphIRI, securityEvaluator, variables, newBGP);
// create the filter
Op filter = OpFilter.filter(secFunc, new OpBGP(BasicPattern.wrap(newBGP)));
// add the filter
addOp(filter);
}
}
use of org.apache.jena.shared.ReadDeniedException in project jena by apache.
the class SecuredRDFListTest method testReduce.
@Test
public void testReduce() {
final ReduceFn fn = new ReduceFn() {
@Override
public Object reduce(final RDFNode node, final Object accumulator) {
return accumulator;
}
};
try {
getSecuredRDFList().reduce(fn, "Hello");
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()));
}
}
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredRDFList().reduce(perms, fn, "Hello");
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 SecuredRDFListTest method testApply.
@Test
public void testApply() {
final ApplyFn fn = new ApplyFn() {
@Override
public void apply(final RDFNode node) {
// do nothing
}
};
try {
getSecuredRDFList().apply(fn);
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()));
}
}
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Read });
try {
getSecuredRDFList().apply(perms, fn);
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