You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by cl...@apache.org on 2015/04/25 10:51:08 UTC
[05/24] jena git commit: modifications to rename jena security as
jena permissions modifications to adapt to removed deprecated classes in
org.apache.jena.
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredStatementTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredStatementTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredStatementTest.java
new file mode 100644
index 0000000..b6a7737
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredStatementTest.java
@@ -0,0 +1,707 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions.model;
+
+import java.util.Set;
+
+import org.apache.jena.permissions.AccessDeniedException;
+import org.apache.jena.permissions.Factory;
+import org.apache.jena.permissions.MockSecurityEvaluator;
+import org.apache.jena.permissions.SecurityEvaluator;
+import org.apache.jena.permissions.SecurityEvaluatorParameters;
+import org.apache.jena.permissions.SecurityEvaluator.Action;
+import org.apache.jena.permissions.model.SecuredModel;
+import org.apache.jena.permissions.model.SecuredStatement;
+import org.apache.jena.permissions.model.impl.SecuredStatementImpl;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.shared.PropertyNotFoundException ;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredStatementTest
+{
+ private final MockSecurityEvaluator securityEvaluator;
+ private Statement baseStatement;
+ private SecuredStatement securedStatement;
+ private Model baseModel;
+ private SecuredModel securedModel;
+ private Property property;
+
+ public SecuredStatementTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ this.securityEvaluator = securityEvaluator;
+ }
+
+ protected Model createModel()
+ {
+ return ModelFactory.createDefaultModel();
+ }
+
+ @Before
+ public void setup()
+ {
+ baseModel = createModel();
+ property = ResourceFactory
+ .createProperty("http://example.com/property");
+ baseModel.add(ResourceFactory.createResource(), property,
+ ResourceFactory.createResource());
+ baseStatement = baseModel.listStatements().next();
+ securedModel = Factory.getInstance(securityEvaluator,
+ "http://example.com/securedModel", baseModel);
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement);
+ }
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Test
+ public void testChangeLiteralObject()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util
+ .asSet(new Action[] { Action.Update });
+ try
+ {
+ securedStatement.changeLiteralObject(true);
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.changeLiteralObject('c');
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.changeLiteralObject(3.14d);
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.changeLiteralObject(3.14F);
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.changeLiteralObject(2);
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.changeLiteralObject(2L);
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.changeObject(ResourceFactory.createResource());
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.changeObject("Waaa hooo");
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ final Literal l = ResourceFactory
+ .createTypedLiteral(Integer.MAX_VALUE);
+ securedStatement.changeObject(l.getLexicalForm(), true);
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.changeObject("dos", "es");
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.changeObject("dos", "es", false);
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testCreateReifiedStatement()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ try
+ {
+ securedStatement.createReifiedStatement();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedStatement.createReifiedStatement("http://example.com/rsURI");
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetProperty()
+ {
+ // get property of the object
+ baseModel.add(baseStatement.getObject().asResource(), property,
+ ResourceFactory.createResource());
+ try
+ {
+ securedStatement.getProperty(property);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown PropertyNotFound Exception");
+ }
+ }
+ catch (final PropertyNotFoundException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown PropertyNotFound Exception: %s - %s",
+ e, securityEvaluator));
+ }
+ }
+ }
+
+ @Test
+ public void testGets()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util
+ .asSet(new Action[] { Action.Read });
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeLiteralObject(true));
+ try
+ {
+ securedStatement.getBoolean();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeLiteralObject(Byte.MAX_VALUE));
+ try
+ {
+ securedStatement.getByte();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeLiteralObject('c'));
+ try
+ {
+ securedStatement.getChar();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeLiteralObject(3.14d));
+ try
+ {
+ securedStatement.getDouble();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeLiteralObject(3.14F));
+ try
+ {
+ securedStatement.getFloat();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeLiteralObject(2));
+ try
+ {
+ securedStatement.getInt();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeObject("dos", "es"));
+ try
+ {
+ securedStatement.getLanguage();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeLiteralObject(2L));
+ try
+ {
+ securedStatement.getLong();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeLiteralObject(Short.MAX_VALUE));
+ try
+ {
+ securedStatement.getShort();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeObject("who hoo"));
+ try
+ {
+ securedStatement.getString();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeObject("who hoo"));
+ try
+ {
+ securedStatement.hasWellFormedXML();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetStatementProperty()
+ {
+ // get property of the subject
+ final ReifiedStatement s = baseStatement.createReifiedStatement();
+ s.addLiteral(property, "yee haw");
+ securedStatement.getStatementProperty(property);
+
+ }
+
+ @Test
+ public void testIsReified()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util
+ .asSet(new Action[] { Action.Read });
+
+ try
+ {
+ securedStatement.isReified();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testListReifiedStatements()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util
+ .asSet(new Action[] { Action.Read });
+
+ try
+ {
+ securedStatement.listReifiedStatements();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testRemove()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Delete });
+
+ try
+ {
+ securedStatement.remove();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testRemoveReification()
+ {
+ baseStatement.createReifiedStatement();
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Delete });
+
+ try
+ {
+ securedStatement.removeReification();
+ if (!securityEvaluator.evaluate(perms))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(perms))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testUnsecuredGets()
+ {
+ securedStatement.getAlt();
+ securedStatement.getBag();
+ securedStatement.getSeq();
+
+ securedStatement.getResource();
+ // securedStatement.getResource( ResourceF f );
+ securedStatement.getSubject();
+
+ securedStatement = SecuredStatementImpl.getInstance(securedModel,
+ baseStatement.changeLiteralObject(true));
+ securedStatement.getLiteral();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/permissions/query/DataSetTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/query/DataSetTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/query/DataSetTest.java
new file mode 100644
index 0000000..b179da4
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/query/DataSetTest.java
@@ -0,0 +1,245 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions.query;
+
+import org.apache.jena.permissions.Factory;
+import org.apache.jena.permissions.MockSecurityEvaluator;
+import org.apache.jena.permissions.SecurityEvaluator.SecNode.Type;
+import org.apache.jena.permissions.model.SecuredModel;
+import org.apache.jena.permissions.query.SecuredQueryEngineFactory;
+import org.apache.jena.query.* ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.tdb.TDB ;
+import org.apache.jena.tdb.TDBFactory ;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class DataSetTest {
+ private Dataset dataset;
+ private Model baseModel;
+ private MockSecurityEvaluator eval;
+ private SecuredModel dftModel;
+
+ @BeforeClass
+ public static void setupFactory()
+ {
+ SecuredQueryEngineFactory.register();
+ }
+
+ @AfterClass
+ public static void teardownFactory()
+ {
+ SecuredQueryEngineFactory.unregister();
+ }
+
+
+ public void setup() {
+
+ DatasetGraph dsg = TDBFactory.createDatasetGraph() ;
+
+
+ dsg.getContext().set(TDB.symUnionDefaultGraph, true) ;
+ Dataset myDataset = DatasetFactory.create(dsg) ;
+
+// DatasetGraph dsg = DatasetGraphFactory.createMem() ;
+//
+// Dataset myDataset = TDBFactory.createDataset();
+ baseModel = myDataset.getNamedModel( "http://example.com/baseModel");
+ //baseModel = myDataset.getDefaultModel();
+ baseModel = QueryEngineTest.populateModel( baseModel );
+
+ dftModel = Factory.getInstance(eval,
+ "http://example.com/securedModel", baseModel);
+
+ dataset = DatasetFactory.createMem() ;
+ dataset.setDefaultModel(dftModel) ;
+
+// // dataset.addNamedModel( dftModel.getModelIRI(), dftModel);
+
+
+
+ }
+
+ @Test
+ public void testOpenQueryType()
+ {
+ eval = new MockSecurityEvaluator(true, true,
+ true, true, true, true);
+
+ setup();
+
+ try
+ {
+ final String query = "prefix fn: <http://www.w3.org/2005/xpath-functions#> "
+ + " SELECT ?foo ?bar WHERE "
+ + " { ?foo a <http://example.com/class> ; "
+ + "?bar [] ."
+ + " } ";
+ final QueryExecution qexec = QueryExecutionFactory.create(query,
+ dataset);
+ try
+ {
+ final ResultSet results = qexec.execSelect();
+ int count = 0;
+ for (; results.hasNext();)
+ {
+ count++;
+ final QuerySolution soln = results.nextSolution();
+ }
+ Assert.assertEquals(8, count);
+ }
+ finally
+ {
+ qexec.close();
+ }
+ }
+ finally
+ {
+ dataset.close();
+ }
+ }
+
+ @Test
+ public void testRestrictedQueryType()
+ {
+ eval = new MockSecurityEvaluator(true, true,
+ true, true, true, true) {
+
+ @Override
+ public boolean evaluate( final Object principal, final Action action,
+ final SecNode graphIRI, final SecTriple triple )
+ {
+ if (triple.getSubject().equals(
+ new SecNode(Type.URI, "http://example.com/resource/1")))
+ {
+ return false;
+ }
+ return super.evaluate(principal, action, graphIRI, triple);
+ }
+ };
+
+ setup();
+
+ try
+ {
+ final String query = "prefix fn: <http://www.w3.org/2005/xpath-functions#> "
+ + " SELECT ?foo ?bar WHERE "
+ + " { ?foo a <http://example.com/class> ; "
+ + "?bar [] ."
+ + " } ";
+ final QueryExecution qexec = QueryExecutionFactory.create(query,
+ dataset);
+ try
+ {
+ final ResultSet results = qexec.execSelect();
+ int count = 0;
+ for (; results.hasNext();)
+ {
+ count++;
+ results.nextSolution();
+ }
+ Assert.assertEquals(4, count);
+ }
+ finally
+ {
+ qexec.close();
+ }
+ }
+ finally
+ {
+ dataset.close();
+ }
+ }
+
+ @Test
+ public void testSelectAllType()
+ {
+ eval = new MockSecurityEvaluator(true, true,
+ true, true, true, true) {
+
+ @Override
+ public boolean evaluate( final Object principal, final Action action,
+ final SecNode graphIRI, final SecTriple triple )
+ {
+ if (triple.getSubject().equals(
+ new SecNode(Type.URI, "http://example.com/resource/1")))
+ {
+ return false;
+ }
+ return super.evaluate(principal, action, graphIRI, triple);
+ }
+ };
+
+ setup();
+
+ try
+ {
+ String query = "SELECT ?s ?p ?o WHERE "
+ + " { ?s ?p ?o } ";
+ QueryExecution qexec = QueryExecutionFactory.create(query,
+ dataset);
+ try
+ {
+ final ResultSet results = qexec.execSelect();
+ int count = 0;
+ for (; results.hasNext();)
+ {
+ count++;
+ final QuerySolution soln = results.nextSolution();
+ //System.out.println( soln );
+ }
+ // 2x 3 values + type triple
+ Assert.assertEquals(8, count);
+ }
+ finally
+ {
+ qexec.close();
+ }
+
+ query = "SELECT ?g ?s ?p ?o WHERE "
+ + " { GRAPH ?g {?s ?p ?o } }";
+ qexec = QueryExecutionFactory.create(query,
+ dataset);
+ try
+ {
+ final ResultSet results = qexec.execSelect();
+ int count = 0;
+ for (; results.hasNext();)
+ {
+ count++;
+ final QuerySolution soln = results.nextSolution();
+ //System.out.println( soln );
+ }
+ // 2x 3 values + type triple
+ // all are in the base graph so no named graphs
+ Assert.assertEquals(0, count);
+ }
+ finally
+ {
+ qexec.close();
+ }
+ }
+ finally
+ {
+ dataset.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/permissions/query/QueryEngineTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/query/QueryEngineTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/query/QueryEngineTest.java
new file mode 100644
index 0000000..11999a1
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/query/QueryEngineTest.java
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions.query;
+
+import org.apache.jena.permissions.Factory;
+import org.apache.jena.permissions.MockSecurityEvaluator;
+import org.apache.jena.permissions.SecurityEvaluator;
+import org.apache.jena.permissions.SecurityEvaluator.SecNode.Type;
+import org.apache.jena.permissions.model.SecuredModel;
+import org.apache.jena.permissions.query.SecuredQueryEngineFactory;
+import org.apache.jena.query.QueryExecution ;
+import org.apache.jena.query.QueryExecutionFactory ;
+import org.apache.jena.query.QuerySolution ;
+import org.apache.jena.query.ResultSet ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.ModelFactory ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+import org.apache.jena.vocabulary.RDF ;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class QueryEngineTest {
+
+ @BeforeClass
+ public static void setupFactory() {
+ SecuredQueryEngineFactory.register();
+ }
+
+ @AfterClass
+ public static void teardownFactory() {
+ SecuredQueryEngineFactory.unregister();
+ }
+
+ Model baseModel;
+
+ public QueryEngineTest() {
+
+ }
+
+
+ public static Model populateModel(Model baseModel)
+ {
+
+ Resource r = ResourceFactory
+ .createResource("http://example.com/resource/1");
+ final Resource o = ResourceFactory
+ .createResource("http://example.com/class");
+ baseModel.add(r, RDF.type, o);
+ baseModel.add(r, ResourceFactory
+ .createProperty("http://example.com/property/_1"),
+ ResourceFactory.createTypedLiteral(1));
+ baseModel.add(r, ResourceFactory
+ .createProperty("http://example.com/property/_2"),
+ ResourceFactory.createTypedLiteral("foo"));
+ baseModel.add(r, ResourceFactory
+ .createProperty("http://example.com/property/_3"),
+ ResourceFactory.createTypedLiteral(3.14));
+ r = ResourceFactory.createResource("http://example.com/resource/2");
+ baseModel.add(r, RDF.type, o);
+ baseModel.add(r, ResourceFactory
+ .createProperty("http://example.com/property/_1"),
+ ResourceFactory.createTypedLiteral(2));
+ baseModel.add(r, ResourceFactory
+ .createProperty("http://example.com/property/_2"),
+ ResourceFactory.createTypedLiteral("bar"));
+ baseModel.add(r, ResourceFactory
+ .createProperty("http://example.com/property/_3"),
+ ResourceFactory.createTypedLiteral(6.28));
+
+ r = ResourceFactory.createResource("http://example.com/resource/3");
+ baseModel.add(r, RDF.type, ResourceFactory
+ .createResource("http://example.com/anotherClass"));
+ baseModel.add(r, ResourceFactory
+ .createProperty("http://example.com/property/_1"),
+ ResourceFactory.createTypedLiteral(3));
+ baseModel.add(r, ResourceFactory
+ .createProperty("http://example.com/property/_2"),
+ ResourceFactory.createTypedLiteral("baz"));
+ baseModel.add(r, ResourceFactory
+ .createProperty("http://example.com/property/_3"),
+ ResourceFactory.createTypedLiteral(9.42));
+ return baseModel;
+ }
+
+ @Before
+ public void setUp()
+ {
+ baseModel = populateModel( ModelFactory.createDefaultModel());
+ }
+
+ @After
+ public void tearDown() {
+ baseModel.close();
+ }
+
+ @Test
+ public void testOpenQueryType() {
+ final SecurityEvaluator eval = new MockSecurityEvaluator(true, true,
+ true, true, true, true);
+ final SecuredModel model = Factory.getInstance(eval,
+ "http://example.com/securedModel", baseModel);
+ try {
+ final String query = "prefix fn: <http://www.w3.org/2005/xpath-functions#> "
+ + " SELECT ?foo ?bar WHERE "
+ + " { ?foo a <http://example.com/class> ; "
+ + "?bar [] ."
+ + " } ";
+ final QueryExecution qexec = QueryExecutionFactory.create(query,
+ model);
+ try {
+ final ResultSet results = qexec.execSelect();
+ int count = 0;
+ for (; results.hasNext();) {
+ count++;
+ final QuerySolution soln = results.nextSolution();
+ }
+ Assert.assertEquals(8, count);
+ } finally {
+ qexec.close();
+ }
+ } finally {
+ model.close();
+ }
+ }
+
+ @Test
+ public void testRestrictedQueryType() {
+ final SecurityEvaluator eval = new MockSecurityEvaluator(true, true,
+ true, true, true, true) {
+
+ @Override
+ public boolean evaluate(final Object principal,
+ final Action action, final SecNode graphIRI,
+ final SecTriple triple) {
+ if (triple.getSubject().equals(
+ new SecNode(Type.URI, "http://example.com/resource/1"))) {
+ return false;
+ }
+ return super.evaluate(principal, action, graphIRI, triple);
+ }
+ };
+ final SecuredModel model = Factory.getInstance(eval,
+ "http://example.com/securedModel", baseModel);
+ try {
+ final String query = "prefix fn: <http://www.w3.org/2005/xpath-functions#> "
+ + " SELECT ?foo ?bar WHERE "
+ + " { ?foo a <http://example.com/class> ; "
+ + "?bar [] ."
+ + " } ";
+ final QueryExecution qexec = QueryExecutionFactory.create(query,
+ model);
+ try {
+ final ResultSet results = qexec.execSelect();
+ int count = 0;
+ for (; results.hasNext();) {
+ count++;
+ results.nextSolution();
+ }
+ Assert.assertEquals(4, count);
+ } finally {
+ qexec.close();
+ }
+ } finally {
+ model.close();
+ }
+ }
+
+ @Test
+ public void testSelectAllType()
+ {
+ final SecurityEvaluator eval = new MockSecurityEvaluator(true, true,
+ true, true, true, true) {
+
+ @Override
+ public boolean evaluate(Object principal, final Action action,
+ final SecNode graphIRI, final SecTriple triple )
+ {
+ if (triple.getSubject().equals(
+ new SecNode(Type.URI, "http://example.com/resource/1")))
+ {
+ return false;
+ }
+ return super.evaluate(principal, action, graphIRI, triple);
+ }
+ };
+ final SecuredModel model = Factory.getInstance(eval,
+ "http://example.com/securedModel", baseModel);
+ try
+ {
+ String query = "SELECT ?s ?p ?o WHERE "
+ + " { ?s ?p ?o } ";
+ QueryExecution qexec = QueryExecutionFactory.create(query,
+ model);
+ try
+ {
+ final ResultSet results = qexec.execSelect();
+ int count = 0;
+ for (; results.hasNext();)
+ {
+ count++;
+ final QuerySolution soln = results.nextSolution();
+ //System.out.println( soln );
+ }
+ // 2x 3 values + type triple
+ Assert.assertEquals(8, count);
+ }
+ finally
+ {
+ qexec.close();
+ }
+
+ query = "SELECT ?s ?p ?o WHERE "
+ + " { GRAPH ?g {?s ?p ?o } }";
+ qexec = QueryExecutionFactory.create(query,
+ model);
+ try
+ {
+ final ResultSet results = qexec.execSelect();
+ int count = 0;
+ for (; results.hasNext();)
+ {
+ count++;
+ final QuerySolution soln = results.nextSolution();
+ //System.out.println( soln );
+ }
+ // 2x 3 values + type triple
+ // no named graphs so no results.
+ Assert.assertEquals(0, count);
+ }
+ finally
+ {
+ qexec.close();
+ }
+ }
+ finally
+ {
+ model.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/permissions/query/rewriter/OpRewriterTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/query/rewriter/OpRewriterTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/query/rewriter/OpRewriterTest.java
new file mode 100644
index 0000000..3e5d0d4
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/query/rewriter/OpRewriterTest.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions.query.rewriter;
+
+import java.util.Arrays;
+
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.permissions.AccessDeniedException;
+import org.apache.jena.permissions.MockSecurityEvaluator;
+import org.apache.jena.permissions.SecurityEvaluator;
+import org.apache.jena.permissions.query.rewriter.OpRewriter;
+import org.apache.jena.permissions.query.rewriter.SecuredFunction;
+import org.apache.jena.sparql.algebra.Op ;
+import org.apache.jena.sparql.algebra.op.OpBGP ;
+import org.apache.jena.sparql.algebra.op.OpFilter ;
+import org.apache.jena.sparql.core.BasicPattern ;
+import org.apache.jena.sparql.expr.ExprList ;
+import org.apache.jena.vocabulary.RDF ;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class OpRewriterTest
+{
+ private OpRewriter rewriter;
+ private Triple[] triples;
+
+ public OpRewriterTest()
+ {
+ }
+
+ @Before
+ public void setup()
+ {
+ triples = new Triple[] {
+ new Triple( NodeFactory.createVariable("foo"), RDF.type.asNode(), NodeFactory.createURI( "http://example.com/class")),
+ new Triple( NodeFactory.createVariable("foo"), NodeFactory.createAnon(), NodeFactory.createVariable("bar")),
+ new Triple( NodeFactory.createVariable("bar"), NodeFactory.createAnon(), NodeFactory.createVariable("baz")),
+ };
+ }
+
+ @Test
+ public void testBGP()
+ {
+ SecurityEvaluator securityEvaluator = new MockSecurityEvaluator( true, true, true, true, true, true );
+ rewriter = new OpRewriter( securityEvaluator, "http://example.com/dummy");
+
+ rewriter.visit( new OpBGP( BasicPattern.wrap(Arrays.asList(triples))));
+ Op op = rewriter.getResult();
+ Assert.assertTrue( "Should have been an OpFilter", op instanceof OpFilter );
+ OpFilter filter = (OpFilter) op;
+ ExprList eLst = filter.getExprs();
+ Assert.assertEquals( 1, eLst.size());
+ Assert.assertTrue( "Should have been a SecuredFunction", eLst.get(0) instanceof SecuredFunction);
+ op = filter.getSubOp();
+ Assert.assertTrue( "Should have been a OpBGP", op instanceof OpBGP);
+ BasicPattern basicPattern = ((OpBGP)op).getPattern();
+ Assert.assertEquals( 3, basicPattern.size() );
+
+ Triple t = basicPattern.get(0);
+ Assert.assertEquals( NodeFactory.createVariable("foo"), t.getSubject());
+ Assert.assertEquals( RDF.type.asNode(), t.getPredicate());
+ Assert.assertEquals( NodeFactory.createURI( "http://example.com/class"), t.getObject());
+
+ t = basicPattern.get(1);
+ Assert.assertEquals( NodeFactory.createVariable("foo"), t.getSubject());
+ Assert.assertTrue( "Should have been blank", t.getPredicate().isBlank());
+ Assert.assertEquals( NodeFactory.createVariable("bar"), t.getObject());
+
+ t = basicPattern.get(2);
+ Assert.assertEquals( NodeFactory.createVariable("bar"), t.getSubject() );
+ Assert.assertTrue( "Should have been blank", t.getPredicate().isBlank());
+ Assert.assertEquals( NodeFactory.createVariable("baz"), t.getObject());
+ }
+
+ @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.createAnon(), NodeFactory.createVariable("bar")),
+ new Triple( NodeFactory.createVariable("bar"), NodeFactory.createAnon(), NodeFactory.createVariable("baz")),
+ };
+ try {
+ rewriter.visit( new OpBGP( BasicPattern.wrap(Arrays.asList(triples))));
+ Assert.fail( "Should have thrown AccessDeniedException");
+ }
+ catch (AccessDeniedException e)
+ {
+ // expected
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/EqualityTester.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/EqualityTester.java b/jena-permissions/src/test/java/org/apache/jena/security/EqualityTester.java
deleted file mode 100644
index 4b1d882..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/EqualityTester.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security;
-
-import org.junit.Assert;
-
-public class EqualityTester
-{
-
- public static void testEquality( final String label, final Object o1,
- final Object o2 )
- {
- Assert.assertEquals(label, o1, o2);
- Assert.assertEquals(label + " inverse", o2, o1);
- Assert.assertEquals(label + " hashCode", o1.hashCode(), o2.hashCode());
- }
-
- public static void testInequality( final String label, final Object o1,
- final Object o2 )
- {
- if ((o1 == null) && (o2 == null))
- {
- Assert.fail(label + ": both arguments are null");
- }
- if ((o1 == null) || (o2 == null))
- {
- return;
- }
- Assert.assertFalse(label, o2.equals(o1));
- Assert.assertFalse(label, o1.equals(o2));
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/MockPrefixMapping.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/MockPrefixMapping.java b/jena-permissions/src/test/java/org/apache/jena/security/MockPrefixMapping.java
deleted file mode 100644
index 5db2402..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/MockPrefixMapping.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.jena.shared.PrefixMapping ;
-
-public class MockPrefixMapping implements PrefixMapping
-{
-
- @Override
- public String expandPrefix( final String prefixed )
- {
- return prefixed;
- }
-
- @Override
- public Map<String, String> getNsPrefixMap()
- {
- return Collections.emptyMap();
- }
-
- @Override
- public String getNsPrefixURI( final String prefix )
- {
- return null;
- }
-
- @Override
- public String getNsURIPrefix( final String uri )
- {
- return null;
- }
-
- @Override
- public PrefixMapping lock()
- {
- return this;
- }
-
- @Override
- public String qnameFor( final String uri )
- {
- return null;
- }
-
- @Override
- public PrefixMapping removeNsPrefix( final String prefix )
- {
- return this;
- }
-
- @Override
- public boolean samePrefixMappingAs( final PrefixMapping other )
- {
- return false;
- }
-
- @Override
- public PrefixMapping setNsPrefix( final String prefix, final String uri )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public PrefixMapping setNsPrefixes( final Map<String, String> map )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public PrefixMapping setNsPrefixes( final PrefixMapping other )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String shortForm( final String uri )
- {
- return uri;
- }
-
- @Override
- public PrefixMapping withDefaultMappings( final PrefixMapping map )
- {
- throw new UnsupportedOperationException();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/MockSecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/MockSecurityEvaluator.java b/jena-permissions/src/test/java/org/apache/jena/security/MockSecurityEvaluator.java
deleted file mode 100644
index 797bdf0..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/MockSecurityEvaluator.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security;
-
-import java.security.Principal;
-import java.util.Collections;
-import java.util.Set;
-
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.security.SecurityEvaluator;
-
-public class MockSecurityEvaluator implements SecurityEvaluator
-{
-
- private final boolean loggedIn;
- private final boolean create;
- private final boolean read;
- private final boolean update;
- private final boolean delete;
- private final boolean forceTripleChecks;
-
- public static MockSecurityEvaluator getInstance()
- {
- return new MockSecurityEvaluator( true, true, true, true, true, true );
- }
-
-
- public MockSecurityEvaluator( final boolean loggedIn, final boolean create,
- final boolean read, final boolean update, final boolean delete,
- final boolean forceTripleChecks )
- {
- this.loggedIn = loggedIn;
- this.create = create;
- this.read = read;
- this.update = update;
- this.delete = delete;
- this.forceTripleChecks = forceTripleChecks;
- }
-
- public boolean evaluate( final Action action )
- {
- switch (action)
- {
- case Read:
- return read;
- case Create:
- return create;
- case Update:
- return update;
- case Delete:
- return delete;
- default:
- throw new IllegalArgumentException();
- }
- }
-
- /**
- * Answers the question. can the logged in user perform action on the
- * object.
- *
- * if there is no logged in user then anonymous access is assumed.
- *
- * @param action
- * @param object
- * @return boolean
- */
- public boolean evaluate( final Action action, final Resource object )
- {
-
- return evaluate(action);
- }
-
- @Override
- public boolean evaluate( final Object principal, final Action action, final SecNode uri )
- {
- return evaluate(action);
- }
-
- @Override
- public boolean evaluate( final Object principal, final Action action, final SecNode graphIRI,
- final SecTriple triple )
- {
- if (forceTripleChecks)
- {
- if (triple.getSubject().equals(SecNode.ANY)
- || triple.getPredicate().equals(SecNode.ANY)
- || triple.getObject().equals(SecNode.ANY))
- {
- return false;
- }
- }
- return evaluate(action);
- }
-
- public boolean evaluate( final Action[] actions )
- {
- for (final Action a : actions)
- {
- if (!evaluate(a))
- {
- return false;
- }
- }
- return true;
- }
-
- public boolean evaluate( final Set<Action> action )
- {
- boolean result = true;
- for (final Action a : action)
- {
- result &= evaluate(a);
- }
- return result;
- }
-
- public boolean evaluate( final Set<Action> action, final Resource object )
- {
- boolean result = true;
- for (final Action a : action)
- {
- result &= evaluate(a);
- }
- return result;
- }
-
- @Override
- public boolean evaluate( final Object principal, final Set<Action> action, final SecNode uri )
- {
- return evaluate(action);
- }
-
- @Override
- public boolean evaluate( final Object principal, final Set<Action> action, final SecNode graphIRI,
- final SecTriple triple )
- {
- for (final Action a : action)
- {
- if (!evaluate(a))
- {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public boolean evaluateAny( final Object principal, final Set<Action> action, final SecNode graphIRI )
- {
- for (final Action a : action)
- {
- if (evaluate(a))
- {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean evaluateAny( final Object principal, final Set<Action> action,
- final SecNode graphIRI, final SecTriple triple )
- {
- return evaluateAny( principal, action, graphIRI);
- }
-
- @Override
- public boolean evaluateUpdate( final Object principal, final SecNode graphIRI,
- final SecTriple from, final SecTriple to )
- {
- return evaluate(Action.Update);
- }
-
- public Set<Action> getPermissions( final Resource resourceID )
- {
- return Collections.emptySet();
- }
-
- public Set<Action> getPermissions( final SecNode uri )
- {
- return Collections.emptySet();
- }
-
- @Override
- public Principal getPrincipal()
- {
- if (loggedIn)
- {
- return new Principal() {
-
- @Override
- public String getName()
- {
- return "TestingPrincipal";
- }
- };
- }
- return null;
- }
-
- public boolean isLoggedIn()
- {
- return loggedIn;
- }
-
- @Override
- public String toString()
- {
- return String.format("C:%s R:%s U:%s D:%s force:%s", create, read,
- update, delete, forceTripleChecks);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/ModelBasedSecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/ModelBasedSecurityEvaluator.java b/jena-permissions/src/test/java/org/apache/jena/security/ModelBasedSecurityEvaluator.java
deleted file mode 100644
index 0efc9be..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/ModelBasedSecurityEvaluator.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security;
-
-import java.util.Set;
-
-import org.apache.jena.rdf.model.Model ;
-
-public class ModelBasedSecurityEvaluator implements SecurityEvaluator {
-
- //private Model model;
-
- public ModelBasedSecurityEvaluator( Model model) {
- //this.model = model;
- }
-
-
-
- @Override
- public boolean evaluate(final Object principal, Action action, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluate(final Object principal, Action action, SecNode graphIRI, SecTriple triple) {
- return true;
- }
-
- @Override
- public boolean evaluate(final Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluate(final Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return true;
- }
-
- @Override
- public boolean evaluateAny(final Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluateAny(final Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return true;
- }
-
- @Override
- public boolean evaluateUpdate(final Object principal, SecNode graphIRI, SecTriple from, SecTriple to) {
- return true;
- }
-
- @Override
- public Object getPrincipal() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/SecuredAssemblerTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/SecuredAssemblerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/SecuredAssemblerTest.java
deleted file mode 100644
index 697c5f6..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/SecuredAssemblerTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security;
-
-import java.net.URL;
-
-import org.junit.Assert;
-import org.apache.jena.assembler.Assembler ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.ModelFactory ;
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.security.model.SecuredModel;
-import org.junit.Before;
-import org.junit.Test;
-
-public class SecuredAssemblerTest
-{
- private Assembler assembler;
- private Model model;
-
- public SecuredAssemblerTest()
- {
- assembler = Assembler.general;
- }
-
- @Before
- public void setUp() throws Exception {
- model = ModelFactory.createDefaultModel();
- URL url = SecuredAssemblerTest.class.getClassLoader().getResource( SecuredAssemblerTest.class.getName().replace(".", "/")+".ttl");
- model.read( url.toURI().toString(), "TURTLE" );
- //model.write( System.out, "TURTLE" );
- }
-
- @Test
- public void testCreation() throws Exception {
-
- Resource r = model.createResource( "http://apache.org/jena/security/test#secModel");
- Object o = assembler.open( r );
- Assert.assertTrue( o instanceof Model);
- Assert.assertTrue( o instanceof SecuredModel );
- }
-
- @Test
- public void testCreationWithArgs() throws Exception {
-
- Resource r = model.createResource( "http://apache.org/jena/security/test#secModel2");
- Object o = assembler.open( r );
- Assert.assertTrue( o instanceof Model);
- Assert.assertTrue( o instanceof SecuredModel );
- }
-
- @Test
- public void testSecurityEvaluatorWithStringArgs() throws Exception {
-
- Resource r = model.createResource( "http://apache.org/jena/security/test#secEvaluator");
- Object o = assembler.open( r );
- Assert.assertTrue( o instanceof SecurityEvaluator );
- Assert.assertTrue( o instanceof StaticSecurityEvaluator );
- }
-
- @Test
- public void testSecurityEvaluatorWithModelArgs() throws Exception {
-
- Resource r = model.createResource( "http://apache.org/jena/security/test#secEvaluator2");
- Object o = assembler.open( r );
- Assert.assertTrue( o instanceof SecurityEvaluator );
- Assert.assertTrue( o instanceof ModelBasedSecurityEvaluator );
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/SecurityEvaluatorParameters.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/SecurityEvaluatorParameters.java b/jena-permissions/src/test/java/org/apache/jena/security/SecurityEvaluatorParameters.java
deleted file mode 100644
index d6de485..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/SecurityEvaluatorParameters.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security;
-
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.junit.runner.Runner;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.Suite;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.InitializationError;
-import org.junit.runners.model.Statement;
-
-public class SecurityEvaluatorParameters extends Suite
-{
-
- private class TestClassRunnerForParameters extends BlockJUnit4ClassRunner
- {
- private final int fParameterSetNumber;
-
- private final List<Object[]> fParameterList;
-
- TestClassRunnerForParameters( final Class<?> type,
- final List<Object[]> parameterList, final int i )
- throws InitializationError
- {
- super(type);
- fParameterList = parameterList;
- fParameterSetNumber = i;
- }
-
- @Override
- protected Statement classBlock( final RunNotifier notifier )
- {
- return childrenInvoker(notifier);
- }
-
- @Override
- public Object createTest() throws Exception
- {
- return getTestClass().getOnlyConstructor().newInstance(
- fParameterList.get(fParameterSetNumber));
- }
-
- @Override
- protected String getName()
- {
- return String.format("[%s]", fParameterSetNumber);
- }
-
- @Override
- protected Annotation[] getRunnerAnnotations()
- {
- return new Annotation[0];
- }
-
- @Override
- protected String testName( final FrameworkMethod method )
- {
- return String.format("%s[%s]", method.getName(),
- fParameterList.get(fParameterSetNumber)[0]);
- }
-
- @Override
- protected void validateConstructor( final List<Throwable> errors )
- {
- validateOnlyOneConstructor(errors);
- }
- }
-
- private final ArrayList<Runner> runners = new ArrayList<Runner>();
-
- /**
- * Only called reflectively. Do not use programmatically.
- */
- public SecurityEvaluatorParameters( final Class<?> klass ) throws Throwable
- {
- super(klass, Collections.<Runner> emptyList());
- final List<Object[]> parametersList = new ArrayList<Object[]>();
-
- final boolean[] bSet = { true, false };
-
- for (final boolean create : bSet)
- {
- for (final boolean read : bSet)
- {
- for (final boolean update : bSet)
- {
- for (final boolean delete : bSet)
- {
- for (final boolean forceTripleCheck : bSet)
- {
- parametersList
- .add(new Object[] { new MockSecurityEvaluator(
- true, create, read, update, delete,
- forceTripleCheck) });
- }
- }
- }
- }
- }
-
- for (int i = 0; i < parametersList.size(); i++)
- {
- runners.add(new TestClassRunnerForParameters(getTestClass()
- .getJavaClass(), parametersList, i));
- }
- }
-
- @Override
- protected List<Runner> getChildren()
- {
- return runners;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/StaticSecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/StaticSecurityEvaluator.java b/jena-permissions/src/test/java/org/apache/jena/security/StaticSecurityEvaluator.java
deleted file mode 100644
index d59b89c..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/StaticSecurityEvaluator.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security;
-
-import java.util.Set;
-
-public class StaticSecurityEvaluator implements SecurityEvaluator {
-
- private String user;
-
- public StaticSecurityEvaluator( String user) {
- this.user = user;
- }
-
- public void setUser( String user )
- {
- this.user = user;
- }
-
- @Override
- public boolean evaluate(final Object principal, Action action, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluate(final Object principal, Action action, SecNode graphIRI, SecTriple triple) {
- return triple.getSubject().getValue().equals( "urn:"+principal );
- }
-
- @Override
- public boolean evaluate(final Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluate(final Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return triple.getSubject().getValue().equals( "urn:"+principal );
- }
-
- @Override
- public boolean evaluateAny(final Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluateAny(final Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return triple.getSubject().getValue().equals( "urn:"+principal );
- }
-
- @Override
- public boolean evaluateUpdate(final Object principal, SecNode graphIRI, SecTriple from, SecTriple to) {
- return from.getSubject().getValue().equals( "urn:"+principal ) &&
- to.getSubject().getValue().equals( "urn:"+principal );
- }
-
- @Override
- public Object getPrincipal() {
- return user;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/CachedSecurityEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/CachedSecurityEvaluatorTest.java b/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/CachedSecurityEvaluatorTest.java
deleted file mode 100644
index 6201b5c..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/CachedSecurityEvaluatorTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.security.contract.graph;
-
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.StaticSecurityEvaluator;
-import org.apache.jena.security.impl.CachedSecurityEvaluator;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-public class CachedSecurityEvaluatorTest {
-
- private StaticSecurityEvaluator securityEvaluator;
- private SecurityEvaluator cachedEvaluator;
-
- public CachedSecurityEvaluatorTest() {
- securityEvaluator = new StaticSecurityEvaluator( "bob" );
- cachedEvaluator = new CachedSecurityEvaluator( securityEvaluator, "ted" );
-
- }
-
- @Test
- public void testGetPrincipal()
- {
- assertEquals( "bob", securityEvaluator.getPrincipal());
- assertEquals( "ted", cachedEvaluator.getPrincipal());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphContractTests.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphContractTests.java b/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphContractTests.java
deleted file mode 100644
index e903d75..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphContractTests.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security.contract.graph;
-
-import org.apache.jena.graph.Factory ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.test.MetaTestGraph ;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-
-public class SecuredGraphContractTests extends MetaTestGraph
-{
-
- private final SecurityEvaluator eval;
-
- public SecuredGraphContractTests( final Class<? extends Graph> graphClass,
- final String name )
- {
- super(graphClass, name);
- eval = new MockSecurityEvaluator(true, true, true, true, true, true);
- }
-
- public SecuredGraphContractTests( final String name )
- {
- super(name);
- eval = new MockSecurityEvaluator(true, true, true, true, true, true);
- }
-
- @Override
- public Graph getGraph()
- {
- return org.apache.jena.security.Factory.getInstance(eval, getName(),
- Factory.createDefaultGraph());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphListenerTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphListenerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphListenerTest.java
deleted file mode 100644
index fb7f805..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphListenerTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security.contract.graph;
-
-import org.apache.jena.graph.Factory ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.test.TestGraphListener ;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-
-public class SecuredGraphListenerTest extends TestGraphListener
-{
- private final SecurityEvaluator eval;
-
- public SecuredGraphListenerTest( final Class<? extends Graph> graphClass,
- final String name )
- {
- super(graphClass, name);
- eval = new MockSecurityEvaluator(true, true, true, true, true, true);
- }
-
- public SecuredGraphListenerTest( final String name )
- {
- super(name);
- eval = new MockSecurityEvaluator(true, true, true, true, true, true);
- }
-
- @Override
- public Graph getGraph()
- {
- final Graph graph = org.apache.jena.security.Factory.getInstance(eval,
- getName(), Factory.createDefaultGraph());
- graph.getEventManager().register(new CheckChanges("simple tracking", graph));
- return graph;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredTDBGraphContractTests.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredTDBGraphContractTests.java b/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredTDBGraphContractTests.java
deleted file mode 100644
index 6991ea8..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredTDBGraphContractTests.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security.contract.graph;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.test.MetaTestGraph ;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.tdb.TDBFactory ;
-
-public class SecuredTDBGraphContractTests extends MetaTestGraph
-{
-
- private final SecurityEvaluator eval;
-
- public SecuredTDBGraphContractTests( final Class<? extends Graph> graphClass,
- final String name )
- {
- super(graphClass, name);
- eval = new MockSecurityEvaluator(true, true, true, true, true, true);
- }
-
- public SecuredTDBGraphContractTests( final String name )
- {
- super(name);
- eval = new MockSecurityEvaluator(true, true, true, true, true, true);
- }
-
- @Override
- public Graph getGraph()
- {
- return org.apache.jena.security.Factory.getInstance(eval, getName(),
- TDBFactory.createDatasetGraph().getDefaultGraph());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/contract/model/ModelTestSuite.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/ModelTestSuite.java b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/ModelTestSuite.java
deleted file mode 100644
index e3d33e5..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/ModelTestSuite.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security.contract.model;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-
-import junit.framework.Test;
-
-
-import org.junit.runner.Description;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.ParentRunner;
-
-
-public class ModelTestSuite extends ParentRunner<Test>
-{
- private SecTestPackage pkg;
-
- public ModelTestSuite( Class<?> testClass ) throws Exception
- {
- super( Test.class );
- pkg = new SecTestPackage();
- }
-
- @Override
- protected List<Test> getChildren()
- {
- List<Test> lst = new ArrayList<Test>();
- Enumeration<Test> enm = pkg.tests();
- while (enm.hasMoreElements())
- {
- lst.add( enm.nextElement() );
- }
- return lst;
- }
-
- @Override
- protected Description describeChild( Test child )
- {
- return Description.createTestDescription( child.getClass(), child.toString() );
- }
-
- @Override
- protected void runChild( Test child, RunNotifier notifier )
- {
- Method setUp = null;
- try
- {
- setUp = child.getClass().getMethod("setUp" );
- }
- catch (SecurityException e1)
- {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- throw new RuntimeException( e1 );
- }
- catch (NoSuchMethodException e1)
- {
- }
- Method tearDown = null;
- try
- {
- tearDown = child.getClass().getMethod("tearDown" );
- }
- catch (SecurityException e1)
- {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- throw new RuntimeException( e1 );
- }
- catch (NoSuchMethodException e1)
- {
- }
- for (Method m : child.getClass().getMethods())
- {
- if (m.getName().startsWith( "test" ) && m.getParameterTypes().length == 0)
- {
- Description desc = Description.createTestDescription( child.getClass(), child.toString() );
- notifier.fireTestStarted( desc );
- try
- {
- if (setUp != null)
- {
- setUp.invoke(child);
- }
- m.invoke(child);
- if (tearDown != null)
- {
- tearDown.invoke( child );
- }
- notifier.fireTestFinished( desc );
- }
- catch (IllegalArgumentException e)
- {
- notifier.fireTestFailure( new Failure(desc, e));
- }
- catch (IllegalAccessException e)
- {
- notifier.fireTestFailure( new Failure(desc, e));
- }
- catch (InvocationTargetException e)
- {
- notifier.fireTestFailure( new Failure(desc, e.getTargetException()));
- }
- catch (RuntimeException e) {
- notifier.fireTestFailure( new Failure(desc, e));
- throw e;
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestLiterals.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestLiterals.java b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestLiterals.java
deleted file mode 100644
index 6247c68..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestLiterals.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security.contract.model;
-
-import org.apache.jena.rdf.model.test.TestLiterals ;
-import org.apache.jena.rdf.model.test.TestPackage ;
-
-public class SecTestLiterals extends TestLiterals {
-
- public SecTestLiterals() {
- super(new TestPackage.PlainModelFactory(), "SecTestLiterals");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestPackage.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestPackage.java b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestPackage.java
deleted file mode 100644
index 4f0650d..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestPackage.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security.contract.model;
-
-import java.lang.reflect.InvocationTargetException;
-
-import junit.framework.TestSuite;
-import org.apache.jena.atlas.web.TypedInputStream;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.ModelFactory ;
-import org.apache.jena.rdf.model.test.AbstractTestPackage ;
-import org.apache.jena.rdf.model.test.helpers.TestingModelFactory ;
-import org.apache.jena.riot.system.stream.Locator;
-import org.apache.jena.riot.system.stream.StreamManager;
-import org.apache.jena.riot.system.stream.LocatorZip;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.util.FileUtils ;
-
-/**
- * Test package to test Model implementation.
- */
-//@RunWith(ModelTestSuite.class)
-public class SecTestPackage extends AbstractTestPackage
-{
- static public TestSuite suite() throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
- {
- return new SecTestPackage();
- }
-
- public SecTestPackage() throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
- {
- super("SecuredModel", new PlainModelFactory() );
- // register a jar reader here
- StreamManager sm =StreamManager.get();
- sm.addLocator( new LocatorJarURL() );
- }
-
- /* package private */static class PlainModelFactory implements TestingModelFactory
- {
- private final SecurityEvaluator eval;
-
- public PlainModelFactory()
- {
- eval = new MockSecurityEvaluator(true, true, true, true, true, true);
- }
-
- @Override
- public Model createModel()
- {
- // Graph graph = Factory.createDefaultGraph( style );
- final Model model = ModelFactory.createDefaultModel();
- return org.apache.jena.security.Factory.getInstance(eval, "testModel",
- model);
- }
-
- @Override
- public PrefixMapping getPrefixMapping()
- {
- return createModel().getGraph().getPrefixMapping();
- }
-
- @Override
- public Model createModel( Graph base )
- {
- return ModelFactory.createModelForGraph(base);
- }
- }
-
- public static class LocatorJarURL implements Locator {
-
- @Override
- public TypedInputStream open(String uri) {
- String uriSchemeName = FileUtils.getScheme(uri) ;
- if ( ! "jar".equalsIgnoreCase(uriSchemeName))
- {
- return null;
- }
-
- String[] parts = uri.substring( 4 ).split("!");
- if (parts.length != 2)
- {
- return null;
- }
- if (parts[0].toLowerCase().startsWith("file:"))
- {
- parts[0] = parts[0].substring( 5 );
- }
- if (parts[1].startsWith( "/"))
- {
- parts[1] = parts[1].substring(1);
- }
- LocatorZip zl = new LocatorZip( parts[0] );
- return zl.open(parts[1] );
- }
-
- @Override
- public String getName() {
- return "JarURLLocator";
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaderEvents.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaderEvents.java b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaderEvents.java
deleted file mode 100644
index 4a1d662..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaderEvents.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security.contract.model;
-
-import org.apache.jena.rdf.model.test.TestPackage ;
-
-public class SecTestReaderEvents extends org.apache.jena.rdf.model.test.TestReaderEvents {
-
- public SecTestReaderEvents() {
- super( new TestPackage.PlainModelFactory(), "SecTestReaderEvents" );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaders.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaders.java b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaders.java
deleted file mode 100644
index 7ee29fe..0000000
--- a/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaders.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jena.security.contract.model;
-
-import org.apache.jena.rdf.model.test.TestPackage ;
-
-public class SecTestReaders extends org.apache.jena.rdf.model.test.TestReaders {
-
- public SecTestReaders() {
- super( new TestPackage.PlainModelFactory(), "SecTestReaders" );
- }
-
-}