Search in sources :

Example 11 with AccessDeniedException

use of org.apache.jena.shared.AccessDeniedException in project jena by apache.

the class SecuredRDFListTest method testRemoveHead.

@Test
public void testRemoveHead() {
    try {
        RDFList rdfList = getSecuredRDFList().removeHead();
        if (!shouldRead() || !securityEvaluator.evaluate(Action.Update) || !securityEvaluator.evaluate(Action.Delete)) {
            fail("Should have thrown AccessDeniedException");
        }
        Iterator<RDFNode> iter = rdfList.asJavaList().iterator();
        assertEquals(resource2, iter.next());
        assertEquals(resource3, iter.next());
        assertEquals(resource4, iter.next());
        assertFalse(iter.hasNext());
    } catch (final AccessDeniedException e) {
        if (shouldRead() && securityEvaluator.evaluate(Action.Update) && securityEvaluator.evaluate(Action.Delete)) {
            fail("Should not have thrown AccessDeniedException");
        }
    } catch (final EmptyListException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            fail("Should not have thrown EmptyListException");
        }
    }
}
Also used : AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFList(org.apache.jena.rdf.model.RDFList) EmptyListException(org.apache.jena.rdf.model.EmptyListException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Example 12 with AccessDeniedException

use of org.apache.jena.shared.AccessDeniedException in project jena by apache.

the class SecuredRDFListTest method testReplace.

@Test
public void testReplace() {
    try {
        RDFNode result = getSecuredRDFList().replace(1, newResource1);
        if (!shouldRead() || !securityEvaluator.evaluate(Action.Update)) {
            fail("Should have thrown AccessDeniedException");
        }
        assertEquals(resource2, result);
        List<RDFNode> lst = ((RDFList) getBaseRDFNode()).asJavaList();
        Iterator<RDFNode> iter = lst.iterator();
        assertEquals(resource1, iter.next());
        assertEquals(newResource1, iter.next());
        assertEquals(resource3, iter.next());
        assertEquals(resource4, iter.next());
        assertFalse(iter.hasNext());
    } catch (final AccessDeniedException e) {
        if (shouldRead() && securityEvaluator.evaluate(Action.Update) && securityEvaluator.evaluate(Action.Delete)) {
            fail("Should not have thrown AccessDeniedException");
        }
    } catch (final ListIndexException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            fail("Should not have thrown ListIndexException");
        }
    }
}
Also used : AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFList(org.apache.jena.rdf.model.RDFList) ListIndexException(org.apache.jena.rdf.model.ListIndexException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Example 13 with AccessDeniedException

use of org.apache.jena.shared.AccessDeniedException in project jena by apache.

the class SecuredContainerTest method testAdd.

private <T> void testAdd(Supplier<Container> supplier, T expected) {
    final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
    try {
        SecuredContainer securedContainer = (SecuredContainer) supplier.get();
        if (!securityEvaluator.evaluate(perms)) {
            Assert.fail("Should have thrown AccessDeniedException");
        }
        Container container = (Container) securedContainer.getBaseItem();
        if (expected instanceof RDFNode) {
            assertTrue(container.contains((RDFNode) expected));
        } else {
            assertTrue(container.contains(expected));
        }
    } catch (final AccessDeniedException e) {
        if (securityEvaluator.evaluate(perms)) {
            Assert.fail(String.format("Should not have thrown AccessDeniedException: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : Action(org.apache.jena.permissions.SecurityEvaluator.Action) Container(org.apache.jena.rdf.model.Container) AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

AccessDeniedException (org.apache.jena.shared.AccessDeniedException)13 Test (org.junit.Test)11 Action (org.apache.jena.permissions.SecurityEvaluator.Action)8 RDFNode (org.apache.jena.rdf.model.RDFNode)7 RDFList (org.apache.jena.rdf.model.RDFList)4 SecuredPrefixMappingTest (org.apache.jena.permissions.graph.SecuredPrefixMappingTest)3 Literal (org.apache.jena.rdf.model.Literal)3 ReifiedStatement (org.apache.jena.rdf.model.ReifiedStatement)3 Statement (org.apache.jena.rdf.model.Statement)3 Triple (org.apache.jena.graph.Triple)2 Container (org.apache.jena.rdf.model.Container)2 EmptyListException (org.apache.jena.rdf.model.EmptyListException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 ListIndexException (org.apache.jena.rdf.model.ListIndexException)1 Model (org.apache.jena.rdf.model.Model)1