Search in sources :

Example 1 with SecuredGraph

use of org.apache.jena.permissions.graph.SecuredGraph in project jena by apache.

the class SecuredPrefixMappingTest method setup.

@Before
public void setup() {
    final Graph g = GraphFactory.createDefaultGraph();
    final SecuredGraph sg = Factory.getInstance(securityEvaluator, "http://example.com/testGraph", g);
    this.securedMapping = sg.getPrefixMapping();
}
Also used : SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph) Graph(org.apache.jena.graph.Graph) SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph) Before(org.junit.Before)

Example 2 with SecuredGraph

use of org.apache.jena.permissions.graph.SecuredGraph in project jena by apache.

the class Factory method getInstance.

/**
	 * Create an instance of the SecuredGraph
	 * 
	 * @param securityEvaluator
	 *            The security evaluator to use
	 * @param graphIRI
	 *            The IRI for the graph.
	 * @param graph
	 *            The graph that we are wrapping.
	 * @return the secured graph
	 */
public static SecuredGraph getInstance(final SecurityEvaluator securityEvaluator, final String graphIRI, final Graph graph) {
    final ItemHolder<Graph, SecuredGraphImpl> holder = new ItemHolder<>(graph);
    final SecuredGraphImpl checker = new SecuredGraphImpl(securityEvaluator, graphIRI, holder) {
    };
    // If we going to create a duplicate proxy return this one.
    if (graph instanceof SecuredGraphImpl) {
        if (checker.isEquivalent((SecuredGraphImpl) graph)) {
            return (SecuredGraph) graph;
        }
    }
    return holder.setSecuredItem(new SecuredItemInvoker(graph.getClass(), checker));
}
Also used : ItemHolder(org.apache.jena.permissions.impl.ItemHolder) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph) Graph(org.apache.jena.graph.Graph) SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph)

Example 3 with SecuredGraph

use of org.apache.jena.permissions.graph.SecuredGraph in project jena by apache.

the class SecuredModelTest method testGetGraph.

@Test
public void testGetGraph() throws Exception {
    final Graph g = securedModel.getGraph();
    Assert.assertTrue(g instanceof SecuredGraph);
    EqualityTester.testInequality("getGraph test", g, baseModel.getGraph());
}
Also used : SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph) Graph(org.apache.jena.graph.Graph) SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph) Test(org.junit.Test) SecuredPrefixMappingTest(org.apache.jena.permissions.graph.SecuredPrefixMappingTest)

Example 4 with SecuredGraph

use of org.apache.jena.permissions.graph.SecuredGraph in project jena by apache.

the class MemGraphTest method testInequality.

@Test
public void testInequality() {
    EqualityTester.testInequality("proxy and base", securedGraph, baseGraph);
    final Graph g2 = org.apache.jena.permissions.graph.impl.Factory.getInstance(securityEvaluator, "http://example.com/securedGraph", baseGraph);
    EqualityTester.testEquality("proxy and proxy2", securedGraph, g2);
    EqualityTester.testInequality("base and proxy2", baseGraph, g2);
}
Also used : SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph) Test(org.junit.Test)

Example 5 with SecuredGraph

use of org.apache.jena.permissions.graph.SecuredGraph in project jena by apache.

the class SecuredQueryEngine method setGraphIRI.

private void setGraphIRI(final DatasetGraph dataset) {
    final Graph g = dataset.getDefaultGraph();
    if (g instanceof SecuredGraph) {
        final SecuredGraph sg = (SecuredGraph) g;
        graphIRI = sg.getModelNode();
        this.securityEvaluator = sg.getSecurityEvaluator();
    } else {
        graphIRI = NodeFactory.createURI("urn:x-arq:DefaultGraph");
        this.securityEvaluator = new SecurityEvaluator() {

            @Override
            public boolean evaluate(final Object principal, final Action action, final Node graphIRI) {
                return true;
            }

            @Override
            public boolean evaluate(final Object principal, final Action action, final Node graphIRI, final Triple triple) {
                return true;
            }

            @Override
            public boolean evaluate(final Object principal, final Set<Action> action, final Node graphIRI) {
                return true;
            }

            @Override
            public boolean evaluate(final Object principal, final Set<Action> action, final Node graphIRI, final Triple triple) {
                return true;
            }

            @Override
            public boolean evaluateAny(final Object principal, final Set<Action> action, final Node graphIRI) {
                return true;
            }

            @Override
            public boolean evaluateAny(final Object principal, final Set<Action> action, final Node graphIRI, final Triple triple) {
                return true;
            }

            @Override
            public boolean evaluateUpdate(final Object principal, final Node graphIRI, final Triple from, final Triple to) {
                return true;
            }

            @Override
            public Principal getPrincipal() {
                return null;
            }

            @Override
            public boolean isPrincipalAuthenticated(Object principal) {
                return true;
            }
        };
    }
}
Also used : Triple(org.apache.jena.graph.Triple) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) SecurityEvaluator(org.apache.jena.permissions.SecurityEvaluator) Principal(java.security.Principal) SecuredGraph(org.apache.jena.permissions.graph.SecuredGraph)

Aggregations

SecuredGraph (org.apache.jena.permissions.graph.SecuredGraph)5 Graph (org.apache.jena.graph.Graph)4 Test (org.junit.Test)2 Principal (java.security.Principal)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 SecurityEvaluator (org.apache.jena.permissions.SecurityEvaluator)1 SecuredPrefixMappingTest (org.apache.jena.permissions.graph.SecuredPrefixMappingTest)1 ItemHolder (org.apache.jena.permissions.impl.ItemHolder)1 SecuredItemInvoker (org.apache.jena.permissions.impl.SecuredItemInvoker)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 Before (org.junit.Before)1