You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/04/24 14:19:59 UTC
[01/24] jena git commit: Module jena-seurity becomes jena-permissions
Repository: jena
Updated Branches:
refs/heads/jena3 93570e5bc -> b712fb285
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 81ffef7..6495b7a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,7 +74,7 @@
<!--<module>jena-fuseki1</module>-->
<module>jena-fuseki2</module>
- <!-- <module>jena-security</module> Lots of output and warnings -->
+ <!-- <module>jena-permissions</module> Lots of output and warnings -->
<!-- Slow to build - exclude from dev build -->
<!-- <module>jena-jdbc</module> -->
@@ -118,7 +118,7 @@
<module>jena-fuseki1</module>
<module>jena-fuseki2</module>
- <module>jena-security</module>
+ <module>jena-permissions</module>
<module>jena-jdbc</module>
<!-- Jena3 note:
[22/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/package-info.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/package-info.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/package-info.java
new file mode 100644
index 0000000..d787688
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/package-info.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+/**
+ * Secured implementation of the Graph interface and associated classes.
+ * <p>
+ *
+ * The SecurityEvaluator class must be implemented. This class provides the interface to the
+ * authentication results (e.g. getPrincipal())) and the authorization system.
+ * </p><p>
+ * Create a SecuredGraph by calling Factory.getInstance( SecurityEvaluator, String, Graph );
+ * Create a SecuredModel by calling Factory.getInstance( SecurityEvaluator, String, Model )
+ * or ModelFactory.createModelForGraph( SecuredGraph );
+ * </p><p>
+ * NOTE: when creating a model by wrapping a secured graph (e.g.
+ * ModelFactory.createModelForGraph( SecuredGraph );) the resulting Model does not
+ * have the same security requirements that the standard secured model does.
+ * </p><p>
+ * For instance when creating a list on a secured model calling model.createList( RDFNode[] );
+ * The standard secured model verifies that the user
+ * has the right to update the triples and allows or denies the entire operation accordingly.
+ * The wrapped secured graph does not have visibility
+ * to the createList() command and can only operate on the instructions issued by the
+ * model.createList() implementation. In the standard implementation
+ * the model requests the graph to delete one triple and then insert another.
+ * Thus the user must have delete and add permissions, not the update permission.
+ * </p><p>
+ * There are several other cases where the difference in the layer can trip up the security system.
+ * In all known cases the result is a tighter
+ * security definition than was requested. For simplicity sake we recommend that the wrapped
+ * secured graph only be used in cases where access to the
+ * graph as a whole is granted/denied. In these cases the user either has all CRUD capabilities or
+ * none.
+ * </p>
+ */
+package org.apache.jena.security.graph;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/impl/CachedSecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/impl/CachedSecurityEvaluator.java b/jena-permissions/src/main/java/org/apache/jena/security/impl/CachedSecurityEvaluator.java
new file mode 100644
index 0000000..ffc2868
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/impl/CachedSecurityEvaluator.java
@@ -0,0 +1,90 @@
+/*
+ * 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.impl;
+
+import java.util.Set;
+
+import org.apache.jena.security.SecurityEvaluator;
+
+/**
+ * A SecurityEvaluator that can be cached for later use.
+ */
+public class CachedSecurityEvaluator implements SecurityEvaluator {
+ private final SecurityEvaluator wrapped;
+ private final Object origPrincipal;
+
+ /**
+ *
+ * @param wrapped
+ * @param runAs
+ */
+ public CachedSecurityEvaluator(final SecurityEvaluator wrapped,
+ final Object runAs) {
+ this.origPrincipal = runAs;
+ this.wrapped = wrapped;
+ }
+
+ @Override
+ public boolean evaluate(final Object principal, final Action action,
+ final SecNode graphIRI) {
+ return wrapped.evaluate(principal, action, graphIRI);
+ }
+
+ @Override
+ public boolean evaluate(final Object principal, final Action action,
+ final SecNode graphIRI, final SecTriple triple) {
+ return wrapped.evaluate(principal, action, graphIRI, triple);
+ }
+
+ @Override
+ public boolean evaluate(final Object principal, final Set<Action> actions,
+ final SecNode graphIRI) {
+ return wrapped.evaluate(principal, actions, graphIRI);
+ }
+
+ @Override
+ public boolean evaluate(final Object principal, final Set<Action> actions,
+ final SecNode graphIRI, final SecTriple triple) {
+ return wrapped.evaluate(principal, actions, graphIRI, triple);
+ }
+
+ @Override
+ public boolean evaluateAny(final Object principal,
+ final Set<Action> actions, final SecNode graphIRI) {
+ return wrapped.evaluateAny(principal, actions, graphIRI);
+ }
+
+ @Override
+ public boolean evaluateAny(final Object principal,
+ final Set<Action> actions, final SecNode graphIRI,
+ final SecTriple triple) {
+ return wrapped.evaluateAny(principal, actions, graphIRI, triple);
+ }
+
+ @Override
+ public boolean evaluateUpdate(final Object principal,
+ final SecNode graphIRI, final SecTriple from, final SecTriple to) {
+ return wrapped.evaluateUpdate(principal, graphIRI, from, to);
+ }
+
+ @Override
+ public Object getPrincipal() {
+ return origPrincipal;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/impl/ItemHolder.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/impl/ItemHolder.java b/jena-permissions/src/main/java/org/apache/jena/security/impl/ItemHolder.java
new file mode 100644
index 0000000..0262001
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/impl/ItemHolder.java
@@ -0,0 +1,117 @@
+/*
+ * 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.impl;
+
+import java.lang.reflect.Proxy;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ClassUtils;
+
+/**
+ * A class that holds the original item and the secured version of it.
+ *
+ * This class is used by the Invoker to return secured versions of the object
+ * during
+ * calls that return the called class for cascading.
+ *
+ * @param <Base>
+ * The base class that is being secured
+ * @param <Secured>
+ * The implementation (proxy) of the secured class.
+ */
+public class ItemHolder<Base, Secured extends SecuredItem>
+{
+ /**
+ * The base item that is being secured
+ */
+ private final Base baseItem;
+ /**
+ * The proxy to the base class that implements the security.
+ */
+ private Secured securedItem;
+
+ /**
+ * Constructor.
+ *
+ * @param baseItem
+ * The base item.
+ */
+ public ItemHolder( final Base baseItem )
+ {
+ super();
+ this.baseItem = baseItem;
+ }
+
+ /**
+ * Get the base item.
+ *
+ * This method is used in the proxy to get call to the underlying instance.
+ *
+ * @return The instance that is being protected.
+ */
+ public Base getBaseItem()
+ {
+ return baseItem;
+ }
+
+ /**
+ * Get the secured item.
+ *
+ * This method is used in the invocation handler to get the instance of the
+ * proxy that made the
+ * on which a method call was made. Generally used in returing the original
+ * object to support
+ * cascading.
+ *
+ * @return the proxy.
+ */
+ public Secured getSecuredItem()
+ {
+ return securedItem;
+ }
+
+ /**
+ * Creates the proxy, saves it as the securedItem and returns it.
+ *
+ * @param handler
+ * The SecuredItemInvoker to create the proxy with.
+ * @return The proxy.
+ */
+ @SuppressWarnings( "unchecked" )
+ public final Secured setSecuredItem( final SecuredItemInvoker handler )
+ {
+ final Set<Class<?>> ifac = new LinkedHashSet<Class<?>>();
+ if (baseItem.getClass().isInterface())
+ {
+ ifac.add(baseItem.getClass());
+ }
+ ifac.addAll(ClassUtils.getAllInterfaces(baseItem.getClass()));
+ if (handler.securedItem.getClass().isInterface())
+ {
+ ifac.add(handler.securedItem.getClass());
+ }
+ ifac.addAll(ClassUtils.getAllInterfaces(handler.securedItem.getClass()));
+
+ securedItem = (Secured) Proxy.newProxyInstance(
+ SecuredItemImpl.class.getClassLoader(),
+ ifac.toArray(new Class<?>[ifac.size()]), handler);
+ return securedItem;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItem.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItem.java b/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItem.java
new file mode 100644
index 0000000..7c12d19
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItem.java
@@ -0,0 +1,185 @@
+/*
+ * 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.impl;
+
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.SecurityEvaluator.SecTriple;
+
+/**
+ * The secured item interface is mixed into instances of secured objects by the
+ * proxy. It provides the security context for the security checks as well as
+ * several useful shorthand methods for common checks.
+ */
+public interface SecuredItem
+{
+
+ /**
+ * Utilities for SecuredItem implementations.
+ */
+ public static class Util
+ {
+ /**
+ * Secured items are equivalent if their security evaluators and
+ * modelIRIs are equal.
+ *
+ * @param si1
+ * A secured item to check
+ * @param si2
+ * A second secured item to check
+ * @return true if si1 is equivalent to si2.
+ */
+ public static boolean isEquivalent( final SecuredItem si1,
+ final SecuredItem si2 )
+ {
+ return si1.getSecurityEvaluator()
+ .equals(si2.getSecurityEvaluator())
+ && si1.getModelIRI().equals(si2.getModelIRI());
+ }
+ }
+
+ /**
+ * @return true if the securedModel allows items to to be created.
+ */
+ public boolean canCreate();
+
+ /**
+ * Return true if the triple can be created.
+ * If any s,p or o is SecNode.ANY then this method must return false if
+ * there
+ * are
+ * any restrictions where the remaining nodes and held constant and the ANY
+ * node
+ * is allowed to vary.
+ *
+ * See canRead(SecTriple t)
+ *
+ * @param t
+ * The triple to check
+ * @return true if the triple can be created.
+ */
+ public boolean canCreate( SecTriple t );
+
+ /**
+ * @return true if the securedModel allows items to to be deleted.
+ */
+ public boolean canDelete();
+
+ /**
+ * Return true if the triple can be deleted.
+ * If any s,p or o is SecNode.ANY then this method must return false if
+ * there
+ * are
+ * any restrictions where the remaining nodes and held constant and the ANY
+ * node
+ * is allowed to vary.
+ *
+ * See canRead(SecTriple t)
+ *
+ * @param t
+ * The triple to check
+ * @return true if the triple can be deleted.
+ */
+ public boolean canDelete( SecTriple t );
+
+ /**
+ * @return true if the securedModel allows items to to be read.
+ */
+ public boolean canRead();
+
+ /**
+ * Return true if the triple can be read.
+ * If any s,p or o is SecNode.ANY then this method must return false if
+ * there
+ * are
+ * any restrictions where the remaining nodes and held constant and the ANY
+ * node
+ * is allowed to vary.
+ *
+ * (S, P, O) check if S,P,O can be read.
+ * (S, P, ANY) check if there are any S,P,x restrictions.
+ * (S, ANY, P) check if there are any S,x,P restrictions.
+ * (ANY, ANY, ANY) check if there are any restricitons on reading.
+ *
+ * @param t
+ * The triple to check
+ * @return true if the triple can be read.
+ */
+ public boolean canRead( SecTriple t );
+
+ /**
+ * @return true if the securedModel allows items to to be updated.
+ */
+ public boolean canUpdate();
+
+ /**
+ * Return true if the triple can be updated.
+ * If any s,p or o is SecNode.ANY then this method must return false if
+ * there
+ * are
+ * any restrictions where the remaining nodes and held constant and the ANY
+ * node
+ * is allowed to vary.
+ *
+ * See canRead(SecTriple t)
+ *
+ * @param from
+ * The triple that will be changed
+ * @param to
+ * The resulting triple.
+ * @return true if the from triple can be updated as the to triple.
+ */
+ public boolean canUpdate( SecTriple from, SecTriple to );
+
+ @Override
+ public boolean equals( Object o );
+
+ /**
+ * @return the base item that is being secured.
+ */
+ public Object getBaseItem();
+
+ /**
+ * @return The IRI of the securedModel that the item belongs to.
+ */
+ public String getModelIRI();
+
+ /**
+ * @return The node represnetation of the securedModel IRI.
+ */
+ public SecNode getModelNode();
+
+ /**
+ * The SecurityEvaluator implementation that is being used to determine
+ * access.
+ *
+ * @return The SecurityEvaluator implementation.
+ */
+ public SecurityEvaluator getSecurityEvaluator();
+
+ /**
+ * Return true if this secured item is equivalent to another secured item.
+ * Generally implemented by calling SecuredItem.Util.isEquivalent
+ *
+ * @param securedItem
+ * the other secured item.
+ * @return True if they are equivalent, false otherwise.
+ */
+ public boolean isEquivalent( SecuredItem securedItem );
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItemImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItemImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItemImpl.java
new file mode 100644
index 0000000..e24cfb8
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItemImpl.java
@@ -0,0 +1,842 @@
+/*
+ * 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.impl;
+
+import java.lang.reflect.Proxy;
+
+import org.apache.commons.collections4.map.LRUMap;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.jena.rdf.model.Statement ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.SecurityEvaluator.SecTriple;
+import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.vocabulary.RDF ;
+
+/**
+ * An abstract implementation of SecuredItem that caches security checks.
+ * <p>
+ * Security checks are performed at multiple locations. This implementation ensures that
+ * during a single operation the specific check is only evaluated once by caching the result.
+ * </p>
+ *
+ */
+public abstract class SecuredItemImpl implements SecuredItem
+{
+ // a key for the secured item.
+ private class CacheKey implements Comparable<CacheKey>
+ {
+ private final Action action;
+ private final SecNode modelNode;
+ private final SecTriple from;
+ private final SecTriple to;
+ private Integer hashCode;
+
+ public CacheKey( final Action action, final SecNode modelNode )
+ {
+ this(action, modelNode, null, null);
+ }
+
+ public CacheKey( final Action action, final SecNode modelNode,
+ final SecTriple to )
+ {
+ this(action, modelNode, to, null);
+ }
+
+ public CacheKey( final Action action, final SecNode modelNode,
+ final SecTriple to, final SecTriple from )
+ {
+ this.action = action;
+ this.modelNode = modelNode;
+ this.to = to;
+ this.from = from;
+ }
+
+ @Override
+ public int compareTo( final CacheKey other )
+ {
+ int retval = this.action.compareTo(other.action);
+ if (retval == 0)
+ {
+ retval = this.modelNode.compareTo(other.modelNode);
+ }
+ if (retval == 0)
+ {
+ if (this.to == null)
+ {
+ if (other.to == null)
+ {
+ return 0;
+ }
+ return -1;
+ }
+ retval = this.to.compareTo(other.to);
+ }
+ if (retval == 0)
+ {
+ if (this.from == null)
+ {
+ if (other.from == null)
+ {
+ return 0;
+ }
+ return -1;
+ }
+ retval = this.from.compareTo(other.from);
+ }
+ return retval;
+ }
+
+ @Override
+ public boolean equals( final Object o )
+ {
+ if (o instanceof CacheKey)
+ {
+ return this.compareTo((CacheKey) o) == 0;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ if (hashCode == null)
+ {
+ hashCode = new HashCodeBuilder().append(action)
+ .append(modelNode).append(from).append(to).toHashCode();
+ }
+ return hashCode;
+ }
+ }
+
+ // the maximum size of the cache
+ public static int MAX_CACHE = 100;
+ // the cache for this thread.
+ public static final ThreadLocal<LRUMap> CACHE = new ThreadLocal<LRUMap>();
+ // the number of times this thread has recursively called the constructor.
+ public static final ThreadLocal<Integer> COUNT = new ThreadLocal<Integer>();
+
+ /**
+ * Convert a Jena Node object into a SecNode object.
+ * @param jenaNode The Jena node to convert.
+ * @return The SecNode that represents the jenaNode.
+ */
+ public static SecNode convert( final org.apache.jena.graph.Node jenaNode )
+ {
+ if (org.apache.jena.graph.Node.ANY.equals(jenaNode))
+ {
+ return SecNode.ANY;
+ }
+ if (jenaNode.isLiteral())
+ {
+ return new SecNode(Type.Literal, jenaNode.getLiteral().toString());
+ }
+ if (jenaNode.isBlank())
+ {
+ return new SecNode(Type.Anonymous, jenaNode.getBlankNodeLabel());
+ }
+ if (jenaNode.isVariable())
+ {
+ return SecNode.VARIABLE;
+ }
+ return new SecNode(Type.URI, jenaNode.getURI());
+ }
+
+ /**
+ * Convert a Jena Triple into a SecTriple.
+ * @param jenaTriple The Jena Triple to convert.
+ * @return The SecTriple that represents the jenaTriple.
+ */
+ public static SecTriple convert(
+ final org.apache.jena.graph.Triple jenaTriple )
+ {
+ return new SecTriple(SecuredItemImpl.convert(jenaTriple.getSubject()),
+ SecuredItemImpl.convert(jenaTriple.getPredicate()),
+ SecuredItemImpl.convert(jenaTriple.getObject()));
+ }
+
+ /**
+ * Decrement the number of instances of SecuredItem.
+ */
+ public static void decrementUse()
+ {
+ final Integer i = SecuredItemImpl.COUNT.get();
+ if (i == null)
+ {
+ throw new IllegalStateException("No count on exit");
+ }
+ if (i < 1)
+ {
+ throw new IllegalStateException("No count less than 1");
+ }
+ if (i == 1)
+ {
+ SecuredItemImpl.CACHE.remove();
+ SecuredItemImpl.COUNT.remove();
+ }
+ else
+ {
+ SecuredItemImpl.COUNT.set( i - 1 );
+ }
+ }
+
+ /**
+ * Increment the number of instances of SecuredItem.
+ */
+ public static void incrementUse()
+ {
+ final Integer i = SecuredItemImpl.COUNT.get();
+ if (i == null)
+ {
+ SecuredItemImpl.CACHE.set(new LRUMap(Math.max(
+ SecuredItemImpl.MAX_CACHE, 100)));
+ SecuredItemImpl.COUNT.set( 1 );
+ }
+ else
+ {
+ SecuredItemImpl.COUNT.set( i + 1 );
+ }
+ }
+
+ // the evaluator we are using
+ private final SecurityEvaluator securityEvaluator;
+
+ // the secured node for that names the graph.
+ private final SecNode modelNode;
+
+ // the item holder that we are evaluating.
+ private final ItemHolder<?, ?> itemHolder;
+
+ /**
+ * Create the SecuredItemImpl.
+ * @param securedItem The securedItem.
+ * @param holder The Item holder for the securedItem.
+ * @throws IllegalArgumentException if securedItem is null or securedItem.getSecurityEvaluator()
+ * returns null, or the holder is null.
+ */
+ protected SecuredItemImpl( final SecuredItem securedItem,
+ final ItemHolder<?, ?> holder )
+ {
+ if (securedItem == null)
+ {
+ throw new IllegalArgumentException("Secured item may not be null");
+ }
+ if (securedItem.getSecurityEvaluator() == null)
+ {
+ throw new IllegalArgumentException(
+ "Security evaluator in secured item may not be null");
+ }
+ if (holder == null)
+ {
+ throw new IllegalArgumentException("ItemHolder may not be null");
+ }
+ this.securityEvaluator = securedItem.getSecurityEvaluator();
+ this.modelNode = new SecurityEvaluator.SecNode(
+ SecurityEvaluator.SecNode.Type.URI, securedItem.getModelIRI());
+ this.itemHolder = holder;
+ }
+
+ /**
+ * Create the SecuredItemImpl.
+ * @param securityEvaluator the secured evaluator to use.
+ * @param modelURI the URI for the model.
+ * @param holder The holder to use.
+ * @throws IllegalArgumentException if security evaluator is null, modelURI is null or empty,
+ * or holder is null.
+ */
+ protected SecuredItemImpl( final SecurityEvaluator securityEvaluator,
+ final String modelURI, final ItemHolder<?, ?> holder )
+ {
+ if (securityEvaluator == null)
+ {
+ throw new IllegalArgumentException(
+ "Security evaluator may not be null");
+ }
+ if (StringUtils.isEmpty(modelURI))
+ {
+ throw new IllegalArgumentException(
+ "ModelURI may not be empty or null");
+ }
+ if (holder == null)
+ {
+ throw new IllegalArgumentException("ItemHolder may not be null");
+ }
+ this.securityEvaluator = securityEvaluator;
+ this.modelNode = new SecurityEvaluator.SecNode(
+ SecurityEvaluator.SecNode.Type.URI, modelURI);
+ this.itemHolder = holder;
+ }
+
+ @Override
+ public String toString() {
+ if (canRead())
+ {
+ return itemHolder.getBaseItem().toString();
+ }
+ return super.toString();
+ }
+
+ /**
+ * get the cached value.
+ * @param key The key to look for.
+ * @return the value of the security check or <code>null</code> if the value has not been cached.
+ */
+ private Boolean cacheGet( final CacheKey key )
+ {
+ final LRUMap cache = SecuredItemImpl.CACHE.get();
+ return (cache == null) ? null : (Boolean) cache.get(key);
+ }
+
+ /**
+ * set teh cache value.
+ * @param key The key to set the value for.
+ * @param value The value to set.
+ */
+ void cachePut( final CacheKey key, final boolean value )
+ {
+ final LRUMap cache = SecuredItemImpl.CACHE.get();
+ if (cache != null)
+ {
+ cache.put(key, value);
+ SecuredItemImpl.CACHE.set(cache);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jena.security.SecuredItem#canCreate()
+ */
+ @Override
+ public boolean canCreate()
+ {
+ final CacheKey key = new CacheKey(Action.Create, modelNode);
+ Boolean retval = cacheGet(key);
+ if (retval == null)
+ {
+ retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Create, modelNode);
+ cachePut(key, retval);
+ }
+ return retval;
+ }
+
+ public boolean canCreate( final org.apache.jena.graph.Triple t )
+ {
+ return canCreate(SecuredItemImpl.convert(t));
+ }
+
+ @Override
+ public boolean canCreate( final SecTriple t )
+ {
+ final CacheKey key = new CacheKey(Action.Create, modelNode, t);
+ Boolean retval = cacheGet(key);
+ if (retval == null)
+ {
+ retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Create, modelNode, t);
+ cachePut(key, retval);
+ }
+ return retval;
+ }
+
+ public boolean canCreate( final Statement s )
+ {
+ return canCreate(s.asTriple());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jena.security.SecuredItem#canDelete()
+ */
+ @Override
+ public boolean canDelete()
+ {
+ final CacheKey key = new CacheKey(Action.Delete, modelNode);
+ Boolean retval = cacheGet(key);
+ if (retval == null)
+ {
+ retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Delete, modelNode);
+ cachePut(key, retval);
+ }
+ return retval;
+ }
+
+ public boolean canDelete( final org.apache.jena.graph.Triple t )
+ {
+ return canDelete(SecuredItemImpl.convert(t));
+ }
+
+ @Override
+ public boolean canDelete( final SecTriple t )
+ {
+ final CacheKey key = new CacheKey(Action.Delete, modelNode, t);
+ Boolean retval = cacheGet(key);
+ if (retval == null)
+ {
+ retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Delete, modelNode, t);
+ cachePut(key, retval);
+ }
+ return retval;
+ }
+
+ public boolean canDelete( final Statement s )
+ {
+ return canDelete(s.asTriple());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jena.security.SecuredItem#canRead()
+ */
+ @Override
+ public boolean canRead()
+ {
+ final CacheKey key = new CacheKey(Action.Read, modelNode);
+ Boolean retval = cacheGet(key);
+ if (retval == null)
+ {
+ retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Read, modelNode);
+ cachePut(key, retval);
+ }
+ return retval;
+ }
+
+ public boolean canRead( final org.apache.jena.graph.Triple t )
+ {
+ return canRead(SecuredItemImpl.convert(t));
+ }
+
+ @Override
+ public boolean canRead( final SecTriple t )
+ {
+ final CacheKey key = new CacheKey(Action.Read, modelNode, t);
+ Boolean retval = cacheGet(key);
+ if (retval == null)
+ {
+ retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Read, modelNode, t);
+ cachePut(key, retval);
+ }
+ return retval;
+ }
+
+ public boolean canRead( final Statement s )
+ {
+ return canRead(s.asTriple());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jena.security.SecuredItem#canUpdate()
+ */
+ @Override
+ public boolean canUpdate()
+ {
+ final CacheKey key = new CacheKey(Action.Update, modelNode);
+ Boolean retval = cacheGet(key);
+ if (retval == null)
+ {
+ retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Update, modelNode);
+ cachePut(key, retval);
+ }
+ return retval;
+ }
+
+ public boolean canUpdate( final org.apache.jena.graph.Triple from,
+ final org.apache.jena.graph.Triple to )
+ {
+ return canUpdate(SecuredItemImpl.convert(from),
+ SecuredItemImpl.convert(to));
+ }
+
+ @Override
+ public boolean canUpdate( final SecTriple from, final SecTriple to )
+ {
+ final CacheKey key = new CacheKey(Action.Update, modelNode, from, to);
+ Boolean retval = cacheGet(key);
+ if (retval == null)
+ {
+ retval = securityEvaluator.evaluateUpdate(securityEvaluator.getPrincipal(),modelNode, from, to);
+ cachePut(key, retval);
+ }
+ return retval;
+ }
+
+ public boolean canUpdate( final Statement from, final Statement to )
+ {
+ return canUpdate(from.asTriple(), to.asTriple());
+ }
+
+ /**
+ * check that create on the securedModel is allowed,
+ *
+ * @throws AccessDeniedException
+ * on failure
+ */
+ protected void checkCreate()
+ {
+ if (!canCreate())
+ {
+ throw new AccessDeniedException(modelNode, Action.Create);
+ }
+ }
+
+ protected void checkCreate( final org.apache.jena.graph.Triple t )
+ {
+ checkCreate(SecuredItemImpl.convert(t));
+ }
+
+ /**
+ * check that the triple can be created in the securedModel.,
+ *
+ * @throws AccessDeniedException
+ * on failure
+ */
+ protected void checkCreate( final SecTriple t )
+ {
+ if (!canCreate(t))
+ {
+ throw new AccessDeniedException(modelNode, t.toString(),
+ Action.Create);
+ }
+ }
+
+ protected void checkCreate( final Statement s )
+ {
+ checkCreate(s.asTriple());
+ }
+
+ protected void checkCreateReified( final String uri, final SecTriple t )
+ {
+ checkUpdate();
+ final SecNode n = uri == null ? SecNode.FUTURE : new SecNode(Type.URI,
+ uri);
+ checkCreate(new SecTriple(n, SecuredItemImpl.convert(RDF.subject
+ .asNode()), t.getSubject()));
+ checkCreate(new SecTriple(n, SecuredItemImpl.convert(RDF.predicate
+ .asNode()), t.getPredicate()));
+ checkCreate(new SecTriple(n, SecuredItemImpl.convert(RDF.object
+ .asNode()), t.getObject()));
+ }
+
+ protected void checkCreateStatement( final ExtendedIterator<Statement> stmts )
+ {
+ if (!canCreate(SecTriple.ANY))
+ {
+ try
+ {
+ while (stmts.hasNext())
+ {
+ checkCreate(stmts.next());
+ }
+ }
+ finally
+ {
+ stmts.close();
+ }
+ }
+ }
+
+ protected void checkCreateTriples(
+ final ExtendedIterator<org.apache.jena.graph.Triple> triples )
+ {
+ if (!canCreate(SecTriple.ANY))
+ {
+ try
+ {
+ while (triples.hasNext())
+ {
+ checkCreate(triples.next());
+ }
+ }
+ finally
+ {
+ triples.close();
+ }
+ }
+ }
+
+ /**
+ * check that delete on the securedModel is allowed,
+ *
+ * @throws AccessDeniedException
+ * on failure
+ */
+ protected void checkDelete()
+ {
+ if (!canDelete())
+ {
+ throw new AccessDeniedException(modelNode, Action.Delete);
+ }
+ }
+
+ protected void checkDelete( final org.apache.jena.graph.Triple t )
+ {
+ checkDelete(SecuredItemImpl.convert(t));
+ }
+
+ /**
+ * check that the triple can be deleted in the securedModel.,
+ *
+ * @throws AccessDeniedException
+ * on failure
+ */
+ protected void checkDelete( final SecTriple t )
+ {
+ if (!canDelete(t))
+ {
+ throw new AccessDeniedException(modelNode, t.toString(),
+ Action.Delete);
+ }
+ }
+
+ protected void checkDelete( final Statement s )
+ {
+ checkDelete(s.asTriple());
+ }
+
+ protected void checkDeleteStatements(
+ final ExtendedIterator<Statement> stmts )
+ {
+ if (!canDelete(SecTriple.ANY))
+ {
+ try
+ {
+ while (stmts.hasNext())
+ {
+ checkDelete(stmts.next());
+ }
+ }
+ finally
+ {
+ stmts.close();
+ }
+ }
+ }
+
+ protected void checkDeleteTriples(
+ final ExtendedIterator<org.apache.jena.graph.Triple> triples )
+ {
+ if (!canDelete(SecTriple.ANY))
+ {
+ try
+ {
+ while (triples.hasNext())
+ {
+ checkDelete(triples.next());
+ }
+ }
+ finally
+ {
+ triples.close();
+ }
+ }
+ }
+
+ /**
+ * check that read on the securedModel is allowed,
+ *
+ * @throws AccessDeniedException
+ * on failure
+ */
+ protected void checkRead()
+ {
+ if (!canRead())
+ {
+ throw new AccessDeniedException(modelNode, Action.Read);
+ }
+ }
+
+ protected void checkRead( final org.apache.jena.graph.Triple t )
+ {
+ checkRead(SecuredItemImpl.convert(t));
+ }
+
+ /**
+ * check that the triple can be read in the securedModel.,
+ *
+ * @throws AccessDeniedException
+ * on failure
+ */
+ protected void checkRead( final SecTriple t )
+ {
+ if (!canRead(t))
+ {
+ throw new AccessDeniedException(modelNode, t.toString(),
+ Action.Read);
+ }
+ }
+
+ protected void checkRead( final Statement s )
+ {
+ checkRead(s.asTriple());
+ }
+
+ protected void checkReadStatement( final ExtendedIterator<Statement> stmts )
+ {
+ try
+ {
+ while (stmts.hasNext())
+ {
+ checkRead(stmts.next());
+ }
+ }
+ finally
+ {
+ stmts.close();
+ }
+ }
+
+ protected void checkReadTriples(
+ final ExtendedIterator<org.apache.jena.graph.Triple> triples )
+ {
+ try
+ {
+ while (triples.hasNext())
+ {
+ checkRead(triples.next());
+ }
+ }
+ finally
+ {
+ triples.close();
+ }
+ }
+
+ /**
+ * check that update on the securedModel is allowed,
+ *
+ * @throws AccessDeniedException
+ * on failure
+ */
+ protected void checkUpdate()
+ {
+ if (!canUpdate())
+ {
+ throw new AccessDeniedException(modelNode, Action.Update);
+ }
+ }
+
+ protected void checkUpdate( final org.apache.jena.graph.Triple from,
+ final org.apache.jena.graph.Triple to )
+ {
+ checkUpdate(SecuredItemImpl.convert(from), SecuredItemImpl.convert(to));
+ }
+
+ /**
+ * check that the triple can be updated in the securedModel.,
+ *
+ * @param from the starting triple
+ * @param to the final triple.
+ * @throws AccessDeniedException
+ * on failure
+ */
+ protected void checkUpdate( final SecTriple from, final SecTriple to )
+ {
+ if (!canUpdate(from, to))
+ {
+ throw new AccessDeniedException(modelNode, String.format(
+ "%s to %s", from, to), Action.Update);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jena.security.SecuredItem#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( final Object o )
+ {
+ if (Proxy.isProxyClass(o.getClass()))
+ {
+ return o.equals(itemHolder.getSecuredItem());
+ }
+ else
+ {
+ if (o instanceof SecuredItemImpl)
+ {
+ return itemHolder.getBaseItem().equals( ((SecuredItemImpl)o).getBaseItem());
+ }
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return itemHolder.getBaseItem().hashCode();
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jena.security.SecuredItem#getBaseItem()
+ */
+ @Override
+ public Object getBaseItem()
+ {
+ return itemHolder.getBaseItem();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jena.security.SecuredItem#getModelIRI()
+ */
+ @Override
+ public String getModelIRI()
+ {
+ return modelNode.getValue();
+ }
+
+ /**
+ * get the name of the model.
+ */
+ @Override
+ public SecNode getModelNode()
+ {
+ return modelNode;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jena.security.SecuredItem#getSecurityEvaluator()
+ */
+ @Override
+ public SecurityEvaluator getSecurityEvaluator()
+ {
+ return securityEvaluator;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jena.security.isEquivalent()
+ */
+ @Override
+ public boolean isEquivalent( final SecuredItem securedItem )
+ {
+ return SecuredItem.Util.isEquivalent(this, securedItem);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItemInvoker.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItemInvoker.java b/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItemInvoker.java
new file mode 100644
index 0000000..9e9149d
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/impl/SecuredItemInvoker.java
@@ -0,0 +1,146 @@
+/*
+ * 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.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
+
+
+/**
+ * A generic InvocationHandler that handles the general invocation of the
+ * security methods.
+ */
+public class SecuredItemInvoker implements InvocationHandler
+{
+ // the equals() method
+ private static Method EQUALS;
+ // the toString() method
+ private static Method TO_STRING;
+ // the hashCode() method.
+ private static Method HASH_CODE;
+ // the instance of SecuredItem that this proxy is using. Must be
+ // package-private for ItemHolder use.
+ /* package-private */final SecuredItem securedItem;
+
+ final Class<?> securedClass;
+
+ // populate the static fields.
+ static
+ {
+ try
+ {
+ SecuredItemInvoker.EQUALS = Object.class.getMethod("equals",
+ Object.class);
+ SecuredItemInvoker.TO_STRING = Object.class.getMethod("toString");
+ SecuredItemInvoker.HASH_CODE = Object.class.getMethod("hashCode");
+ }
+ catch (final SecurityException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (final NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param securedClass
+ * The class of the object that is being protected.
+ * @param securedItem
+ * The implementation of the SecuredItem version of the object.
+ */
+ public SecuredItemInvoker( final Class<?> securedClass,
+ final SecuredItem securedItem )
+ {
+ this.securedItem = securedItem;
+ this.securedClass = securedClass;
+ }
+
+ @Override
+ public Object invoke( final Object proxy, final Method method,
+ final Object[] args ) throws Throwable
+ {
+
+ // check for the special case methods
+ if (SecuredItemInvoker.EQUALS.equals(method))
+ {
+ if (Proxy.isProxyClass(args[0].getClass()))
+ {
+ return args[0].equals(securedItem);
+ }
+ else
+ {
+ return securedItem.equals(args[0]);
+ }
+ }
+
+ if (SecuredItemInvoker.HASH_CODE.equals(method))
+ {
+ return securedItem.hashCode();
+ }
+
+ if (SecuredItemInvoker.TO_STRING.equals(method))
+ {
+ return securedItem.toString();
+ }
+
+ try
+ {
+ final Method m = securedItem.getClass().getMethod(method.getName(),
+ method.getParameterTypes());
+ if (!Modifier.isAbstract(m.getModifiers()))
+ {
+ try
+ {
+ SecuredItemImpl.incrementUse();
+ try
+ {
+ return m.invoke(securedItem, args);
+ }
+ finally
+ {
+ SecuredItemImpl.decrementUse();
+ }
+
+ }
+ catch (final java.lang.reflect.InvocationTargetException e2)
+ {
+ if (e2.getTargetException() instanceof RuntimeException)
+ {
+ throw e2.getTargetException();
+ }
+ throw e2;
+ }
+ }
+ }
+ catch (final NoSuchMethodException e2)
+ {
+ // acceptable
+ }
+
+ // if we get here then the method is not being proxied so call the
+ // original method on the base item.
+ return method.invoke(securedItem.getBaseItem(), args);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredAlt.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredAlt.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredAlt.java
new file mode 100644
index 0000000..6b4dea4
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredAlt.java
@@ -0,0 +1,264 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.Alt ;
+import org.apache.jena.rdf.model.RDFNode ;
+import org.apache.jena.rdf.model.ResourceF ;
+import org.apache.jena.security.AccessDeniedException;
+
+/**
+ * The interface for secured Alt instances.
+ *
+ * Use the SecuredAlt.Factory to create instances
+ */
+@SuppressWarnings("deprecation")
+public interface SecuredAlt extends Alt, SecuredContainer
+{
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredRDFNode getDefault() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt getDefaultAlt() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredBag getDefaultBag() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean getDefaultBoolean() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public byte getDefaultByte() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public char getDefaultChar() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public double getDefaultDouble() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public float getDefaultFloat() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public int getDefaultInt() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getDefaultLanguage() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredLiteral getDefaultLiteral() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public long getDefaultLong() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource getDefaultResource() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public SecuredResource getDefaultResource( final ResourceF f )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredSeq getDefaultSeq() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public short getDefaultShort() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getDefaultString() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
+ * RDF.li(1), o )
+ * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt setDefault( final boolean o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
+ * RDF.li(1), o )
+ * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt setDefault( final char o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
+ * RDF.li(1), o )
+ * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt setDefault( final double o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
+ * RDF.li(1), o )
+ * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt setDefault( final float o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
+ * RDF.li(1), o )
+ * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt setDefault( final long o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
+ * RDF.li(1), o )
+ * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt setDefault( final Object o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
+ * RDF.li(1), o )
+ * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt setDefault( final RDFNode o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
+ * RDF.li(1), o )
+ * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt setDefault( final String o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
+ * RDF.li(1), o )
+ * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt setDefault( final String o, final String l )
+ throws AccessDeniedException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredBag.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredBag.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredBag.java
new file mode 100644
index 0000000..62d63fa
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredBag.java
@@ -0,0 +1,29 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.Bag ;
+
+/**
+ * The interface for secured Bag instances.
+ *
+ * Use the SecuredBag.Factory to create instances
+ */
+public interface SecuredBag extends Bag, SecuredContainer
+{
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredContainer.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredContainer.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredContainer.java
new file mode 100644
index 0000000..eff2858
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredContainer.java
@@ -0,0 +1,218 @@
+/*
+ * 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.model;
+
+import java.util.Set;
+
+import org.apache.jena.rdf.model.Container ;
+import org.apache.jena.rdf.model.RDFNode ;
+import org.apache.jena.rdf.model.Statement ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.impl.SecuredNodeIterator;
+
+/**
+ * The interface for secured Container instances.
+ *
+ * Use one of the SecuredContainer derived class Factory methods to create
+ * instances
+ */
+public interface SecuredContainer extends Container, SecuredResource
+{
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer add( final boolean o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer add( final char o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer add( final double o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer add( final float o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer add( final long o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer add( final Object o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer add( final RDFNode o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer add( final String o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer add( final String o, final String l )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final boolean o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final char o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final double o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final float o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final long o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final Object o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final RDFNode o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final String o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final String o, final String l )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read on each triple ( this, rdf:li_? node ) returned by
+ * iterator;
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredNodeIterator<RDFNode> iterator() throws AccessDeniedException;
+
+ /**
+ * @param perms the Permissions required on each node returned
+ * @sec.graph Read
+ * @sec.triple Read + perms on each triple ( this, rdf:li_? node ) returned
+ * by iterator;
+ * @throws AccessDeniedException
+ */
+ public SecuredNodeIterator<RDFNode> iterator( Set<Action> perms )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete s as triple;
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredContainer remove( final Statement s )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public int size() throws AccessDeniedException;
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredLiteral.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredLiteral.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredLiteral.java
new file mode 100644
index 0000000..bb34453
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredLiteral.java
@@ -0,0 +1,165 @@
+/*
+ * 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.model;
+
+import org.apache.jena.datatypes.DatatypeFormatException ;
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.rdf.model.Literal ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.security.AccessDeniedException;
+
+/**
+ * The interface for secured Literal instances.
+ *
+ * Use the SecuredLiteral.Factory to create instances
+ */
+public interface SecuredLiteral extends Literal, SecuredRDFNode
+{
+
+ @Override
+ public SecuredLiteral asLiteral();
+
+ // @Override
+ // public SecuredResource asResource();
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean getBoolean() throws AccessDeniedException,
+ DatatypeFormatException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public byte getByte() throws AccessDeniedException, DatatypeFormatException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public char getChar() throws AccessDeniedException, DatatypeFormatException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public RDFDatatype getDatatype() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getDatatypeURI() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public double getDouble() throws AccessDeniedException,
+ DatatypeFormatException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public float getFloat() throws AccessDeniedException,
+ DatatypeFormatException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public int getInt() throws AccessDeniedException, DatatypeFormatException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getLanguage() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getLexicalForm() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public long getLong() throws AccessDeniedException, DatatypeFormatException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public short getShort() throws AccessDeniedException,
+ DatatypeFormatException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getString() throws AccessDeniedException,
+ DatatypeFormatException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Object getValue() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Literal inModel( final Model m ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean isWellFormedXML() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean sameValueAs( final Literal other )
+ throws AccessDeniedException;
+
+}
[14/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredModelTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredModelTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredModelTest.java
new file mode 100644
index 0000000..0e251d7
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredModelTest.java
@@ -0,0 +1,2034 @@
+/*
+ * 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.model;
+
+import java.io.* ;
+import java.net.URL ;
+import java.util.ArrayList ;
+import java.util.List ;
+import java.util.Set ;
+
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.* ;
+import org.apache.jena.security.SecurityEvaluator.Action ;
+import org.apache.jena.security.graph.SecuredGraph ;
+import org.apache.jena.security.graph.SecuredPrefixMappingTest ;
+import org.junit.Assert ;
+import org.junit.Before ;
+import org.junit.Test ;
+import org.junit.runner.RunWith ;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredModelTest
+{
+ protected final MockSecurityEvaluator securityEvaluator;
+ protected SecuredModel securedModel;
+ protected Model baseModel;
+ protected Resource s;
+ protected Property p;
+ protected Resource o;
+
+ public SecuredModelTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ this.securityEvaluator = securityEvaluator;
+ }
+
+ /**
+ * create an unsecured securedModel.
+ *
+ * @return
+ */
+ protected Model createModel()
+ {
+ return ModelFactory.createDefaultModel();
+ }
+
+ @Before
+ public void setup()
+ {
+ baseModel = createModel();
+ baseModel.removeAll();
+ securedModel = Factory.getInstance(securityEvaluator,
+ "http://example.com/securedGraph", baseModel);
+ s = ResourceFactory.createResource("http://example.com/graph/s");
+ p = ResourceFactory.createProperty("http://example.com/graph/p");
+ o = ResourceFactory.createResource("http://example.com/graph/o");
+ baseModel.add(s, p, o);
+ }
+
+ @Test
+ public void testAdd() throws Exception
+ {
+ final List<Statement> stmt = baseModel.listStatements().toList();
+ final Set<Action> createAndUpdate = SecurityEvaluator.Util
+ .asSet(new Action[] { Action.Update, Action.Create });
+ try
+ {
+ securedModel.add(stmt);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.add(baseModel);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.add(stmt.get(0));
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+
+ securedModel.add(stmt.toArray(new Statement[stmt.size()]));
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.add(baseModel.listStatements());
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.add(baseModel);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.add(s, p, o);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.add(s, p, "foo");
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.add(s, p, "foo", false);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.add(s, p, "foo", XSDDatatype.XSDstring);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.add(s, p, "foo", "en");
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testAnonymousInModel()
+ {
+ // test anonymous
+ final RDFNode rdfNode = ResourceFactory.createResource();
+ final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
+ Assert.assertEquals(
+ "Should have placed RDFNode in secured securedModel",
+ securedModel, rdfNode2.getModel());
+ }
+
+ @Test
+ public void testAsRDFNode() throws Exception
+ {
+ securedModel.asRDFNode(NodeFactory.createURI("http://example.com/rdfNode"));
+ }
+
+ @Test
+ public void testAsStatement()
+ {
+ final Triple t = new Triple(s.asNode(), p.asNode(), o.asNode());
+ try
+ {
+ securedModel.asStatement(t);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testContains() throws Exception
+ {
+ final Statement stmt = baseModel.listStatements().next();
+ try
+ {
+ securedModel.contains(stmt);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedModel.contains(s, p);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.contains(s, p, o);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.contains(s, p, "foo");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.contains(s, p, "foo", "en");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testContainsAll() throws Exception
+ {
+ try
+ {
+ securedModel.containsAll(baseModel);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.containsAll(baseModel.listStatements());
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCreateAlt() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+ try
+ {
+ securedModel.createAlt();
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.createAlt("foo");
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCreateBag() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+ try
+ {
+ securedModel.createBag();
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.createBag("foo");
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCreateList() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ final List<RDFNode> nodeList = new ArrayList<RDFNode>();
+ try
+ {
+ securedModel.createList();
+ if (!securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ baseModel.removeAll();
+
+ try
+ {
+ securedModel.createList(nodeList.iterator());
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ baseModel.removeAll();
+
+ try
+ {
+ final RDFNode[] list = new RDFNode[] {
+ ResourceFactory.createResource(),
+ ResourceFactory.createResource(),
+ ResourceFactory.createResource(),
+ ResourceFactory.createResource(), };
+
+ securedModel.createList(list);
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ baseModel.removeAll();
+
+ }
+
+ @Test
+ public void testCreateLiteral() throws Exception
+ {
+ securedModel.createLiteral("foo");
+ securedModel.createLiteral("foo", false);
+ }
+
+ @Test
+ public void testCreateLiteralBoolean() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+
+ try
+ {
+ securedModel.createLiteralStatement(s, p, true);
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCreateLiteralChar() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+ try
+ {
+ securedModel.createLiteralStatement(s, p, 'a');
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCreateLiteralDouble() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+
+ try
+ {
+ securedModel.createLiteralStatement(s, p, 1.0d);
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCreateLiteralFloat() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+
+ try
+ {
+ securedModel.createLiteralStatement(s, p, 1.0f);
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCreateLiteralInt() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+
+ try
+ {
+ securedModel.createLiteralStatement(s, p, 1);
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testCreateLiteralLong() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+
+ try
+ {
+ securedModel.createLiteralStatement(s, p, 1L);
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCreateLiteralObject() throws Exception
+ {
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+
+ try
+ {
+ securedModel.createLiteralStatement(s, p, new URL( "http://example.com/testing/URIType"));
+ if (!securityEvaluator.evaluate(CU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(CU))
+ {
+ e.printStackTrace();
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testDifference() throws Exception
+ {
+ try
+ {
+ securedModel.difference(baseModel);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testEquals() throws Exception
+ {
+ securedModel.equals(baseModel);
+ baseModel.equals(securedModel);
+ }
+
+ @Test
+ public void testExpandPrefix() throws Exception
+ {
+ try
+ {
+ securedModel.expandPrefix("foo");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetAlt() throws Exception
+ {
+ final Resource a = baseModel
+ .createAlt("http://example.com/securedModel/alt");
+ try
+ {
+
+ securedModel.getAlt(a);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedModel.getAlt("http://example.com/securedModel/alt");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetAnyReifiedStmt()
+ {
+ // first with create.
+ final Set<Action> UCR = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create, Action.Read });
+ try
+ {
+ securedModel.getAnyReifiedStatement(baseModel.listStatements()
+ .next());
+ if (!securityEvaluator.evaluate(UCR))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(UCR))
+ {
+ e.printStackTrace();
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ final Statement st = baseModel.listStatements().next();
+ baseModel.createReifiedStatement(st);
+ // now it is there so try with read
+ try
+ {
+ securedModel.getAnyReifiedStatement(st);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetBag()
+ {
+ final Resource b = baseModel
+ .createBag("http://example.com/securedModel/bag");
+ try
+ {
+ securedModel.getBag(b);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedModel.getBag("http://example.com/securedModel/bag");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetGraph() throws Exception
+ {
+ final Graph g = securedModel.getGraph();
+ Assert.assertTrue(g instanceof SecuredGraph);
+ EqualityTester.testInequality("getGraph test", g, baseModel.getGraph());
+ }
+
+ @Test
+ public void testGetLock()
+ {
+ securedModel.getLock();
+ }
+
+ @Test
+ public void testGetProperty()
+ {
+
+ try
+ {
+ securedModel.getProperty("foo");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.getProperty(s, p);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.getProperty("fooNS", "foo");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetQNameFor() throws Exception
+ {
+ try
+ {
+ securedModel.qnameFor("foo");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testgetRDFNode()
+ {
+
+ try
+ {
+ securedModel.getRDFNode(NodeFactory.createURI("foo"));
+ if (!securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetReader()
+ {
+ securedModel.getReader();
+ securedModel.getReader("TURTLE");
+ }
+
+ @Test
+ public void testGetResource()
+ {
+ securedModel.getResource("foo");
+ }
+
+ @Test
+ public void testGetSeq()
+ {
+ final Resource s = baseModel
+ .createSeq("http://example.com/securedModel/seq");
+ try
+ {
+ securedModel.getSeq(s);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.getSeq("http://example.com/securedModel/seq");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetWriter()
+ {
+ securedModel.getWriter();
+ securedModel.getWriter("TURTLE");
+ }
+
+ @Test
+ public void testIndependent() throws Exception
+ {
+ Assert.assertFalse(securedModel.independent());
+ }
+
+ @Test
+ public void testIntersection() throws Exception
+ {
+ try
+ {
+ securedModel.intersection(baseModel);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testIsClosed() throws Exception
+ {
+ securedModel.isClosed();
+ }
+
+ @Test
+ public void testIsEmpty() throws Exception
+ {
+ try
+ {
+ securedModel.isEmpty();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testIsIsomorphicWith()
+ {
+ try
+ {
+ securedModel.isIsomorphicWith(baseModel);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ baseModel.isIsomorphicWith(securedModel);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testIsReified()
+ {
+ try
+ {
+ securedModel.isReified(baseModel.listStatements().next());
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testListLiteralStatements() throws Exception
+ {
+ try
+ {
+ securedModel.listLiteralStatements(s, p, true);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.listLiteralStatements(s, p, '0');
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.listLiteralStatements(s, p, 2.0d);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.listLiteralStatements(s, p, 2.0f);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.listLiteralStatements(s, p, 1);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testLock() throws Exception
+ {
+ try
+ {
+ securedModel.lock();
+ if (!securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testPrefixMapping() throws Exception
+ {
+ SecuredPrefixMappingTest.runTests(securityEvaluator, securedModel);
+ }
+
+ @Test
+ public void testQuery() throws Exception
+ {
+ final Selector s = new SimpleSelector();
+ try
+ {
+ securedModel.query(s);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testRDFNodeInModel()
+ {
+ // test uri
+ final RDFNode rdfNode = ResourceFactory
+ .createResource("http://exmple.com/testInModel");
+ final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
+ Assert.assertEquals(
+ "Should have placed RDFNode in secured securedModel",
+ securedModel, rdfNode2.getModel());
+ }
+
+ @Test
+ public void testReadEmpty() throws Exception
+ {
+ final Set<Action> createAndUpdate = SecurityEvaluator.Util
+ .asSet(new Action[] { Action.Update, Action.Create });
+
+ final String XML_INPUT = "<rdf:RDF"
+ + " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' "
+ + " xmlns:rt='http://example.com/readTest#' "
+ + " xmlns:j.0='http://example.com/readTest#3' > "
+ + " <rdf:Description rdf:about='http://example.com/readTest#1'> "
+ + " <rdf:type rdf:resource='http://example.com/readTest#3'/>"
+ + " </rdf:Description>" + "</rdf:RDF>";
+ final String TTL_INPUT = "@prefix rt: <http://example.com/readTest#> . rt:1 a rt:3 .";
+ final String base = "http://example.com/test";
+ final String lang = "TURTLE";
+ try
+ {
+ final URL url = SecuredModelTest.class.getResource("./test.xml");
+ securedModel.read(url.toString());
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ finally
+ {
+ baseModel.removeAll();
+ }
+
+ try
+ {
+ final InputStream in = new ByteArrayInputStream(
+ XML_INPUT.getBytes());
+ securedModel.read(in, base);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ finally
+ {
+ baseModel.removeAll();
+ }
+
+ try
+ {
+ final Reader reader = new StringReader(XML_INPUT);
+ securedModel.read(reader, base);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ finally
+ {
+ baseModel.removeAll();
+ }
+
+ try
+ {
+ final URL url = SecuredModelTest.class.getResource("./test.ttl");
+ securedModel.read(url.toString(), lang);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ finally
+ {
+ baseModel.removeAll();
+ }
+
+ try
+ {
+ final InputStream in = new ByteArrayInputStream(
+ TTL_INPUT.getBytes());
+ securedModel.read(in, base, lang);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ finally
+ {
+ baseModel.removeAll();
+ }
+
+ try
+ {
+ final Reader reader = new StringReader(TTL_INPUT);
+ securedModel.read(reader, base, lang);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ finally
+ {
+ baseModel.removeAll();
+ }
+
+ try
+ {
+ final URL url = SecuredModelTest.class.getResource("./test.ttl");
+ securedModel.read(url.toString(), base, lang);
+ if (!securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(createAndUpdate))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ finally
+ {
+ baseModel.removeAll();
+ }
+
+ }
+
+ @Test
+ public void testRemove() throws Exception
+ {
+ final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Delete, Action.Update });
+
+ final List<Statement> stmt = baseModel.listStatements().toList();
+ try
+ {
+ securedModel.remove(baseModel.listStatements().toList());
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedModel.remove(baseModel);
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.remove(stmt.get(0));
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedModel.remove(stmt.toArray(new Statement[stmt.size()]));
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedModel.remove(baseModel.listStatements());
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedModel.remove(baseModel);
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedModel.remove(s, p, o);
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testRemoveAll() throws Exception
+ {
+ final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Delete, Action.Update });
+
+ try
+ {
+ securedModel.removeAll();
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ // put some data back
+ baseModel.add(s, p, o);
+ try
+ {
+ securedModel.removeAll(s, p, o);
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testRemoveAllReifications()
+ {
+ final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Delete, Action.Update });
+
+ final List<Statement> stmt = baseModel.listStatements().toList();
+ baseModel.createReifiedStatement(stmt.get(0));
+
+ try
+ {
+ securedModel.removeAllReifications(stmt.get(0));
+ if (!securityEvaluator.evaluate(DU))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(DU))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testRequiredProperty()
+ {
+
+ try
+ {
+ securedModel.getRequiredProperty(s, p);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testSize() throws Exception
+ {
+ try
+ {
+ securedModel.size();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testUnion() throws Exception
+ {
+ try
+ {
+ securedModel.union(baseModel);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ baseModel.union(securedModel);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testVariableInModel()
+ {
+ try
+ {
+ final RDFNode rdfNode = ResourceFactory
+ .createTypedLiteral("yeehaw");
+ final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
+ if (!securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ Assert.assertEquals(
+ "Should have placed RDFNode in secured securedModel",
+ securedModel, rdfNode2.getModel());
+
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testWrapAsResource() throws Exception
+ {
+ securedModel.wrapAsResource(NodeFactory.createURI("http://example.com/rdfNode"));
+ }
+
+ @Test
+ public void testWrite() throws Exception
+ {
+ final OutputStream out = new ByteArrayOutputStream();
+ final Writer writer = new CharArrayWriter();
+ final String lang = "TURTLE";
+ try
+ {
+ securedModel.write(out);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.write(writer);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.write(out, lang);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.write(writer, lang);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.write(out, lang, "http://example.com/securedGraph");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ securedModel.write(writer, lang, "http://example.com/securedGraph");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredPropertyTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredPropertyTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredPropertyTest.java
new file mode 100644
index 0000000..d035bae
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredPropertyTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.Property ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredProperty;
+import org.apache.jena.security.model.impl.SecuredPropertyImpl;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredPropertyTest extends SecuredResourceTest
+{
+
+ public SecuredPropertyTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ }
+
+ private SecuredProperty getSecuredProperty()
+ {
+ return (SecuredProperty) getSecuredRDFNode();
+ }
+
+ @Override
+ @Before
+ public void setup()
+ {
+ super.setup();
+ final Property p = ResourceFactory
+ .createProperty("http://example.com/testProperty");
+ setSecuredRDFNode(SecuredPropertyImpl.getInstance(securedModel, p), p);
+ }
+
+ @Test
+ public void testGetOrdinal()
+ {
+ try
+ {
+ getSecuredProperty().getOrdinal();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredRDFListTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredRDFListTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredRDFListTest.java
new file mode 100644
index 0000000..d1c32aa
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredRDFListTest.java
@@ -0,0 +1,970 @@
+/*
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.rdf.model.RDFList.ApplyFn ;
+import org.apache.jena.rdf.model.RDFList.ReduceFn ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredRDFList;
+import org.apache.jena.security.model.impl.SecuredRDFListImpl;
+import org.apache.jena.security.utils.RDFListIterator;
+import org.apache.jena.security.utils.RDFListSecFilter;
+import org.apache.jena.util.iterator.WrappedIterator ;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredRDFListTest extends SecuredResourceTest
+{
+ private RDFList baseList;
+
+ public SecuredRDFListTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ }
+
+ private int count( final Action action )
+ {
+ final Iterator<RDFList> iter = new RDFListIterator(
+ (RDFList) getBaseRDFNode());
+ return WrappedIterator.create(iter)
+ .filterKeep(new RDFListSecFilter<RDFList>(getSecuredRDFList(), action))
+ .toList().size();
+ }
+
+ private int count( final Set<Action> action )
+ {
+ final Iterator<RDFList> iter = new RDFListIterator(
+ (RDFList) getBaseRDFNode());
+ return WrappedIterator.create(iter)
+ .filterKeep(new RDFListSecFilter<RDFList>(getSecuredRDFList(), action))
+ .toList().size();
+ }
+
+ private SecuredRDFList getSecuredRDFList()
+ {
+ return (SecuredRDFList) getSecuredRDFNode();
+ }
+
+ @Override
+ @Before
+ public void setup()
+ {
+ super.setup();
+ final RDFNode[] listElements = {
+ ResourceFactory.createResource("http://example.com/ListNode1"),
+ ResourceFactory.createResource("http://example.com/ListNode2"),
+ ResourceFactory.createResource("http://example.com/ListNode3"),
+ ResourceFactory.createResource("http://example.com/ListNode4") };
+ baseList = baseModel.createList(listElements);
+ setSecuredRDFNode(SecuredRDFListImpl.getInstance(securedModel, baseList), baseList);
+ }
+
+ @Test
+ public void testAdd()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredRDFList().add(baseModel.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()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testAppendNodeIterator()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredRDFList().append(baseModel.listObjects());
+ 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 testAppendRDFList()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ try {
+ getSecuredRDFList().append(baseModel.createList());
+ if (!securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ if (!securityEvaluator.evaluate(Action.Create) && (baseList.size()>0 && securityEvaluator.evaluate(Action.Read) ))
+ {
+ 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 testApply()
+ {
+
+ final ApplyFn fn = new ApplyFn() {
+
+ @Override
+ public void apply( final RDFNode node )
+ {
+ // do nothing
+ }
+ };
+
+ try
+ {
+ getSecuredRDFList().apply(fn);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Read });
+ try
+ {
+ getSecuredRDFList().apply(perms, fn);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testAsJaveList()
+ {
+ try
+ {
+ getSecuredRDFList().asJavaList();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testConcatenate()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredRDFList().concatenate(baseModel.listObjects());
+ 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 List<Resource> lst = new ArrayList<Resource>();
+ lst.add(ResourceFactory
+ .createResource("http://example.com/dummyList"));
+ getSecuredRDFList().concatenate(
+ baseModel.createList(lst.iterator()));
+ 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 testCons()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredRDFList().cons(SecuredRDFNodeTest.s);
+ 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 testContains()
+ {
+ try
+ {
+ getSecuredRDFList().contains(SecuredRDFNodeTest.s);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCopy()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Read, Action.Update, Action.Create });
+ try
+ {
+ getSecuredRDFList().copy();
+ }
+ 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 testGet()
+ {
+ try
+ {
+ getSecuredRDFList().get(0);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final ListIndexException e)
+ {
+ if (((RDFList) getBaseRDFNode()).size() < 0)
+ {
+ // acceptable exception
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testGetHead()
+ {
+ try
+ {
+ getSecuredRDFList().getHead();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final ListIndexException e)
+ {
+ if (((RDFList) getBaseRDFNode()).size() == 0)
+ {
+ // acceptable exception
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testGetTail()
+ {
+ try
+ {
+ getSecuredRDFList().getTail();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final ListIndexException e)
+ {
+ if (((RDFList) getBaseRDFNode()).size() == 0)
+ {
+ // acceptable exception
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testGetValidityErrorMessage()
+ {
+ try
+ {
+ getSecuredRDFList().getValidityErrorMessage();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testIndexOf()
+ {
+ try
+ {
+ getSecuredRDFList().indexOf(SecuredRDFNodeTest.s);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final ListIndexException e)
+ {
+ if (((RDFList) getBaseRDFNode()).size() == 0)
+ {
+ // acceptable exception
+ }
+ else
+ {
+ throw e;
+ }
+ }
+
+ try
+ {
+ getSecuredRDFList().indexOf(SecuredRDFNodeTest.s, 1);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final ListIndexException e)
+ {
+ if (((RDFList) getBaseRDFNode()).size() <= 0)
+
+ {
+ // acceptable exception
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testIsEmpty()
+ {
+ try
+ {
+ getSecuredRDFList().isEmpty();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testIterator()
+ {
+ try
+ {
+ getSecuredRDFList().iterator();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ try
+ {
+ getSecuredRDFList().iterator(perms);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testReduce()
+ {
+ final ReduceFn fn = new ReduceFn() {
+
+ @Override
+ public Object reduce( final RDFNode node, final Object accumulator )
+ {
+ return accumulator;
+ }
+ };
+
+ try
+ {
+ getSecuredRDFList().reduce(fn, "Hello");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ try
+ {
+ getSecuredRDFList().reduce(perms, fn, "Hello");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ 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
+ {
+ final int count = count(Action.Delete);
+ getSecuredRDFList().remove(SecuredRDFNodeTest.s);
+ if (!securityEvaluator.evaluate(Action.Update)
+ || ((count > 0) && !securityEvaluator
+ .evaluate(Action.Delete)))
+ {
+ 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()));
+ }
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ @Test
+ public void testRemoveAll()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Delete });
+
+ try
+ {
+ final int count = count(SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Delete, Action.Read }));
+ getSecuredRDFList().removeAll();
+ if (!securityEvaluator.evaluate(Action.Update)
+ || ((count > 0) && !securityEvaluator
+ .evaluate(Action.Delete)))
+ {
+ 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()));
+ }
+ }
+ catch (final EmptyListException e)
+ {
+ if (count(Action.Read) == 0)
+ {
+ // expected.
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testRemoveHead()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Delete });
+
+ try
+ {
+ getSecuredRDFList().removeHead();
+ 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()));
+ }
+ }
+ catch (final EmptyListException e)
+ {
+ if (count(Action.Read) == 0)
+ {
+ // expected.
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testRemoveList()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Delete });
+
+ try
+ {
+ final int count = count(Action.Delete);
+ getSecuredRDFList().removeList();
+ if (!securityEvaluator.evaluate(Action.Update)
+ || ((count > 0) && !securityEvaluator
+ .evaluate(Action.Delete)))
+ {
+ 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 testReplace()
+ {
+ try
+ {
+ getSecuredRDFList().replace(1, SecuredRDFNodeTest.s);
+ if (!securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final ListIndexException e)
+ {
+ if (count(Action.Read) == 0)
+ {
+ // expected.
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testSameListAs()
+ {
+ try
+ {
+ getSecuredRDFList().sameListAs(baseModel.createList());
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testSetHead()
+ {
+
+ try
+ {
+ getSecuredRDFList().setHead(SecuredRDFNodeTest.s);
+ if (!securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final EmptyListException e)
+ {
+ if (count(Action.Read) == 0)
+ {
+ // expected.
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testSetStrict()
+ {
+ try
+ {
+ getSecuredRDFList().setStrict(true);
+ if (!securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Update))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testSize()
+ {
+ try
+ {
+ getSecuredRDFList().size();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testValid()
+ {
+ try
+ {
+ getSecuredRDFList().isValid();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testWith()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ try
+ {
+ getSecuredRDFList().with(SecuredRDFNodeTest.s);
+ 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()));
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredRDFNodeTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredRDFNodeTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredRDFNodeTest.java
new file mode 100644
index 0000000..79ba3e2
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredRDFNodeTest.java
@@ -0,0 +1,209 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.Factory;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredRDFNode;
+import org.apache.jena.security.model.impl.SecuredRDFNodeImpl;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredRDFNodeTest
+{
+ protected final MockSecurityEvaluator securityEvaluator;
+ protected Model baseModel;
+ protected SecuredModel securedModel;
+ private SecuredRDFNode securedRDFNode;
+ private RDFNode baseRDFNode;
+
+ public static Resource s = ResourceFactory
+ .createResource("http://example.com/graph/s");
+ public static Property p = ResourceFactory
+ .createProperty("http://example.com/graph/p");
+ public static Property p2 = ResourceFactory
+ .createProperty("http://example.com/graph/p2");
+ public static Resource o = ResourceFactory
+ .createResource("http://example.com/graph/o");
+
+ public SecuredRDFNodeTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ this.securityEvaluator = securityEvaluator;
+ }
+
+ protected Model createModel()
+ {
+ return ModelFactory.createDefaultModel();
+ }
+
+ protected RDFNode getBaseRDFNode()
+ {
+ return baseRDFNode;
+ }
+
+ protected SecuredRDFNode getSecuredRDFNode()
+ {
+ return securedRDFNode;
+ }
+
+ protected void setSecuredRDFNode( final SecuredRDFNode securedRDFNode,
+ final RDFNode baseRDFNode )
+ {
+ this.securedRDFNode = securedRDFNode;
+ this.baseRDFNode = baseRDFNode;
+ }
+
+ @Before
+ public void setup()
+ {
+ baseModel = createModel();
+ baseModel.removeAll();
+ baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p,
+ SecuredRDFNodeTest.o);
+ baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p2, "yeehaw");
+ securedModel = Factory.getInstance(securityEvaluator,
+ "http://example.com/securedGraph", baseModel);
+ securedRDFNode = SecuredRDFNodeImpl.getInstance(
+ securedModel,
+ baseModel.listObjectsOfProperty(SecuredRDFNodeTest.s,
+ SecuredRDFNodeTest.p).next());
+ }
+
+ @After
+ public void teardown()
+ {
+ securedModel.close();
+ securedModel = null;
+ }
+
+ @Test
+ public void testAsNode()
+ {
+ try
+ {
+ securedRDFNode.asNode();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testCanAs()
+ {
+ try
+ {
+ securedRDFNode.canAs(Resource.class);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetModel()
+ {
+ final Model m2 = securedRDFNode.getModel();
+ Assert.assertTrue("Model should have been secured",
+ m2 instanceof SecuredModel);
+ }
+
+ @Test
+ public void testInModel()
+ {
+ final Model m2 = ModelFactory.createDefaultModel();
+ try
+ {
+ final RDFNode n2 = securedRDFNode.inModel(m2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ Assert.assertFalse("RDFNode should not have been secured",
+ n2 instanceof SecuredRDFNode);
+ Assert.assertEquals("Wrong securedModel returned", n2.getModel(),
+ m2);
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ m2.removeAll();
+ final SecuredModel m3 = Factory.getInstance(securityEvaluator,
+ "http://example.com/securedGraph2", m2);
+
+ try
+ {
+ final RDFNode n2 = securedRDFNode.inModel(m3);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ Assert.assertTrue("RDFNode should have been secured",
+ n2 instanceof SecuredRDFNode);
+ Assert.assertEquals("Wrong securedModel returned", n2.getModel(),
+ m3);
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredReifiedStatementTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredReifiedStatementTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredReifiedStatementTest.java
new file mode 100644
index 0000000..00aceb2
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredReifiedStatementTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.ReifiedStatement ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredReifiedStatement;
+import org.apache.jena.security.model.impl.SecuredReifiedStatementImpl;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredReifiedStatementTest extends SecuredResourceTest
+{
+
+ public SecuredReifiedStatementTest(
+ final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ }
+
+ private SecuredReifiedStatement getSecuredReifiedStatement()
+ {
+ return (SecuredReifiedStatement) getSecuredRDFNode();
+ }
+
+ @Override
+ @Before
+ public void setup()
+ {
+ super.setup();
+ final ReifiedStatement stmt = baseModel.listStatements().next()
+ .createReifiedStatement();
+ setSecuredRDFNode(
+ SecuredReifiedStatementImpl.getInstance(securedModel, stmt),
+ stmt);
+ }
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Test
+ public void testGetStatement()
+ {
+ try
+ {
+ getSecuredReifiedStatement().getStatement();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+}
[11/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/SecurityEvaluatorAssembler.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/SecurityEvaluatorAssembler.java b/jena-security/src/main/java/org/apache/jena/security/SecurityEvaluatorAssembler.java
deleted file mode 100644
index 57f6dfd..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/SecurityEvaluatorAssembler.java
+++ /dev/null
@@ -1,183 +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.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.jena.assembler.Assembler ;
-import org.apache.jena.assembler.Mode ;
-import org.apache.jena.assembler.assemblers.AssemblerBase ;
-import org.apache.jena.assembler.exceptions.AssemblerException ;
-import org.apache.jena.rdf.model.* ;
-
-/**
- * A simple assembler for a SecurityEvaluator
- * <p>
- * This assembler load the specified class, locates the first constructor that accepts
- * the number of arguments in the assembler file, and calls it passing the arguments.
- * Generally the result of this assembler is passed to a sec:Model construction.
- * @see SecuredAssembler
- * </p>
- * <ul>
- * <li>The evaluator must have one and only one public constructor
- * that takes the number of arguments specified in the assembler file.
- * </li>
- *
- * <li>
- * The evaluator may have more constructors but they may not have the same
- * number of arguments as specified in the assembler file.
- * </li>
- *
- * <li>
- * The arguments must be specified in the assembler file in the order that they
- * should be passed to the constructor.
- * </li>
- * </ul>
- *
- * <p>
- * Literal arguments are converted to their data type before calling the constructor. For example
- * "13"^^xsd:int will be converted to an Integer with the value of 13.
- * </p>
- * The assembler file should include the following
- * <code><pre>
- * @prefix xsd: <http://www.w3.org/2001/XMLSchema#>
- *
- * <>; ja:loadClass "org.apache.jena.security.SecuredAssembler" .
- *
- * sec:Model rdfs:subClassOf ja:NamedModel .
- *
- * </pre></code>
- *
- * The model definition should include something like.
- *
- * <code><pre>
- * ex:myEvaluator a sec:Evaluator ;
- * sec:args [ rdf:_1 "argument 1 for my evaluator constructor" ;
- * rdf:_2 "13"^^xsd:int ; ];
- * sec:evaluatorClass "evaluatorClassname";
- * .
- * </pre></code>
- *
- * Terms used in above example:
- *
- * <dl>
- * <dt>my:secEvaluator</dt>
- * <dd>The security evaluator as referenced in the assembler file.</dd>
- *
- * <dt>sec:Evaluator</dt>
- * <dd>Identifies my:secEvaluator as a SecurityEvaluator</dd>
- *
- * <dt>sec:args</dt>
- * <dd>Identifies the argument list</dd>
- *
- * <dt>rdf:_1</dt>
- * <dd>The first argument</dd>
- *
- * <dt>rdf:_2</dt>
- * <dd>The second argument (an integer in this case</dd>
- *
- * <dt>sec:evaluatorClass</dt>
- * <dd>The fully qualified name of the SecurityEvaluator class to call. This class must extend
- * SecurityEvaluator, and must have one and only one constructor that takes the number of arguments
- * specified in sec:args</dd>
- *
- * </p>
- *
- */
-public class SecurityEvaluatorAssembler extends AssemblerBase implements Assembler, AssemblerConstants {
- // initialization and registration is performed by SecuredAssembler
-
- @Override
- public SecurityEvaluator open(Assembler a, Resource root, Mode mode) {
-
- Literal className = getUniqueLiteral( root, EVALUATOR_CLASS );
- if (className == null)
- {
- throw new AssemblerException( root, String.format( NO_X_PROVIDED, EVALUATOR_CLASS, root ));
- }
-
- Class<?> clazz;
- try {
- clazz = Class.forName(className.getString());
- } catch (ClassNotFoundException e1) {
- throw new AssemblerException( root, String.format( "Can not locate class %s as specified by %s in %s", className, EVALUATOR_CLASS, root ));
- }
- if ( ! SecurityEvaluator.class.isAssignableFrom( clazz ))
- {
- throw new AssemblerException( root, String.format( "Class %s as specified by %s in %s does not implement SecurityEvaluator", className, EVALUATOR_CLASS, root ));
- }
-
- // get the arguments as specified.
- List<Object> args = new ArrayList<Object>();
- Resource argRes = getUniqueResource( root, ARGUMENT_LIST );
- if (argRes != null)
- {
- Seq seq = argRes.as( Seq.class );
- NodeIterator iter = seq.iterator();
- RDFNode n = null;
- while (iter.hasNext())
- {
- n = iter.next();
- if (n.isLiteral())
- {
- args.add( n.asLiteral().getValue());
- }
- else if (n.isResource())
- {
- args.add( a.open( a, n.asResource(), mode ) );
- }
- else
- {
- throw new AssemblerException( root, String.format( "%s must be a literal or a resource", n ));
- }
- }
- }
-
- for (Constructor<?> c : clazz.getConstructors())
- {
- if (c.getParameterTypes().length == args.size())
- {
- try {
- if (args.size() == 0)
- {
- return (SecurityEvaluator) c.newInstance();
- }
- else
- {
- return (SecurityEvaluator) c.newInstance( args.toArray() );
- }
- } catch (InstantiationException e) {
- throw new AssemblerException( root, e.getMessage(), e );
- } catch (IllegalAccessException e) {
- throw new AssemblerException( root, e.getMessage(), e );
- } catch (IllegalArgumentException e) {
- throw new AssemblerException( root, e.getMessage(), e );
- } catch (InvocationTargetException e) {
- throw new AssemblerException( root, e.getMessage(), e );
- }
- }
-
- }
- throw new AssemblerException( root, String.format( "Class %s does not have a %s argument constructor", className, args.size() ));
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/SecuredBulkUpdateHandler.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredBulkUpdateHandler.java b/jena-security/src/main/java/org/apache/jena/security/graph/SecuredBulkUpdateHandler.java
deleted file mode 100644
index 6263af9..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredBulkUpdateHandler.java
+++ /dev/null
@@ -1,148 +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.graph;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.jena.graph.BulkUpdateHandler ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.impl.SecuredItem;
-
-/**
- * The interface for secured BulkUpdateHanlder instances.
- *
- * Use the SecuredBulkUpdateHandler.Factory to create instances
- */
-public interface SecuredBulkUpdateHandler extends BulkUpdateHandler,
- SecuredItem
-{
-
- /**
- * @sec.graph Update
- * @sec.triple Create
- * @throws AccessDeniedException
- */
- @Override
- public void add( final Graph g ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public void add( final Graph g, final boolean withReifications )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public void add( final Iterator<Triple> it ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public void add( final List<Triple> triples ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public void add( final Triple[] triples ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- */
- @Override
- public void delete( final Graph g ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public void delete( final Graph g, final boolean withReifications )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public void delete( final Iterator<Triple> it )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public void delete( final List<Triple> triples )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public void delete( final Triple[] triples ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- */
- @Override
- public void remove( final Node s, final Node p, final Node o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- */
- @Override
- public void removeAll() throws AccessDeniedException;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/SecuredCapabilities.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredCapabilities.java b/jena-security/src/main/java/org/apache/jena/security/graph/SecuredCapabilities.java
deleted file mode 100644
index 6a12fa1..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredCapabilities.java
+++ /dev/null
@@ -1,151 +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.graph;
-
-import org.apache.jena.graph.Capabilities ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.SecurityEvaluator.SecTriple;
-import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
-
-/**
- * The interface for secured Capabilities instances.
- *
- */
-public class SecuredCapabilities implements Capabilities
-{
- // the security evaluator in use
- private final SecurityEvaluator securityEvaluator;
- // the graphIRI that the capabilities belong to.
- private final SecNode graphIRI;
- // the unsecured capabilities.
- private final Capabilities capabilities;
-
- /**
- * Constructor.
- *
- * @param securityEvaluator
- * The security evaluator in use.
- * @param graphURI
- * The graphIRI that the capabilities describe.
- * @param capabilities
- * The unsecured capabilities.
- */
- public SecuredCapabilities( final SecurityEvaluator securityEvaluator,
- final String graphURI, final Capabilities capabilities )
- {
- this.securityEvaluator = securityEvaluator;
- this.graphIRI = new SecNode(Type.URI, graphURI);
- this.capabilities = capabilities;
- }
-
- /**
- * @sec.graph Update
- */
- @Override
- public boolean addAllowed()
- {
- return securityEvaluator.evaluate(securityEvaluator.getPrincipal(), Action.Update, graphIRI)
- && capabilities.addAllowed();
- }
-
- /**
- * @sec.graph Update
- * @sec.triple Create (if everyTriple is true)
- */
- @Override
- public boolean addAllowed( final boolean everyTriple )
- {
- Object principal = securityEvaluator.getPrincipal();
-
- boolean retval = securityEvaluator.evaluate(principal, Action.Update, graphIRI)
- && capabilities.addAllowed(everyTriple);
- if (retval && everyTriple)
- {
- // special security check
- retval = securityEvaluator.evaluate(principal, Action.Create, graphIRI,
- SecTriple.ANY);
- }
- return retval;
- }
-
- @Override
- public boolean canBeEmpty()
- {
- return capabilities.canBeEmpty();
- }
-
- /**
- * @sec.graph Update
- */
- @Override
- public boolean deleteAllowed()
- {
- return securityEvaluator.evaluate(securityEvaluator.getPrincipal(), Action.Update, graphIRI)
- && capabilities.deleteAllowed();
- }
-
- /**
- * @sec.graph Update
- * @sec.triple Delete (if everyTriple is true)
- */
- @Override
- public boolean deleteAllowed( final boolean everyTriple )
- {
- Object principal = securityEvaluator.getPrincipal();
-
- boolean retval = securityEvaluator.evaluate(principal, Action.Update, graphIRI)
- && capabilities.addAllowed(everyTriple);
- if (retval && everyTriple)
- {
- // special security check
- retval = securityEvaluator.evaluate(principal, Action.Delete, graphIRI,
- SecTriple.ANY);
- }
- return retval;
- }
-
- @Override
- public boolean findContractSafe()
- {
- return capabilities.findContractSafe();
- }
-
- @Override
- public boolean handlesLiteralTyping()
- {
- return capabilities.handlesLiteralTyping();
- }
-
- /**
- * @sec.graph Update
- */
- @Override
- public boolean iteratorRemoveAllowed()
- {
- return securityEvaluator.evaluate(securityEvaluator.getPrincipal(), Action.Update, graphIRI)
- && capabilities.iteratorRemoveAllowed();
- }
-
- @Override
- public boolean sizeAccurate()
- {
- return capabilities.sizeAccurate();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/SecuredGraph.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredGraph.java b/jena-security/src/main/java/org/apache/jena/security/graph/SecuredGraph.java
deleted file mode 100644
index afdfdc8..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredGraph.java
+++ /dev/null
@@ -1,176 +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.graph;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.GraphStatisticsHandler ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.security.AccessDeniedException ;
-import org.apache.jena.security.SecurityEvaluator ;
-import org.apache.jena.security.SecurityEvaluator.SecNode ;
-import org.apache.jena.shared.AddDeniedException ;
-import org.apache.jena.shared.DeleteDeniedException ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-
-/**
- * The interface for secured Graph instances.
- *
- * Use the SecuredGraph.Factory to create instances
- */
-public interface SecuredGraph extends Graph
-{
-
- /**
- * @sec.graph Update
- * @sec.triple Create
- * @throws AccessDeniedException
- * @throws AddDeniedException
- */
- @Override
- public void add( final Triple t ) throws AddDeniedException,
- AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final Node s, final Node p, final Node o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final Triple t ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- * @throws DeleteDeniedException
- */
- @Override
- public void delete( final Triple t ) throws DeleteDeniedException,
- AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean dependsOn( final Graph other ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read, otherwise filtered from iterator.
- * @throws AccessDeniedException
- */
- @Override
- public ExtendedIterator<Triple> find( final Node s, final Node p,
- final Node o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read, otherwise filtered from iterator.
- * @throws AccessDeniedException
- * @deprecated Use {@link #find(Triple)}
- */
- @Deprecated
- @Override
- public ExtendedIterator<Triple> find( final org.apache.jena.graph.TripleMatch triple )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read, otherwise filtered from iterator.
- * @throws AccessDeniedException
- */
- @Override
- public ExtendedIterator<Triple> find( final Triple triple )
- throws AccessDeniedException;
-
- @Override
- public SecuredBulkUpdateHandler getBulkUpdateHandler();
-
- @Override
- public SecuredCapabilities getCapabilities();
-
- @Override
- public SecuredGraphEventManager getEventManager();
-
- public SecNode getModelNode();
-
- @Override
- public SecuredPrefixMapping getPrefixMapping();
-
- public SecurityEvaluator getSecurityEvaluator();
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public GraphStatisticsHandler getStatisticsHandler()
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean isEmpty() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean isIsomorphicWith( final Graph g )
- throws AccessDeniedException;
-
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public int size() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete for every triple
- * @throws AccessDeniedException
- */
- @Override
- public void clear();
-
- /**
- * @sec.graph Update
- * @sec.triple Delete (s, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public void remove( Node s, Node p, Node o );
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/SecuredGraphEventManager.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredGraphEventManager.java b/jena-security/src/main/java/org/apache/jena/security/graph/SecuredGraphEventManager.java
deleted file mode 100644
index 9c62127..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredGraphEventManager.java
+++ /dev/null
@@ -1,608 +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.graph;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Stack;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.GraphEventManager ;
-import org.apache.jena.graph.GraphListener ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.graph.impl.CollectionGraph ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.graph.impl.SecuredGraphImpl;
-import org.apache.jena.security.impl.CachedSecurityEvaluator;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.security.utils.PermTripleFilter;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.NiceIterator ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-
-/**
- * Since we sit between the graph and other items we have to determine when the
- * message is first seen and send it to the underlying graph if necessary.
- */
-public class SecuredGraphEventManager implements GraphEventManager {
- private class SecuredGraphListener implements GraphListener {
- private final GraphListener wrapped;
- private final Object runAs;
-
- SecuredGraphListener(final GraphListener wrapped) {
- if (wrapped == null) {
- throw new IllegalArgumentException(
- "Wrapped listener may not be null");
- }
- this.wrapped = wrapped;
- this.runAs = securedGraph.getSecurityEvaluator().getPrincipal();
- }
-
- private Triple[] getArray(final Graph g, final Triple[] triples,
- final Set<Action> perms) {
- Triple[] retval = triples;
- if (g instanceof SecuredGraphImpl) {
- final SecuredGraphImpl sg = (SecuredGraphImpl) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- if (evaluator.evaluateAny(runAs, perms, sg.getModelNode())) {
- if (!evaluator.evaluateAny(runAs, perms, sg.getModelNode(),
- SecuredItemImpl.convert(Triple.ANY))) {
- final List<Triple> list = wrapPermIterator(sg,
- Arrays.asList(triples).iterator(), perms)
- .toList();
- retval = list.toArray(new Triple[list.size()]);
- }
- else {
- retval = triples;
- }
- }
- else {
- retval = new Triple[0];
- }
- }
- return retval;
- }
-
- @Override
- public void notifyAddArray(final Graph g, final Triple[] triples) {
- final Triple[] added = getArray(g, triples,
- SecuredGraphEventManager.ADD);
-
- if (added.length > 0) {
- wrapped.notifyAddArray(g, added);
- }
- }
-
- @Override
- public void notifyAddGraph(final Graph g, final Graph added) {
- Graph addGraph = added;
- if (g instanceof SecuredGraph) {
- final SecuredGraph sg = (SecuredGraph) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- if (evaluator.evaluateAny(runAs, SecuredGraphEventManager.ADD,
- sg.getModelNode())) {
- if (!evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.ADD, sg.getModelNode(),
- SecuredItemImpl.convert(Triple.ANY))) {
- final List<Triple> lst = added.find(Triple.ANY)
- .toList();
- addGraph = new CollectionGraph(Arrays.asList(getArray(
- g, lst.toArray(new Triple[lst.size()]),
- SecuredGraphEventManager.ADD)));
- }
- else {
- addGraph = added;
- }
- }
- else {
- addGraph = new CollectionGraph(
- Collections.<Triple> emptyList());
- }
- }
- if (addGraph.size() > 0) {
- wrapped.notifyAddGraph(g, addGraph);
-
- }
- }
-
- @Override
- public void notifyAddIterator(final Graph g, final Iterator<Triple> it) {
-
- if (g instanceof SecuredGraphImpl) {
- final SecuredGraphImpl sg = (SecuredGraphImpl) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- // only report if we can write to the graph
- if (evaluator.evaluateAny(runAs, SecuredGraphEventManager.ADD,
- sg.getModelNode())) {
- final ExtendedIterator<Triple> iter = wrapPermIterator(sg,
- it, SecuredGraphEventManager.ADD);
- try {
- wrapped.notifyAddIterator(g, iter);
- } finally {
- iter.close();
- }
- }
- }
- else {
- wrapped.notifyAddIterator(g, it);
- }
-
- }
-
- @Override
- public void notifyAddList(final Graph g, final List<Triple> triples) {
- List<Triple> list = triples;
- if (g instanceof SecuredGraphImpl) {
- final SecuredGraphImpl sg = (SecuredGraphImpl) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- if (evaluator.evaluateAny(runAs, SecuredGraphEventManager.ADD,
- sg.getModelNode())) {
- if (!evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.ADD, sg.getModelNode(),
- SecuredItemImpl.convert(Triple.ANY))) {
- list = wrapPermIterator(sg, triples.iterator(),
- SecuredGraphEventManager.ADD).toList();
- }
- else {
- list = triples;
- }
- }
- else {
- list = Collections.emptyList();
- }
- }
-
- if (list.size() > 0) {
-
- wrapped.notifyAddList(g, list);
- }
- }
-
- @Override
- public void notifyAddTriple(final Graph g, final Triple t) {
- boolean notify = false;
- if (g instanceof SecuredGraph) {
- final SecuredGraph sg = (SecuredGraph) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- notify = evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.ADD, sg.getModelNode());
- if (notify) {
- notify = evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.ADD, sg.getModelNode(),
- SecuredItemImpl.convert(t));
- }
- }
- else {
- notify = true;
- }
- if (notify) {
- wrapped.notifyAddTriple(g, t);
- }
- }
-
- @Override
- public void notifyDeleteArray(final Graph g, final Triple[] triples) {
- Triple[] deleted = triples;
- if (g instanceof SecuredGraphImpl) {
- final SecuredGraphImpl sg = (SecuredGraphImpl) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- if (evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode())) {
- if (!evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode(),
- SecuredItemImpl.convert(Triple.ANY))) {
- final List<Triple> list = wrapPermIterator(sg,
- Arrays.asList(triples).iterator(),
- SecuredGraphEventManager.DELETE).toList();
- deleted = list.toArray(new Triple[list.size()]);
- }
- else {
- deleted = triples;
- }
- }
- else {
- deleted = new Triple[0];
- }
- }
-
- if (deleted.length > 0) {
- wrapped.notifyDeleteArray(g, deleted);
- }
- }
-
- @Override
- public void notifyDeleteGraph(final Graph g, final Graph removed) {
- if (g instanceof SecuredGraphImpl) {
- final SecuredGraphImpl sg = (SecuredGraphImpl) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- if (evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode())) {
- Graph g2 = removed;
- if (!evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode(),
- SecuredItemImpl.convert(Triple.ANY))) {
- g2 = new CollectionGraph(
- removed.find(Triple.ANY)
- .filterKeep(
- new PermTripleFilter(
- SecuredGraphEventManager.DELETE,
- sg, evaluator))
- .toList());
-
- }
- wrapped.notifyDeleteGraph(g, g2);
- }
- else {
- // do nothing.
- }
- }
- else {
- wrapped.notifyDeleteGraph(g, removed);
- }
- }
-
- @Override
- public void notifyDeleteIterator(final Graph g,
- final Iterator<Triple> it) {
- Iterator<Triple> iter = it;
- if (g instanceof SecuredGraphImpl) {
- final SecuredGraphImpl sg = (SecuredGraphImpl) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- if (evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode())) {
-
- if (!evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode(),
- SecuredItemImpl.convert(Triple.ANY))) {
- iter = WrappedIterator.create(it).filterKeep(
- new PermTripleFilter(
- SecuredGraphEventManager.DELETE, sg,
- evaluator));
- }
- // else use the default list as all can bee seen
- wrapped.notifyDeleteIterator(g, iter);
- }
- else {
- // do nothing.
- }
- }
- else {
- wrapped.notifyDeleteIterator(g, iter);
- }
-
- }
-
- @Override
- public void notifyDeleteList(final Graph g, final List<Triple> triples) {
- List<Triple> list = triples;
- if (g instanceof SecuredGraphImpl) {
- final SecuredGraphImpl sg = (SecuredGraphImpl) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- if (evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode())) {
- if (!evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode(),
- SecuredItemImpl.convert(Triple.ANY))) {
- list = WrappedIterator
- .create(triples.iterator())
- .filterKeep(
- new PermTripleFilter(
- SecuredGraphEventManager.DELETE,
- sg, evaluator)).toList();
- }
- // else use the default list as all can bee seen
- }
- else {
- list = Collections.emptyList();
- }
- }
-
- if (list.size() > 0) {
- wrapped.notifyDeleteList(g, list);
- }
- }
-
- @Override
- public void notifyDeleteTriple(final Graph g, final Triple t) {
- boolean notify = false;
- if (g instanceof SecuredGraph) {
- final SecuredGraph sg = (SecuredGraph) g;
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- notify = evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode());
- if (notify) {
- notify = evaluator.evaluateAny(runAs,
- SecuredGraphEventManager.DELETE, sg.getModelNode(),
- SecuredItemImpl.convert(t));
- }
- }
- else {
- notify = true;
- }
- if (notify) {
- wrapped.notifyDeleteTriple(g, t);
- }
- }
-
- @Override
- public void notifyEvent(final Graph source, final Object value) {
- wrapped.notifyEvent(source, value);
- }
-
- private ExtendedIterator<Triple> wrapPermIterator(
- final SecuredGraphImpl sg, final Iterator<Triple> it,
- final Set<Action> perms) {
- final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
- if (!evaluator.evaluateAny(runAs, perms, sg.getModelNode(),
- SecuredItemImpl.convert(Triple.ANY))) {
- // nope so wrap the iterator with security iterator
- return WrappedIterator.create(it).filterKeep(
- new PermTripleFilter(perms, sg, evaluator));
- }
- return WrappedIterator.create(it);
- }
-
- }
-
- // the security evaluator in use
- private final SecuredGraph securedGraph;
- private final Graph baseGraph;
- private final Map<GraphListener, Stack<SecuredGraphListener>> listenerMap = new HashMap<GraphListener, Stack<SecuredGraphListener>>();
- private static Set<Action> DELETE;
-
- private static Set<Action> ADD;
-
- static {
- SecuredGraphEventManager.ADD = new HashSet<Action>(
- Arrays.asList(new Action[] {
- Action.Create, Action.Read
- }));
- SecuredGraphEventManager.DELETE = new HashSet<Action>(
- Arrays.asList(new Action[] {
- Action.Delete, Action.Read
- }));
- }
-
- public SecuredGraphEventManager(final SecuredGraph securedGraph,
- final Graph baseGraph, final GraphEventManager manager) {
- this.securedGraph = securedGraph;
- this.baseGraph = baseGraph;
- manager.register(this);
- }
-
- private synchronized Collection<SecuredGraphListener> getListenerCollection() {
- ExtendedIterator<SecuredGraphListener> retval = NiceIterator
- .emptyIterator();
- for (final Collection<SecuredGraphListener> coll : listenerMap.values()) {
- retval = retval.andThen(coll.iterator());
- }
- return retval.toList();
- }
-
- @Override
- public boolean listening() {
- return !listenerMap.isEmpty();
- }
-
- @Override
- public void notifyAddArray(final Graph g, final Triple[] triples) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyAddArray(securedGraph, triples);
- }
- else {
- sgl.notifyAddArray(g, triples);
- }
- }
- }
-
- @Override
- public void notifyAddGraph(final Graph g, final Graph added) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyAddGraph(securedGraph, added);
- }
- else {
- sgl.notifyAddGraph(g, added);
- }
- }
- }
-
- @Override
- public void notifyAddIterator(final Graph g, final Iterator<Triple> it) {
- notifyAddIterator(g, WrappedIterator.create(it).toList());
- baseGraph.equals(g);
- }
-
- @Override
- public void notifyAddIterator(final Graph g, final List<Triple> triples) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyAddIterator(securedGraph, triples.iterator());
- }
- else {
- sgl.notifyAddIterator(g, triples.iterator());
- }
- }
- }
-
- @Override
- public void notifyAddList(final Graph g, final List<Triple> triples) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyAddList(securedGraph, triples);
- }
- else {
- sgl.notifyAddList(g, triples);
- }
- }
- }
-
- @Override
- public void notifyAddTriple(final Graph g, final Triple t) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyAddTriple(securedGraph, t);
- }
- else {
- sgl.notifyAddTriple(g, t);
- }
- }
- }
-
- @Override
- public void notifyDeleteArray(final Graph g, final Triple[] triples) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyDeleteArray(securedGraph, triples);
- }
- else {
- sgl.notifyDeleteArray(g, triples);
- }
- }
- }
-
- @Override
- public void notifyDeleteGraph(final Graph g, final Graph removed) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyDeleteGraph(securedGraph, removed);
- }
- else {
- sgl.notifyDeleteGraph(g, removed);
- }
- }
- }
-
- @Override
- public void notifyDeleteIterator(final Graph g, final Iterator<Triple> it) {
- notifyDeleteIterator(g, WrappedIterator.create(it).toList());
- }
-
- @Override
- public void notifyDeleteIterator(final Graph g, final List<Triple> triples) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyDeleteIterator(securedGraph, triples.iterator());
- }
- else {
- sgl.notifyDeleteIterator(g, triples.iterator());
- }
- }
- }
-
- @Override
- public void notifyDeleteList(final Graph g, final List<Triple> L) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyDeleteList(securedGraph, L);
- }
- else {
- sgl.notifyDeleteList(g, L);
- }
- }
- }
-
- @Override
- public void notifyDeleteTriple(final Graph g, final Triple t) {
- final boolean wrap = baseGraph.equals(g);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyDeleteTriple(securedGraph, t);
- }
- else {
- sgl.notifyDeleteTriple(g, t);
- }
- }
- }
-
- @Override
- public void notifyEvent(final Graph source, final Object value) {
- if ((source instanceof SecuredGraph) && securedGraph.equals(source)) {
- baseGraph.getEventManager().notifyEvent(baseGraph, value);
- }
- else {
-
- final boolean wrap = baseGraph.equals(source);
-
- for (final SecuredGraphListener sgl : getListenerCollection()) {
- if (wrap) {
- sgl.notifyEvent(securedGraph, value);
- }
- else {
- sgl.notifyEvent(source, value);
- }
- }
- }
- }
-
- @Override
- public synchronized GraphEventManager register(final GraphListener listener) {
- Stack<SecuredGraphListener> sgl = listenerMap.get(listener);
- if (sgl == null) {
- sgl = new Stack<SecuredGraphListener>();
- }
- sgl.push(new SecuredGraphListener(listener));
- listenerMap.put(listener, sgl);
- return this;
- }
-
- @Override
- public synchronized GraphEventManager unregister(
- final GraphListener listener) {
- final Stack<SecuredGraphListener> sgl = listenerMap.get(listener);
- if (sgl != null) {
- if (sgl.size() == 1) {
- listenerMap.remove(listener);
- }
- else {
- sgl.pop();
- listenerMap.put(listener, sgl);
- }
- }
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/SecuredPrefixMapping.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredPrefixMapping.java b/jena-security/src/main/java/org/apache/jena/security/graph/SecuredPrefixMapping.java
deleted file mode 100644
index 61c2544..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/SecuredPrefixMapping.java
+++ /dev/null
@@ -1,133 +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.graph;
-
-import java.util.Map;
-
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.impl.SecuredItem;
-import org.apache.jena.shared.PrefixMapping ;
-
-/**
- * The interface for secured PrefixMapping instances.
- *
- * Use the SecuredPrefixMapping.Factory to create instances
- */
-public interface SecuredPrefixMapping extends PrefixMapping, SecuredItem
-{
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String expandPrefix( final String prefixed )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public Map<String, String> getNsPrefixMap() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getNsPrefixURI( final String prefix )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getNsURIPrefix( final String uri )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredPrefixMapping lock() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String qnameFor( final String uri ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredPrefixMapping removeNsPrefix( final String prefix )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean samePrefixMappingAs( final PrefixMapping other )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredPrefixMapping setNsPrefix( final String prefix,
- final String uri ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredPrefixMapping setNsPrefixes( final Map<String, String> map )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredPrefixMapping setNsPrefixes( final PrefixMapping other )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String shortForm( final String uri ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredPrefixMapping withDefaultMappings( final PrefixMapping map )
- throws AccessDeniedException;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/impl/Factory.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/impl/Factory.java b/jena-security/src/main/java/org/apache/jena/security/graph/impl/Factory.java
deleted file mode 100644
index d66d46e..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/impl/Factory.java
+++ /dev/null
@@ -1,129 +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.graph.impl;
-
-import org.apache.jena.graph.BulkUpdateHandler ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.graph.SecuredBulkUpdateHandler;
-import org.apache.jena.security.graph.SecuredGraph;
-import org.apache.jena.security.graph.SecuredPrefixMapping;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemInvoker;
-import org.apache.jena.shared.PrefixMapping ;
-
-public class Factory
-{
-
- /**
- * Create an instance of the SecuredBulkUpdateHandler
- *
- * @param graph
- * The SecuredGraph that created the handler
- * @param handler
- * The unsecured handler from the base graph.
- * @return SecuredBulkUpdateHandler.
- */
- static SecuredBulkUpdateHandler getInstance( final SecuredGraphImpl graph,
- final Graph baseGraph, final BulkUpdateHandler handler )
- {
- final ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler> holder = new ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler>(
- handler);
-
- final SecuredBulkUpdateHandlerImpl checker = new SecuredBulkUpdateHandlerImpl(
- graph, baseGraph, holder);
-
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (handler instanceof SecuredBulkUpdateHandler)
- {
- if (checker.isEquivalent((SecuredBulkUpdateHandler) handler))
- {
- return (SecuredBulkUpdateHandler) handler;
- }
- }
-
- return holder.setSecuredItem(new SecuredItemInvoker(handler.getClass(),
- checker));
- }
-
- /**
- * Create an instance of SecuredPrefixMapping
- *
- * @param graph
- * The SecuredGraph that contains the prefixmapping.
- * @param prefixMapping
- * The prefixmapping returned from the base graph.
- * @return The SecuredPrefixMapping.
- */
- static SecuredPrefixMapping getInstance( final SecuredGraphImpl graph,
- final PrefixMapping prefixMapping )
- {
-
- final ItemHolder<PrefixMapping, SecuredPrefixMapping> holder = new ItemHolder<PrefixMapping, SecuredPrefixMapping>(
- prefixMapping);
- final SecuredPrefixMappingImpl checker = new SecuredPrefixMappingImpl(
- graph, holder);
- // if we are going to create a duplicate proxy just return this one.
- if (prefixMapping instanceof SecuredPrefixMapping)
- {
- if (checker.isEquivalent((SecuredPrefixMapping) prefixMapping))
- {
- return (SecuredPrefixMapping) prefixMapping;
- }
- }
-
- return holder.setSecuredItem(new SecuredItemInvoker(prefixMapping
- .getClass(), checker));
- }
-
- /**
- * 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, SecuredGraphImpl>(
- 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));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredBulkUpdateHandlerImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredBulkUpdateHandlerImpl.java b/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredBulkUpdateHandlerImpl.java
deleted file mode 100644
index 9d0d990..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredBulkUpdateHandlerImpl.java
+++ /dev/null
@@ -1,242 +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.graph.impl;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.jena.graph.BulkUpdateHandler ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.security.graph.SecuredBulkUpdateHandler;
-import org.apache.jena.security.graph.SecuredGraph;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-
-/**
- * Implementation of SecuredBulkUpdateHandler to be used by a SecuredItemInvoker
- * proxy.
- */
-@SuppressWarnings("deprecation")
-public class SecuredBulkUpdateHandlerImpl extends SecuredItemImpl implements
- SecuredBulkUpdateHandler
-{
- // the base graph for he secured graph.
- private final Graph baseGraph;
- // the graph this handler is for.
- private final SecuredGraph graph;
- // the item holder holding this SecuredBulkUpdateHandler.
- private final ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler> holder;
-
- /**
- * Constructor.
- *
- * @param graph
- * The graph handler is for.
- * @param holder
- * The item holder that will hold this SecuredBulkUpdateHandler.
- */
- SecuredBulkUpdateHandlerImpl( final SecuredGraphImpl graph,
- final Graph baseGraph,
- final ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler> holder )
- {
- super(graph, holder);
- this.holder = holder;
- this.graph = graph;
- this.baseGraph = baseGraph;
- }
-
- @Override
- public void add( final Graph g )
- {
- checkUpdate();
- final Graph g2 = g;
- if (!canCreate(Triple.ANY))
- {
- checkCreateTriples(g.find(Triple.ANY));
- }
- holder.getBaseItem().add(g2);
- }
-
- @Override
- @Deprecated
- public void add( final Graph g, final boolean withReifications )
- {
- checkUpdate();
-
- if (!canCreate(Triple.ANY))
- {
- checkCreateTriples(g.find(Triple.ANY));
- }
- holder.getBaseItem().add(g, withReifications);
- }
-
- @Override
- @Deprecated
- public void add( final Iterator<Triple> it )
- {
- checkUpdate();
- if (canCreate(Triple.ANY))
- {
- holder.getBaseItem().add(it);
- }
- else
- {
- final List<Triple> lst = WrappedIterator.create(it).toList();
- for (final Triple t : lst)
- {
- checkCreate(t);
- }
- holder.getBaseItem().add(lst.iterator());
- }
- }
-
- @Override
- @Deprecated
- public void add( final List<Triple> triples )
- {
- checkUpdate();
- if (!canCreate(Triple.ANY))
- {
- checkCreateTriples(WrappedIterator.create(triples.iterator()));
- }
- holder.getBaseItem().add(triples);
- }
-
- @Override
- @Deprecated
- public void add( final Triple[] triples )
- {
- checkUpdate();
- if (!canCreate(Triple.ANY))
- {
- checkCreateTriples(WrappedIterator.create(Arrays.asList(triples)
- .iterator()));
- }
- holder.getBaseItem().add(triples);
- }
-
- private void checkExtendedTripleDelete( final Triple t )
- {
- final ExtendedIterator<Triple> iter = baseGraph.find(t);
- try
- {
- while (iter.hasNext())
- {
- checkDelete(iter.next());
- }
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public void delete( final Graph g )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- checkDeleteTriples(g.find(Triple.ANY));
- }
- holder.getBaseItem().delete(g);
-
- }
-
- @Override
- @Deprecated
- public void delete( final Graph g, final boolean withReifications )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- checkDeleteTriples(g.find(Triple.ANY));
- }
- holder.getBaseItem().delete(g, withReifications);
-
- }
-
- @Override
- @Deprecated
- public void delete( final Iterator<Triple> it )
- {
- checkUpdate();
- final List<Triple> lst = WrappedIterator.create(it).toList();
- if (!canDelete(Triple.ANY))
- {
- checkDeleteTriples(WrappedIterator.create(lst.iterator()));
- }
- holder.getBaseItem().delete(lst.iterator());
- }
-
- @Override
- @Deprecated
- public void delete( final List<Triple> triples )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- checkDeleteTriples(WrappedIterator.create(triples.iterator()));
- }
- holder.getBaseItem().delete(triples);
- }
-
- @Override
- @Deprecated
- public void delete( final Triple[] triples )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- checkDeleteTriples(WrappedIterator.create(Arrays.asList(triples)
- .iterator()));
- }
- holder.getBaseItem().delete(triples);
- }
-
- @Override
- public void remove( final Node s, final Node p, final Node o )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- // the remove can be a pattern so expand it.
- checkExtendedTripleDelete(new Triple(s, p, o));
- }
- holder.getBaseItem().remove(s, p, o);
- }
-
- @Override
- public void removeAll()
- {
- checkUpdate();
-
- if (!canDelete(Triple.ANY))
- {
- checkDeleteTriples(graph.find(Triple.ANY));
- }
-
- holder.getBaseItem().removeAll();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredGraphImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredGraphImpl.java b/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredGraphImpl.java
deleted file mode 100644
index 9725236..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredGraphImpl.java
+++ /dev/null
@@ -1,303 +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.graph.impl;
-
-import org.apache.jena.graph.* ;
-import org.apache.jena.security.SecurityEvaluator ;
-import org.apache.jena.security.SecurityEvaluator.Action ;
-import org.apache.jena.security.graph.* ;
-import org.apache.jena.security.impl.ItemHolder ;
-import org.apache.jena.security.impl.SecuredItem ;
-import org.apache.jena.security.impl.SecuredItemImpl ;
-import org.apache.jena.security.utils.PermTripleFilter ;
-import org.apache.jena.shared.AddDeniedException ;
-import org.apache.jena.shared.DeleteDeniedException ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-
-/**
- * Implementation of SecuredGraph to be used by a SecuredItemInvoker proxy.
- */
-public class SecuredGraphImpl extends SecuredItemImpl implements SecuredGraph
-{
-
- // the prefixMapping for this graph.
- private SecuredPrefixMapping prefixMapping;
- // the item holder that contains this SecuredGraph
- private final ItemHolder<Graph, SecuredGraphImpl> holder;
-
- private final SecuredGraphEventManager eventManager;
-
- /**
- * Constructor
- *
- * @param securityEvaluator
- * The security evaluator to use
- * @param graphIRI
- * The IRI for the graph
- * @param holder
- * The item holder that will contain this SecuredGraph.
- */
- SecuredGraphImpl( final SecuredItem securedItem,
- final ItemHolder<Graph, SecuredGraphImpl> holder )
- {
- super(securedItem, holder);
- this.holder = holder;
- this.eventManager = new SecuredGraphEventManager(this,
- holder.getBaseItem(), holder.getBaseItem().getEventManager());
- }
-
- SecuredGraphImpl( final SecurityEvaluator securityEvaluator,
- final String modelURI,
- final ItemHolder<Graph, SecuredGraphImpl> holder )
- {
- super(securityEvaluator, modelURI, holder);
- this.holder = holder;
- this.eventManager = new SecuredGraphEventManager(this,
- holder.getBaseItem(), holder.getBaseItem().getEventManager());
- }
-
- @Override
- public void add( final Triple t ) throws AddDeniedException
- {
- checkUpdate();
- checkCreate(t);
- holder.getBaseItem().add(t);
- }
-
- @Override
- public void close()
- {
- holder.getBaseItem().close();
- }
-
- @Override
- public boolean contains( final Node s, final Node p, final Node o )
- {
- return contains(new Triple(s, p, o));
- }
-
- @Override
- public boolean contains( final Triple t )
- {
- checkRead();
- if (canRead(t))
- {
- return holder.getBaseItem().contains(t);
- }
- final ExtendedIterator<Triple> iter = holder.getBaseItem().find(t);
- try
- {
- while (iter.hasNext())
- {
- if (canRead(iter.next()))
- {
- return true;
- }
- }
- return false;
- }
- finally
- {
- iter.close();
- }
-
- }
-
- private synchronized void createPrefixMapping()
- {
- if (prefixMapping == null)
- {
- prefixMapping = org.apache.jena.security.graph.impl.Factory
- .getInstance(this, holder.getBaseItem().getPrefixMapping());
- }
- }
-
- @Override
- public void delete( final Triple t ) throws DeleteDeniedException
- {
- checkUpdate();
- checkDelete(t);
- holder.getBaseItem().delete(t);
- }
-
- @Override
- public boolean dependsOn( final Graph other )
- {
- checkRead();
- if (other.equals(holder.getBaseItem()))
- {
- return true;
- }
- return holder.getBaseItem().dependsOn(other);
- }
-
- @Override
- public ExtendedIterator<Triple> find( final Node s, final Node p,
- final Node o )
- {
- checkRead();
- ExtendedIterator<Triple> retval = holder.getBaseItem().find(s, p, o);
- if (!canRead(Triple.ANY))
- {
- retval = retval.filterKeep(new PermTripleFilter(Action.Read, this));
- }
- return retval;
- }
-
- /** @deprecated Use/implement {@link #find(Triple)} */
- @Deprecated
- @Override
- public ExtendedIterator<Triple> find( final TripleMatch m ) {
- return find(Triple.createMatch(m.getMatchSubject(),
- m.getMatchPredicate(),
- m.getMatchObject())) ;
- }
-
- @Override
- public ExtendedIterator<Triple> find( final Triple m )
- {
- checkRead();
- ExtendedIterator<Triple> retval = holder.getBaseItem().find(m);
- if (!canRead(Triple.ANY))
- {
- retval = retval.filterKeep(new PermTripleFilter(Action.Read, this));
- }
- return retval;
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public SecuredBulkUpdateHandler getBulkUpdateHandler()
- {
- return org.apache.jena.security.graph.impl.Factory.getInstance(this,
- holder.getBaseItem(), holder.getBaseItem()
- .getBulkUpdateHandler());
- }
-
- @Override
- public SecuredCapabilities getCapabilities()
- {
- return new SecuredCapabilities(getSecurityEvaluator(), getModelIRI(),
- holder.getBaseItem().getCapabilities());
- }
-
- @Override
- public SecuredGraphEventManager getEventManager()
- {
- return eventManager;
- }
-
- @Override
- public SecuredPrefixMapping getPrefixMapping()
- {
- if (prefixMapping == null)
- {
- createPrefixMapping();
- }
- return prefixMapping;
- }
-
- @Override
- public GraphStatisticsHandler getStatisticsHandler()
- {
- checkRead();
- return holder.getBaseItem().getStatisticsHandler();
- }
-
- @Override
- public TransactionHandler getTransactionHandler()
- {
- return holder.getBaseItem().getTransactionHandler();
- }
-
- @Override
- public boolean isClosed()
- {
- return holder.getBaseItem().isClosed();
- }
-
- @Override
- public boolean isEmpty()
- {
- checkRead();
- return holder.getBaseItem().isEmpty();
- }
-
- @Override
- public boolean isIsomorphicWith( final Graph g )
- {
- checkRead();
- if (g.size() != holder.getBaseItem().size())
- {
- return false;
- }
- final Triple t = new Triple(Node.ANY, Node.ANY, Node.ANY);
- if (!canRead(t))
- {
- final ExtendedIterator<Triple> iter = g.find(t);
- while (iter.hasNext())
- {
- checkRead(iter.next());
- }
- }
- return holder.getBaseItem().isIsomorphicWith(g);
- }
-
- @Override
- public int size()
- {
- checkRead();
- return holder.getBaseItem().size();
- }
-
- @Override
- public void clear()
- {
- checkUpdate();
- if (! canDelete( Triple.ANY ))
- {
- ExtendedIterator<Triple> iter = holder.getBaseItem().find( Triple.ANY );
- while (iter.hasNext())
- {
- checkDelete( iter.next() );
- }
- }
- holder.getBaseItem().clear();
- }
-
- @Override
- public void remove( Node s, Node p, Node o )
- {
- checkUpdate();
- Triple t = new Triple( s, p, o );
- if (t.isConcrete())
- {
- checkDelete( t );
- }
- else
- {
- ExtendedIterator<Triple> iter = holder.getBaseItem().find( Triple.ANY );
- while (iter.hasNext())
- {
- checkDelete( iter.next() );
- }
- }
- holder.getBaseItem().remove(s, p, o);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredPrefixMappingImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredPrefixMappingImpl.java b/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredPrefixMappingImpl.java
deleted file mode 100644
index 46d9657..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/impl/SecuredPrefixMappingImpl.java
+++ /dev/null
@@ -1,167 +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.graph.impl;
-
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.jena.security.graph.SecuredPrefixMapping;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.shared.impl.PrefixMappingImpl ;
-
-/**
- * Implementation of SecuredPrefixMapping to be used by a SecuredItemInvoker
- * proxy.
- */
-public class SecuredPrefixMappingImpl extends SecuredItemImpl implements
- SecuredPrefixMapping
-{
- // the item holder that holds this SecuredPrefixMapping
- private final ItemHolder<PrefixMapping, SecuredPrefixMapping> holder;
-
- /**
- * Constructor
- *
- * @param graph
- * The Secured graph this mapping is for.
- * @param holder
- * The item holder that will contain this SecuredPrefixMapping.
- */
- SecuredPrefixMappingImpl( final SecuredGraphImpl graph,
- final ItemHolder<PrefixMapping, SecuredPrefixMapping> holder )
- {
- super(graph, holder);
- this.holder = holder;
- }
-
- @Override
- public String expandPrefix( final String prefixed )
- {
- checkRead();
- return holder.getBaseItem().expandPrefix(prefixed);
- }
-
- @Override
- public Map<String, String> getNsPrefixMap()
- {
- checkRead();
- return holder.getBaseItem().getNsPrefixMap();
- }
-
- @Override
- public String getNsPrefixURI( final String prefix )
- {
- checkRead();
- return holder.getBaseItem().getNsPrefixURI(prefix);
- }
-
- @Override
- public String getNsURIPrefix( final String uri )
- {
- checkRead();
- return holder.getBaseItem().getNsURIPrefix(uri);
- }
-
- @Override
- public SecuredPrefixMapping lock()
- {
- checkUpdate();
- holder.getBaseItem().lock();
- return holder.getSecuredItem();
- }
-
- @Override
- public String qnameFor( final String uri )
- {
- checkRead();
- return holder.getBaseItem().qnameFor(uri);
- }
-
- @Override
- public SecuredPrefixMapping removeNsPrefix( final String prefix )
- {
- checkUpdate();
- holder.getBaseItem().removeNsPrefix(prefix);
- return holder.getSecuredItem();
- }
-
- @Override
- public boolean samePrefixMappingAs( final PrefixMapping other )
- {
- checkRead();
- return holder.getBaseItem().samePrefixMappingAs(other);
- }
-
- @Override
- public SecuredPrefixMapping setNsPrefix( final String prefix,
- final String uri )
- {
- checkUpdate();
- holder.getBaseItem().setNsPrefix(prefix, uri);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredPrefixMapping setNsPrefixes( final Map<String, String> map )
- {
- checkUpdate();
- holder.getBaseItem().setNsPrefixes(map);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredPrefixMapping setNsPrefixes( final PrefixMapping other )
- {
- checkUpdate();
- holder.getBaseItem().setNsPrefixes(other);
- return holder.getSecuredItem();
- }
-
- @Override
- public String shortForm( final String uri )
- {
- checkRead();
- return holder.getBaseItem().shortForm(uri);
- }
-
- @Override
- public SecuredPrefixMapping withDefaultMappings( final PrefixMapping map )
- {
- // mapping only updates if there are map entries to add. Since this gets called
- // when we are doing deep triple checks while writing we need to attempt the
- // update only if there are new updates to add.
-
- PrefixMapping m = holder.getBaseItem();
- PrefixMappingImpl pm = new PrefixMappingImpl();
- for ( Entry<String, String> e : map.getNsPrefixMap().entrySet())
- {
- if (m.getNsPrefixURI(e.getKey()) == null && m.getNsURIPrefix(e.getValue()) == null )
- {
- pm.setNsPrefix( e.getKey(), e.getValue() );
- }
- }
- if ( !pm.getNsPrefixMap().isEmpty())
- {
- checkUpdate();
- holder.getBaseItem().withDefaultMappings(pm);
- }
- return holder.getSecuredItem();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/graph/package-info.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/graph/package-info.java b/jena-security/src/main/java/org/apache/jena/security/graph/package-info.java
deleted file mode 100644
index d787688..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/graph/package-info.java
+++ /dev/null
@@ -1,50 +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.
- */
-/**
- * Secured implementation of the Graph interface and associated classes.
- * <p>
- *
- * The SecurityEvaluator class must be implemented. This class provides the interface to the
- * authentication results (e.g. getPrincipal())) and the authorization system.
- * </p><p>
- * Create a SecuredGraph by calling Factory.getInstance( SecurityEvaluator, String, Graph );
- * Create a SecuredModel by calling Factory.getInstance( SecurityEvaluator, String, Model )
- * or ModelFactory.createModelForGraph( SecuredGraph );
- * </p><p>
- * NOTE: when creating a model by wrapping a secured graph (e.g.
- * ModelFactory.createModelForGraph( SecuredGraph );) the resulting Model does not
- * have the same security requirements that the standard secured model does.
- * </p><p>
- * For instance when creating a list on a secured model calling model.createList( RDFNode[] );
- * The standard secured model verifies that the user
- * has the right to update the triples and allows or denies the entire operation accordingly.
- * The wrapped secured graph does not have visibility
- * to the createList() command and can only operate on the instructions issued by the
- * model.createList() implementation. In the standard implementation
- * the model requests the graph to delete one triple and then insert another.
- * Thus the user must have delete and add permissions, not the update permission.
- * </p><p>
- * There are several other cases where the difference in the layer can trip up the security system.
- * In all known cases the result is a tighter
- * security definition than was requested. For simplicity sake we recommend that the wrapped
- * secured graph only be used in cases where access to the
- * graph as a whole is granted/denied. In these cases the user either has all CRUD capabilities or
- * none.
- * </p>
- */
-package org.apache.jena.security.graph;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/impl/CachedSecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/impl/CachedSecurityEvaluator.java b/jena-security/src/main/java/org/apache/jena/security/impl/CachedSecurityEvaluator.java
deleted file mode 100644
index ffc2868..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/impl/CachedSecurityEvaluator.java
+++ /dev/null
@@ -1,90 +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.impl;
-
-import java.util.Set;
-
-import org.apache.jena.security.SecurityEvaluator;
-
-/**
- * A SecurityEvaluator that can be cached for later use.
- */
-public class CachedSecurityEvaluator implements SecurityEvaluator {
- private final SecurityEvaluator wrapped;
- private final Object origPrincipal;
-
- /**
- *
- * @param wrapped
- * @param runAs
- */
- public CachedSecurityEvaluator(final SecurityEvaluator wrapped,
- final Object runAs) {
- this.origPrincipal = runAs;
- this.wrapped = wrapped;
- }
-
- @Override
- public boolean evaluate(final Object principal, final Action action,
- final SecNode graphIRI) {
- return wrapped.evaluate(principal, action, graphIRI);
- }
-
- @Override
- public boolean evaluate(final Object principal, final Action action,
- final SecNode graphIRI, final SecTriple triple) {
- return wrapped.evaluate(principal, action, graphIRI, triple);
- }
-
- @Override
- public boolean evaluate(final Object principal, final Set<Action> actions,
- final SecNode graphIRI) {
- return wrapped.evaluate(principal, actions, graphIRI);
- }
-
- @Override
- public boolean evaluate(final Object principal, final Set<Action> actions,
- final SecNode graphIRI, final SecTriple triple) {
- return wrapped.evaluate(principal, actions, graphIRI, triple);
- }
-
- @Override
- public boolean evaluateAny(final Object principal,
- final Set<Action> actions, final SecNode graphIRI) {
- return wrapped.evaluateAny(principal, actions, graphIRI);
- }
-
- @Override
- public boolean evaluateAny(final Object principal,
- final Set<Action> actions, final SecNode graphIRI,
- final SecTriple triple) {
- return wrapped.evaluateAny(principal, actions, graphIRI, triple);
- }
-
- @Override
- public boolean evaluateUpdate(final Object principal,
- final SecNode graphIRI, final SecTriple from, final SecTriple to) {
- return wrapped.evaluateUpdate(principal, graphIRI, from, to);
- }
-
- @Override
- public Object getPrincipal() {
- return origPrincipal;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/impl/ItemHolder.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/impl/ItemHolder.java b/jena-security/src/main/java/org/apache/jena/security/impl/ItemHolder.java
deleted file mode 100644
index 0262001..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/impl/ItemHolder.java
+++ /dev/null
@@ -1,117 +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.impl;
-
-import java.lang.reflect.Proxy;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.apache.commons.lang3.ClassUtils;
-
-/**
- * A class that holds the original item and the secured version of it.
- *
- * This class is used by the Invoker to return secured versions of the object
- * during
- * calls that return the called class for cascading.
- *
- * @param <Base>
- * The base class that is being secured
- * @param <Secured>
- * The implementation (proxy) of the secured class.
- */
-public class ItemHolder<Base, Secured extends SecuredItem>
-{
- /**
- * The base item that is being secured
- */
- private final Base baseItem;
- /**
- * The proxy to the base class that implements the security.
- */
- private Secured securedItem;
-
- /**
- * Constructor.
- *
- * @param baseItem
- * The base item.
- */
- public ItemHolder( final Base baseItem )
- {
- super();
- this.baseItem = baseItem;
- }
-
- /**
- * Get the base item.
- *
- * This method is used in the proxy to get call to the underlying instance.
- *
- * @return The instance that is being protected.
- */
- public Base getBaseItem()
- {
- return baseItem;
- }
-
- /**
- * Get the secured item.
- *
- * This method is used in the invocation handler to get the instance of the
- * proxy that made the
- * on which a method call was made. Generally used in returing the original
- * object to support
- * cascading.
- *
- * @return the proxy.
- */
- public Secured getSecuredItem()
- {
- return securedItem;
- }
-
- /**
- * Creates the proxy, saves it as the securedItem and returns it.
- *
- * @param handler
- * The SecuredItemInvoker to create the proxy with.
- * @return The proxy.
- */
- @SuppressWarnings( "unchecked" )
- public final Secured setSecuredItem( final SecuredItemInvoker handler )
- {
- final Set<Class<?>> ifac = new LinkedHashSet<Class<?>>();
- if (baseItem.getClass().isInterface())
- {
- ifac.add(baseItem.getClass());
- }
- ifac.addAll(ClassUtils.getAllInterfaces(baseItem.getClass()));
- if (handler.securedItem.getClass().isInterface())
- {
- ifac.add(handler.securedItem.getClass());
- }
- ifac.addAll(ClassUtils.getAllInterfaces(handler.securedItem.getClass()));
-
- securedItem = (Secured) Proxy.newProxyInstance(
- SecuredItemImpl.class.getClassLoader(),
- ifac.toArray(new Class<?>[ifac.size()]), handler);
- return securedItem;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItem.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItem.java b/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItem.java
deleted file mode 100644
index 7c12d19..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItem.java
+++ /dev/null
@@ -1,185 +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.impl;
-
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.SecurityEvaluator.SecTriple;
-
-/**
- * The secured item interface is mixed into instances of secured objects by the
- * proxy. It provides the security context for the security checks as well as
- * several useful shorthand methods for common checks.
- */
-public interface SecuredItem
-{
-
- /**
- * Utilities for SecuredItem implementations.
- */
- public static class Util
- {
- /**
- * Secured items are equivalent if their security evaluators and
- * modelIRIs are equal.
- *
- * @param si1
- * A secured item to check
- * @param si2
- * A second secured item to check
- * @return true if si1 is equivalent to si2.
- */
- public static boolean isEquivalent( final SecuredItem si1,
- final SecuredItem si2 )
- {
- return si1.getSecurityEvaluator()
- .equals(si2.getSecurityEvaluator())
- && si1.getModelIRI().equals(si2.getModelIRI());
- }
- }
-
- /**
- * @return true if the securedModel allows items to to be created.
- */
- public boolean canCreate();
-
- /**
- * Return true if the triple can be created.
- * If any s,p or o is SecNode.ANY then this method must return false if
- * there
- * are
- * any restrictions where the remaining nodes and held constant and the ANY
- * node
- * is allowed to vary.
- *
- * See canRead(SecTriple t)
- *
- * @param t
- * The triple to check
- * @return true if the triple can be created.
- */
- public boolean canCreate( SecTriple t );
-
- /**
- * @return true if the securedModel allows items to to be deleted.
- */
- public boolean canDelete();
-
- /**
- * Return true if the triple can be deleted.
- * If any s,p or o is SecNode.ANY then this method must return false if
- * there
- * are
- * any restrictions where the remaining nodes and held constant and the ANY
- * node
- * is allowed to vary.
- *
- * See canRead(SecTriple t)
- *
- * @param t
- * The triple to check
- * @return true if the triple can be deleted.
- */
- public boolean canDelete( SecTriple t );
-
- /**
- * @return true if the securedModel allows items to to be read.
- */
- public boolean canRead();
-
- /**
- * Return true if the triple can be read.
- * If any s,p or o is SecNode.ANY then this method must return false if
- * there
- * are
- * any restrictions where the remaining nodes and held constant and the ANY
- * node
- * is allowed to vary.
- *
- * (S, P, O) check if S,P,O can be read.
- * (S, P, ANY) check if there are any S,P,x restrictions.
- * (S, ANY, P) check if there are any S,x,P restrictions.
- * (ANY, ANY, ANY) check if there are any restricitons on reading.
- *
- * @param t
- * The triple to check
- * @return true if the triple can be read.
- */
- public boolean canRead( SecTriple t );
-
- /**
- * @return true if the securedModel allows items to to be updated.
- */
- public boolean canUpdate();
-
- /**
- * Return true if the triple can be updated.
- * If any s,p or o is SecNode.ANY then this method must return false if
- * there
- * are
- * any restrictions where the remaining nodes and held constant and the ANY
- * node
- * is allowed to vary.
- *
- * See canRead(SecTriple t)
- *
- * @param from
- * The triple that will be changed
- * @param to
- * The resulting triple.
- * @return true if the from triple can be updated as the to triple.
- */
- public boolean canUpdate( SecTriple from, SecTriple to );
-
- @Override
- public boolean equals( Object o );
-
- /**
- * @return the base item that is being secured.
- */
- public Object getBaseItem();
-
- /**
- * @return The IRI of the securedModel that the item belongs to.
- */
- public String getModelIRI();
-
- /**
- * @return The node represnetation of the securedModel IRI.
- */
- public SecNode getModelNode();
-
- /**
- * The SecurityEvaluator implementation that is being used to determine
- * access.
- *
- * @return The SecurityEvaluator implementation.
- */
- public SecurityEvaluator getSecurityEvaluator();
-
- /**
- * Return true if this secured item is equivalent to another secured item.
- * Generally implemented by calling SecuredItem.Util.isEquivalent
- *
- * @param securedItem
- * the other secured item.
- * @return True if they are equivalent, false otherwise.
- */
- public boolean isEquivalent( SecuredItem securedItem );
-
-}
\ No newline at end of file
[20/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredUnsupportedPolymorphismException.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredUnsupportedPolymorphismException.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredUnsupportedPolymorphismException.java
new file mode 100644
index 0000000..0fe619c
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredUnsupportedPolymorphismException.java
@@ -0,0 +1,36 @@
+/*
+ * 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.model;
+
+import org.apache.jena.enhanced.UnsupportedPolymorphismException ;
+import org.apache.jena.security.model.impl.SecuredRDFNodeImpl;
+
+/**
+ * An extension to the UnsupportedPolymorphismException to handle
+ * secured polymorphic changes.
+ */
+public class SecuredUnsupportedPolymorphismException extends
+ UnsupportedPolymorphismException
+{
+
+ public SecuredUnsupportedPolymorphismException(
+ final SecuredRDFNodeImpl node, final Class<?> type )
+ {
+ super( node, node.getModel() != null, type);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredAltImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredAltImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredAltImpl.java
new file mode 100644
index 0000000..0d082fa
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredAltImpl.java
@@ -0,0 +1,339 @@
+/*
+ * 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.model.impl;
+
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemInvoker;
+import org.apache.jena.security.model.SecuredAlt;
+import org.apache.jena.security.model.SecuredBag;
+import org.apache.jena.security.model.SecuredLiteral;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredRDFNode;
+import org.apache.jena.security.model.SecuredResource;
+import org.apache.jena.security.model.SecuredSeq;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+
+/**
+ * Implementation of SecuredAlt to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt
+{
+ /**
+ * Get an instance of SecuredAlt.
+ *
+ * @param securedModel
+ * the Secured Model to use.
+ * @param alt
+ * The Alt to be secured.
+ * @return The secured Alt instance.
+ */
+ public static SecuredAlt getInstance( final SecuredModel securedModel,
+ final Alt alt )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (alt == null)
+ {
+ throw new IllegalArgumentException("Alt may not be null");
+ }
+ final ItemHolder<Alt, SecuredAlt> holder = new ItemHolder<Alt, SecuredAlt>(
+ alt);
+ final SecuredAltImpl checker = new SecuredAltImpl(securedModel, holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (alt instanceof SecuredAlt)
+ {
+ if (checker.isEquivalent((SecuredAlt) alt))
+ {
+ return (SecuredAlt) alt;
+ }
+ }
+ return holder.setSecuredItem(new SecuredItemInvoker(alt.getClass(),
+ checker));
+ }
+
+ // The item holder holding this SecuredAlt
+ private final ItemHolder<? extends Alt, ? extends SecuredAlt> holder;
+
+ /**
+ * Constructor.
+ *
+ * @param securedModel
+ * the securedModel to use.
+ * @param holder
+ * The item holder that will hold this SecuredAlt.
+ */
+ protected SecuredAltImpl( final SecuredModel securedModel,
+ final ItemHolder<? extends Alt, ? extends SecuredAlt> holder )
+ {
+ super(securedModel, holder);
+ this.holder = holder;
+ }
+
+ @Override
+ public SecuredRDFNode getDefault()
+ {
+ // getDefaultStatement() calls checkRead
+ return SecuredRDFNodeImpl.getInstance(getModel(), getDefaultStatement()
+ .getObject());
+ }
+
+ @Override
+ public SecuredAlt getDefaultAlt()
+ {
+ // getDefaultStatement() calls checkRead
+ return SecuredAltImpl.getInstance(getModel(), getDefaultStatement()
+ .getAlt());
+ }
+
+ @Override
+ public SecuredBag getDefaultBag()
+ {
+ // getDefaultStatement() calls checkRead
+ return SecuredBagImpl.getInstance(getModel(), getDefaultStatement()
+ .getBag());
+ }
+
+ @Override
+ public boolean getDefaultBoolean()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getBoolean();
+ }
+
+ @Override
+ public byte getDefaultByte()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getByte();
+ }
+
+ @Override
+ public char getDefaultChar()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getChar();
+ }
+
+ @Override
+ public double getDefaultDouble()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getDouble();
+ }
+
+ @Override
+ public float getDefaultFloat()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getFloat();
+ }
+
+ @Override
+ public int getDefaultInt()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getInt();
+ }
+
+ @Override
+ public String getDefaultLanguage()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getLanguage();
+ }
+
+ @Override
+ public SecuredLiteral getDefaultLiteral()
+ {
+ // getDefaultStatement() calls checkRead
+ return SecuredLiteralImpl.getInstance(getModel(), getDefaultStatement()
+ .getLiteral());
+ }
+
+ @Override
+ public long getDefaultLong()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getLong();
+ }
+
+ @Override
+ public SecuredResource getDefaultResource()
+ {
+ // getDefaultStatement() calls checkRead
+ return SecuredResourceImpl.getInstance(getModel(),
+ getDefaultStatement().getResource());
+ }
+
+ @Override
+ @Deprecated
+ public SecuredResource getDefaultResource( final ResourceF f )
+ {
+ // getDefaultStatement() calls checkRead
+ return SecuredResourceImpl.getInstance(getModel(),
+ getDefaultStatement().getResource(f));
+ }
+
+ @Override
+ public SecuredSeq getDefaultSeq()
+ {
+ // getDefaultStatement() calls checkRead
+ return SecuredSeqImpl.getInstance(getModel(), getDefaultStatement()
+ .getSeq());
+ }
+
+ @Override
+ public short getDefaultShort()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getShort();
+
+ }
+
+ private Statement getDefaultStatement()
+ {
+ checkRead();
+ final ExtendedIterator<Statement> iter = getStatementIterator(Action.Read);
+ try
+ {
+ if (iter.hasNext())
+ {
+ return iter.next();
+ }
+ throw new AltHasNoDefaultException(this);
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public String getDefaultString()
+ {
+ // getDefaultStatement() calls checkRead
+ return getDefaultStatement().getString();
+
+ }
+
+ /*
+ * private SecTriple getDefaultTriple()
+ * {
+ * final StmtIterator iter = holder.getBaseItem().getModel()
+ * .listStatements(this, RDF.li(1), (RDFNode) null);
+ * try
+ * {
+ * return iter.hasNext() ? iter.nextStatement().asTriple() : null;
+ * }
+ * finally
+ * {
+ * iter.close();
+ * }
+ *
+ * }
+ *
+ * private SecTriple getNewTriple( final SecTriple t, final Object o )
+ * {
+ * return new SecTriple(t.getSubject(), t.getPredicate(),
+ * SecNode.createLiteral(
+ * String.valueOf(o), "", false));
+ * }
+ */
+ @Override
+ public SecuredAlt setDefault( final boolean o )
+ {
+ return setDefault( asObject( o ));
+ }
+
+ @Override
+ public SecuredAlt setDefault( final char o )
+ {
+ return setDefault( asObject( o ));
+ }
+
+ @Override
+ public SecuredAlt setDefault( final double o )
+ {
+ return setDefault( asObject( o ));
+ }
+
+ @Override
+ public SecuredAlt setDefault( final float o )
+ {
+ return setDefault( asObject( o ));
+ }
+
+ @Override
+ public SecuredAlt setDefault( final long o )
+ {
+ return setDefault( asObject( o ));
+ }
+
+ @Override
+ public SecuredAlt setDefault( final Object o )
+ {
+ return setDefault( asObject( o ));
+ }
+
+ @Override
+ public SecuredAlt setDefault( final RDFNode o )
+ {
+ checkUpdate();
+ final ExtendedIterator<Statement> iter = getStatementIterator(Action.Read);
+ try {
+ if (iter.hasNext())
+ {
+ final Statement stmt = iter.next();
+ final Triple t = stmt.asTriple();
+ final Triple t2 = new Triple(t.getSubject(), t.getPredicate(),
+ o.asNode());
+ checkUpdate(t, t2);
+ stmt.changeObject(o);
+ return holder.getSecuredItem();
+ }
+ else
+ {
+ add( o );
+ return holder.getSecuredItem();
+ }
+ }
+ finally {
+ iter.close();
+ }
+
+ }
+
+ @Override
+ public SecuredAlt setDefault( final String o )
+ {
+ return setDefault( asLiteral( o, "" ));
+ }
+
+ @Override
+ public SecuredAlt setDefault( final String o, final String l )
+ {
+ return setDefault( asLiteral( o, l) );
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredBagImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredBagImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredBagImpl.java
new file mode 100644
index 0000000..9c8b3a1
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredBagImpl.java
@@ -0,0 +1,81 @@
+/*
+ * 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.model.impl;
+
+import org.apache.jena.rdf.model.Bag ;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemInvoker;
+import org.apache.jena.security.model.SecuredBag;
+import org.apache.jena.security.model.SecuredModel;
+
+/**
+ * Implementation of SecuredBag to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredBagImpl extends SecuredContainerImpl implements SecuredBag
+{
+ /**
+ * Get an instance of SecuredBag
+ *
+ * @param securedModel
+ * The Secured Model to use.
+ * @param bag
+ * The bag to secure
+ * @return The SecuredBag
+ */
+ public static SecuredBag getInstance( final SecuredModel securedModel,
+ final Bag bag )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (bag == null)
+ {
+ throw new IllegalArgumentException("Bag may not be null");
+ }
+ final ItemHolder<Bag, SecuredBag> holder = new ItemHolder<Bag, SecuredBag>(
+ bag);
+ final SecuredBagImpl checker = new SecuredBagImpl(securedModel, holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (bag instanceof SecuredBag)
+ {
+ if (checker.isEquivalent((SecuredBag) bag))
+ {
+ return (SecuredBag) bag;
+ }
+ }
+ return holder.setSecuredItem(new SecuredItemInvoker(bag.getClass(),
+ checker));
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param securedModel
+ * The Secured Model to use.
+ * @param holder
+ * The holder that will contain this SecuredBag.
+ */
+ protected SecuredBagImpl( final SecuredModel securedModel,
+ final ItemHolder<? extends Bag, ? extends SecuredBag> holder )
+ {
+ super(securedModel, holder);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredContainerImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredContainerImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredContainerImpl.java
new file mode 100644
index 0000000..2de34fa
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredContainerImpl.java
@@ -0,0 +1,576 @@
+/*
+ * 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.model.impl;
+
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemInvoker;
+import org.apache.jena.security.model.SecuredContainer;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.utils.ContainerFilter;
+import org.apache.jena.security.utils.PermStatementFilter;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.Map1 ;
+import org.apache.jena.util.iterator.WrappedIterator ;
+import org.apache.jena.vocabulary.RDF ;
+
+/**
+ * Implementation of SecuredContainer to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredContainerImpl extends SecuredResourceImpl implements
+ SecuredContainer
+{
+ /**
+ * Constructor
+ *
+ * @param securedModel
+ * the Secured Model to use.
+ * @param container
+ * The container to secure.
+ * @return The SecuredResource
+ */
+ public static SecuredContainer getInstance(
+ final SecuredModel securedModel, final Container container )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (container == null)
+ {
+ throw new IllegalArgumentException("Container may not be null");
+ }
+
+ // check that resource has a securedModel.
+ Container goodContainer = container;
+ if (goodContainer.getModel() == null)
+ {
+ container.asNode();
+ goodContainer = securedModel.createBag();
+ }
+
+ final ItemHolder<Container, SecuredContainer> holder = new ItemHolder<Container, SecuredContainer>(
+ goodContainer);
+
+ final SecuredContainerImpl checker = new SecuredContainerImpl(
+ securedModel, holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (goodContainer instanceof SecuredContainer)
+ {
+ if (checker.isEquivalent((SecuredContainer) goodContainer))
+ {
+ return (SecuredContainer) goodContainer;
+ }
+ }
+
+ return holder.setSecuredItem(new SecuredItemInvoker(container
+ .getClass(), checker));
+
+ }
+
+ // the item holder that contains this SecuredContainer.
+ private final ItemHolder<? extends Container, ? extends SecuredContainer> holder;
+
+ /**
+ * Constructor
+ *
+ * @param securedModel
+ * the Secured Model to use.
+ * @param holder
+ * The item holder that will contain this SecuredContainer
+ */
+ protected SecuredContainerImpl(
+ final SecuredModel securedModel,
+ final ItemHolder<? extends Container, ? extends SecuredContainer> holder )
+ {
+ super(securedModel, holder);
+ this.holder = holder;
+ // listener=new ChangeListener();
+ // holder.getBaseItem().getModel().register(listener);
+ }
+
+ protected RDFNode asObject( Object o )
+ {
+ return o instanceof RDFNode ? (RDFNode) o : ResourceFactory.createTypedLiteral( o );
+ }
+
+ protected RDFNode asLiteral( String o, String l )
+ {
+ return holder.getBaseItem().getModel().createLiteral(o, l);
+ }
+
+ @Override
+ public SecuredContainer add( final boolean o )
+ {
+ return add( asObject( o ));
+ }
+
+ @Override
+ public SecuredContainer add( final char o )
+ {
+ return add( asObject( o ));
+ }
+
+ @Override
+ public SecuredContainer add( final double o )
+ {
+ return add( asObject( o ));
+ }
+
+ @Override
+ public SecuredContainer add( final float o )
+ {
+ return add( asObject( o ));
+ }
+
+ @Override
+ public SecuredContainer add( final long o )
+ {
+ return add( asObject( o ));
+ }
+
+ @Override
+ public SecuredContainer add( final Object o )
+ {
+ return add( asObject( o ));
+ }
+
+ @Override
+ public SecuredContainer add( final RDFNode o )
+ {
+ checkUpdate();
+ final int pos = holder.getBaseItem().size();
+ checkAdd(pos, o.asNode());
+ holder.getBaseItem().add(o);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredContainer add( final String o )
+ {
+ return add( asLiteral( o, "" ));
+ }
+
+ @Override
+ public SecuredContainer add( final String o, final String l )
+ {
+ return add( asLiteral( o, l));
+ }
+
+ protected void checkAdd( final int pos, final Literal literal )
+ {
+ checkAdd(pos, literal.asNode());
+ }
+
+ protected void checkAdd( final int pos, final Node node )
+ {
+ checkCreate(new Triple(holder.getBaseItem().asNode(), RDF.li(pos)
+ .asNode(), node));
+ }
+
+ @Override
+ public boolean contains( final boolean o )
+ {
+ return contains( asObject( o ) );
+ }
+
+ @Override
+ public boolean contains( final char o )
+ {
+ return contains( asObject( o ) );
+ }
+
+ @Override
+ public boolean contains( final double o )
+ {
+ return contains( asObject( o ) );
+ }
+
+ @Override
+ public boolean contains( final float o )
+ {
+ return contains( asObject( o ) );
+ }
+
+ @Override
+ public boolean contains( final long o )
+ {
+ return contains( asObject( o ) );
+ }
+
+ @Override
+ public boolean contains( final Object o )
+ {
+ return contains( asObject( o ) );
+ }
+
+ @Override
+ public boolean contains( final RDFNode o )
+ {
+ // iterator check reads
+ final SecuredNodeIterator<RDFNode> iter = iterator();
+ while (iter.hasNext())
+ {
+ if (iter.next().asNode().equals(o.asNode()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean contains( final String o )
+ {
+ return contains( asLiteral( o, "" ));
+ }
+
+ @Override
+ public boolean contains( final String o, final String l )
+ {
+ return contains( asLiteral( o, l ));
+ }
+
+ protected int getAddIndex()
+ {
+ int pos = -1;
+ final ExtendedIterator<Statement> iter = holder.getBaseItem()
+ .listProperties();
+ try
+ {
+ while (iter.hasNext())
+ {
+ pos = Math.max(pos, getIndex(iter.next().getPredicate()));
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ return pos + 1;
+ }
+
+ protected static int getIndex( final Property p )
+ {
+ if (p.getNameSpace().equals(RDF.getURI())
+ && p.getLocalName().startsWith("_"))
+ {
+ try
+ {
+ return Integer.parseInt(p.getLocalName().substring(1));
+ }
+ catch (final NumberFormatException e)
+ {
+ // acceptable;
+ }
+ }
+ return -1;
+ }
+
+ protected ExtendedIterator<Statement> getStatementIterator(
+ final Action perm )
+ {
+ return holder.getBaseItem().listProperties()
+ .filterKeep(new ContainerFilter())
+ .filterKeep(new PermStatementFilter(perm, this));
+ }
+
+ protected ExtendedIterator<Statement> getStatementIterator(
+ final Set<Action> perm )
+ {
+ return holder.getBaseItem().listProperties()
+ .filterKeep(new ContainerFilter())
+ .filterKeep(new PermStatementFilter(perm, this));
+ }
+
+ @Override
+ public boolean isAlt()
+ {
+ return holder.getBaseItem().isAlt();
+ }
+
+ @Override
+ public boolean isBag()
+ {
+ return holder.getBaseItem().isBag();
+ }
+
+ @Override
+ public boolean isSeq()
+ {
+ return holder.getBaseItem().isSeq();
+ }
+
+ @Override
+ public SecuredNodeIterator<RDFNode> iterator()
+ {
+ // listProperties calls checkRead();
+ SecuredStatementIterator iter = listProperties();
+ try {
+ SortedSet<Statement> result = new TreeSet<Statement>( new ContainerComparator() );
+ while (iter.hasNext()) {
+ Statement stmt = iter.next();
+ if (stmt.getPredicate().getOrdinal() > 0)
+ {
+ result.add( stmt );
+ }
+ }
+ return new SecuredNodeIterator<RDFNode>(getModel(), new StatementRemovingIterator(result.iterator()).mapWith( new NodeMap() ) );
+ }
+ finally {
+ iter.close();
+ }
+ }
+
+ @Override
+ public SecuredNodeIterator<RDFNode> iterator( final Set<Action> perms )
+ {
+ checkRead();
+ final Set<Action> permsCopy = new HashSet<Action>(perms);
+ permsCopy.add(Action.Read);
+ final ExtendedIterator<RDFNode> ni = getStatementIterator(perms)
+ .mapWith(new Map1<Statement, RDFNode>() {
+
+ @Override
+ public RDFNode map1( final Statement o )
+ {
+ return o.getObject();
+ }
+ });
+ return new SecuredNodeIterator<RDFNode>(getModel(), ni);
+
+ }
+
+ @Override
+ public SecuredContainer remove( final Statement s )
+ {
+ checkUpdate();
+ checkDelete(s.asTriple());
+ holder.getBaseItem().remove(s);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public int size()
+ {
+ checkRead();
+ return holder.getBaseItem().size();
+ }
+ /*
+ * private synchronized void resetIndexes()
+ * {
+ * indexes.clear();
+ * }
+ */
+ /*
+ /**
+ * find the position of i in the array
+ *
+ * @param i
+ * @return the position or x<0 if not found.
+ */
+ /*
+ * protected int mapValue( int i )
+ * {
+ * rebuildIndex();
+ * return Collections.binarySearch( indexes, i );
+ * }
+ *
+ * // return the value at position i
+ * protected int unmapValue( int i )
+ * {
+ * return indexes.get(i);
+ * }
+ *
+ *
+ * private synchronized void rebuildIndex()
+ * {
+ * if (indexes.isEmpty())
+ * {
+ * ExtendedIterator<Statement> iter = getStatementIterator( Action.Read );
+ * try {
+ * while (iter.hasNext())
+ * {
+ * indexes.add( getIndex( iter.next().getPredicate() ) );
+ * }
+ * }
+ * finally {
+ * iter.close();
+ * }
+ * Collections.sort(indexes);
+ * }
+ * }
+ *
+ * private class ChangeListener implements ModelChangedListener
+ * {
+ *
+ * private void checkStatement( Statement s )
+ * {
+ * if (indexes != null && s.getSubject().equals( holder.getBaseItem()))
+ * {
+ * resetIndexes();
+ * }
+ * }
+ *
+ * private void checkStatements( Iterator<Statement> iter )
+ * {
+ * while( indexes != null && iter.hasNext())
+ * {
+ * checkStatement( iter.next() );
+ * }
+ * }
+ *
+ * @Override
+ * public void addedStatement( Statement s )
+ * {
+ * checkStatement( s );
+ * }
+ *
+ * @Override
+ * public void addedStatements( Statement[] statements )
+ * {
+ * checkStatements( Arrays.asList(statements).iterator() );
+ * }
+ *
+ * @Override
+ * public void addedStatements( List<Statement> statements )
+ * {
+ * checkStatements( statements.iterator() );
+ * }
+ *
+ * @Override
+ * public void addedStatements( StmtIterator statements )
+ * {
+ * try {
+ * checkStatements( statements );
+ * }
+ * finally {
+ * statements.close();
+ * }
+ * }
+ *
+ * @Override
+ * public void addedStatements( Model baseModel )
+ * {
+ * addedStatements( baseModel.listStatements() );
+ * }
+ *
+ * @Override
+ * public void removedStatement( Statement s )
+ * {
+ * checkStatement( s );
+ * }
+ *
+ * @Override
+ * public void removedStatements( Statement[] statements )
+ * {
+ * checkStatements( Arrays.asList(statements).iterator() );
+ * }
+ *
+ * @Override
+ * public void removedStatements( List<Statement> statements )
+ * {
+ * checkStatements( statements.iterator() );
+ * }
+ *
+ * @Override
+ * public void removedStatements( StmtIterator statements )
+ * {
+ * try {
+ * checkStatements( statements );
+ * }
+ * finally {
+ * statements.close();
+ * }
+ * }
+ *
+ * @Override
+ * public void removedStatements( Model baseModel )
+ * {
+ * removedStatements( baseModel.listStatements() );
+ * }
+ *
+ * @Override
+ * public void notifyEvent( Model baseModel, Object event )
+ * {
+ * // do nothing
+ * }
+ *
+ * }
+ */
+
+ static class NodeMap implements Map1<Statement,RDFNode>
+ {
+
+ @Override
+ public RDFNode map1( Statement o )
+ {
+ return o.getObject();
+ }
+
+ }
+
+ static class ContainerComparator implements Comparator<Statement>
+ {
+
+ @Override
+ public int compare( Statement arg0, Statement arg1 )
+ {
+ return Integer.valueOf(arg0.getPredicate().getOrdinal()).compareTo( arg1.getPredicate().getOrdinal());
+ }
+
+ }
+
+ static class StatementRemovingIterator extends WrappedIterator<Statement>
+ {
+ private Statement stmt;
+
+ public StatementRemovingIterator( Iterator<? extends Statement> base )
+ {
+ super(base);
+ }
+
+ @Override
+ public Statement next()
+ {
+ stmt = super.next();
+ return stmt;
+ }
+
+ @Override
+ public void remove()
+ {
+ stmt.remove();
+ super.remove();
+ }
+
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredLiteralImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredLiteralImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredLiteralImpl.java
new file mode 100644
index 0000000..9d78388
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredLiteralImpl.java
@@ -0,0 +1,277 @@
+/*
+ * 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.model.impl;
+
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.rdf.model.Literal ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.RDFVisitor ;
+import org.apache.jena.rdf.model.ResourceRequiredException ;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemInvoker;
+import org.apache.jena.security.model.SecuredLiteral;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredResource;
+
+/**
+ * Implementation of SecuredLiteral to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredLiteralImpl extends SecuredRDFNodeImpl implements
+ SecuredLiteral
+{
+ /**
+ * Get an instance of SecuredLiteral
+ *
+ * @param securedModel
+ * the item providing the security context.
+ * @param literal
+ * the literal to secure
+ * @return SecuredLiteral
+ */
+ public static SecuredLiteral getInstance( final SecuredModel securedModel,
+ final Literal literal )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (literal == null)
+ {
+ throw new IllegalArgumentException("literal may not be null");
+ }
+
+ // check that literal has a securedModel.
+ Literal goodLiteral = literal;
+ if (goodLiteral.getModel() == null)
+ {
+ goodLiteral = securedModel.createTypedLiteral(
+ literal.getLexicalForm(), literal.getDatatype());
+ }
+
+ final ItemHolder<Literal, SecuredLiteral> holder = new ItemHolder<Literal, SecuredLiteral>(
+ goodLiteral);
+ final SecuredLiteralImpl checker = new SecuredLiteralImpl(securedModel,
+ holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (goodLiteral instanceof SecuredLiteral)
+ {
+ if (checker.isEquivalent((SecuredLiteral) goodLiteral))
+ {
+ return (SecuredLiteral) goodLiteral;
+ }
+ }
+ return holder.setSecuredItem(new SecuredItemInvoker(literal.getClass(),
+ checker));
+ }
+
+ // the item holder that contains this SecuredLiteral
+ private final ItemHolder<? extends Literal, ? extends SecuredLiteral> holder;
+
+ /**
+ * Constructor
+ *
+ * @param securityEvaluator
+ * The security evaluator to use.
+ * @param graphIRI
+ * the graph IRI to validate against.
+ * @param holder
+ * The item holder that will contain this SecuredLiteral.
+ */
+
+ private SecuredLiteralImpl( final SecuredModel securedModel,
+ final ItemHolder<? extends Literal, ? extends SecuredLiteral> holder )
+ {
+ super(securedModel, holder);
+ this.holder = holder;
+ }
+
+ @Override
+ public SecuredLiteral asLiteral()
+ {
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredResource asResource()
+ {
+ if (canRead())
+ {
+ throw new ResourceRequiredException(asNode());
+ }
+ else
+ {
+ throw new ResourceRequiredException(
+ Node.createLiteral("Can not read"));
+ }
+ }
+
+ @Override
+ public boolean getBoolean()
+ {
+ checkRead();
+ return holder.getBaseItem().getBoolean();
+ }
+
+ @Override
+ public byte getByte()
+ {
+ checkRead();
+ return holder.getBaseItem().getByte();
+ }
+
+ @Override
+ public char getChar()
+ {
+ checkRead();
+ return holder.getBaseItem().getChar();
+ }
+
+ /**
+ * Return the datatype of the literal. This will be null in the
+ * case of plain literals.
+ */
+ @Override
+ public RDFDatatype getDatatype()
+ {
+ checkRead();
+ return holder.getBaseItem().getDatatype();
+ }
+
+ /**
+ * Return the uri of the datatype of the literal. This will be null in the
+ * case of plain literals.
+ */
+ @Override
+ public String getDatatypeURI()
+ {
+ checkRead();
+ return holder.getBaseItem().getDatatypeURI();
+ }
+
+ @Override
+ public double getDouble()
+ {
+ checkRead();
+ return holder.getBaseItem().getDouble();
+ }
+
+ @Override
+ public float getFloat()
+ {
+ checkRead();
+ return holder.getBaseItem().getFloat();
+ }
+
+ @Override
+ public int getInt()
+ {
+ checkRead();
+ return holder.getBaseItem().getInt();
+ }
+
+ @Override
+ public String getLanguage()
+ {
+ checkRead();
+ return holder.getBaseItem().getLanguage();
+ }
+
+ /**
+ * Return the lexical form of the literal.
+ */
+ @Override
+ public String getLexicalForm()
+ {
+ checkRead();
+ return holder.getBaseItem().getLexicalForm();
+ }
+
+ @Override
+ public long getLong()
+ {
+ checkRead();
+ return holder.getBaseItem().getLong();
+ }
+
+ @Override
+ public short getShort()
+ {
+ checkRead();
+ return holder.getBaseItem().getShort();
+ }
+
+ @Override
+ public String getString()
+ {
+ checkRead();
+ return holder.getBaseItem().getString();
+ }
+
+ /**
+ * Return the value of the literal. In the case of plain literals
+ * this will return the literal string. In the case of typed literals
+ * it will return a java object representing the value. In the case
+ * of typed literals representing a java primitive then the appropriate
+ * java wrapper class (Integer etc) will be returned.
+ */
+ @Override
+ public Object getValue()
+ {
+ checkRead();
+ return holder.getBaseItem().getValue();
+ }
+
+ @Override
+ public Literal inModel( final Model m )
+ {
+ checkRead();
+ return m.createTypedLiteral(holder.getBaseItem().getLexicalForm(),
+ holder.getBaseItem().getDatatype());
+ }
+
+ @Override
+ public boolean isWellFormedXML()
+ {
+ checkRead();
+ return holder.getBaseItem().isWellFormedXML();
+ }
+
+ /**
+ * Test that two literals are semantically equivalent.
+ * In some cases this may be the sames as equals, in others
+ * equals is stricter. For example, two xsd:int literals with
+ * the same value but different language tag are semantically
+ * equivalent but distinguished by the java equality function
+ * in order to support round tripping.
+ */
+ @Override
+ public boolean sameValueAs( final Literal other )
+ {
+ checkRead();
+ return holder.getBaseItem().sameValueAs(other);
+ }
+
+ @Override
+ public Object visitWith( final RDFVisitor rv )
+ {
+ return rv.visitLiteral(this);
+ }
+}
[04/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredAltTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredAltTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredAltTest.java
deleted file mode 100644
index 4a33885..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredAltTest.java
+++ /dev/null
@@ -1,657 +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.model;
-
-import java.util.Set;
-
-import org.apache.jena.rdf.model.Alt ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredAlt;
-import org.apache.jena.security.model.impl.SecuredAltImpl;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredAltTest extends SecuredContainerTest
-{
- private Alt alt;
-
- public SecuredAltTest( final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- }
-
- private SecuredAlt getSecuredAlt()
- {
- return (SecuredAlt) getSecuredRDFNode();
- }
-
- @Override
- @Before
- public void setup()
- {
- super.setup();
- alt = baseModel.getAlt("http://example.com/testContainer");
- setSecuredRDFNode(SecuredAltImpl.getInstance(securedModel, alt), alt);
- }
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Test
- public void testGetDefault()
- {
- alt.add("SomeDummyItem");
- try
- {
- getSecuredAlt().getDefault();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredAlt().getDefaultAlt();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredAlt().getDefaultBag();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredAlt().getDefaultSeq();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDefaultBoolean()
- {
- alt.add(true);
- try
- {
- getSecuredAlt().getDefaultBoolean();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDefaultByte()
- {
- alt.add(Byte.MAX_VALUE);
- try
- {
- getSecuredAlt().getDefaultByte();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDefaultChar()
- {
- alt.add('c');
- try
- {
- getSecuredAlt().getDefaultChar();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDefaultDouble()
- {
- alt.add(3.14d);
- try
- {
- getSecuredAlt().getDefaultDouble();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDefaultFloat()
- {
- alt.add(3.14f);
- try
- {
- getSecuredAlt().getDefaultFloat();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDefaultInt()
- {
- alt.add(2);
- try
- {
- getSecuredAlt().getDefaultInt();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDefaultLanguage()
- {
- alt.add("SomeDummyItem");
- try
- {
- getSecuredAlt().getDefaultLanguage();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredAlt().getDefaultLiteral();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetDefaultLong()
- {
- alt.add(3L);
-
- try
- {
- getSecuredAlt().getDefaultLong();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDefaultResource()
- {
- alt.setDefault(ResourceFactory
- .createResource("http://example.com/exampleResourec"));
- try
- {
- getSecuredAlt().getDefaultResource();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- /*
- * try
- * {
- * ResourceF f = ResourceFactory.getInstance();
- * getSecuredAlt().getDefaultResource( f );
- * if (!securityEvaluator.evaluate(Action.Read))
- * {
- * Assert.fail("Should have thrown AccessDenied Exception");
- * }
- * }
- * catch (final AccessDeniedException e)
- * {
- * if (securityEvaluator.evaluate(Action.Read))
- * {
- * Assert.fail(String
- * .format("Should not have thrown AccessDenied Exception: %s - %s",
- * e, e.getTriple()));
- * }
- * }
- */
-
- @Test
- public void testGetDefaultShort()
- {
- alt.setDefault(Short.MAX_VALUE);
- try
- {
- getSecuredAlt().getDefaultShort();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDefaultString()
- {
- alt.setDefault("Hello World");
- try
- {
- getSecuredAlt().getDefaultString();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testSetDefaultBoolean()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredAlt().setDefault(true);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- 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 testSetDefaultChar()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredAlt().setDefault('c');
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- 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 testSetDefaultDouble()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredAlt().setDefault(3.14d);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- 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 testSetDefaultFloat()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredAlt().setDefault(3.14f);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- 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 testSetDefaultLong()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredAlt().setDefault(2L);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- 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 testSetDefaultObject()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- final Object o = 2;
- getSecuredAlt().setDefault(o);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- 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 testSetDefaultResource()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredAlt().setDefault(
- ResourceFactory
- .createResource("http://example.com/resource"));
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- 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 testSetDefaultString()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredAlt().setDefault("test");
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- 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 testSetDefaultStringAndLang()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredAlt().setDefault("dos", "es");
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- 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()));
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredBagTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredBagTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredBagTest.java
deleted file mode 100644
index 6c3ac5c..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredBagTest.java
+++ /dev/null
@@ -1,46 +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.model;
-
-import org.apache.jena.rdf.model.Bag ;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.model.impl.SecuredBagImpl;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredBagTest extends SecuredContainerTest
-{
-
- public SecuredBagTest( final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- }
-
- @Override
- @Before
- public void setup()
- {
- super.setup();
- final Bag bag = baseModel.getBag("http://example.com/testContainer");
- bag.add("SomeDummyItem");
- setSecuredRDFNode(SecuredBagImpl.getInstance(securedModel, bag), bag);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java
deleted file mode 100644
index 9f00757..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java
+++ /dev/null
@@ -1,480 +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.model;
-
-import java.util.Set;
-
-import org.apache.jena.rdf.model.Container ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.rdf.model.Statement ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredContainer;
-import org.apache.jena.security.model.impl.SecuredContainerImpl;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public abstract class SecuredContainerTest extends SecuredResourceTest
-{
-
- public SecuredContainerTest( final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- }
-
- private SecuredContainer getSecuredContainer()
- {
- return (SecuredContainer) getSecuredRDFNode();
- }
-
- @Override
- @Before
- public void setup()
- {
- super.setup();
- final Container container = baseModel
- .getBag("http://example.com/testContainer");
- container.add("SomeDummyItem");
- setSecuredRDFNode(
- SecuredContainerImpl.getInstance(securedModel, container),
- container);
- }
-
- @Test
- public void test()
- {
- try
- {
- getSecuredContainer().size();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Test
- public void testAdd()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredContainer().add(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
- {
- getSecuredContainer().add('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
- {
- getSecuredContainer().add(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
- {
- getSecuredContainer().add(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
- {
- getSecuredContainer().add(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()));
- }
- }
-
- final Object o = Integer.valueOf("1234");
- try
- {
- getSecuredContainer().add(o);
- 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
- {
- getSecuredContainer().add(
- ResourceFactory
- .createResource("http://example.com/testResource"));
- 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
- {
- getSecuredContainer().add("foo");
- 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
- {
- getSecuredContainer().add("dos", "esp");
- 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 testContains()
- {
- try
- {
- getSecuredContainer().contains(true);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredContainer().contains('c');
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredContainer().contains(3.14D);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredContainer().contains(3.14F);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredContainer().contains(2L);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- final Object o = Integer.valueOf("1234");
- try
- {
- getSecuredContainer().contains(o);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredContainer().contains(
- ResourceFactory
- .createResource("http://example.com/testResource"));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredContainer().contains("foo");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredContainer().contains("dos", "esp");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testIterator()
- {
- try
- {
- getSecuredContainer().iterator();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- 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 });
- final Statement s = baseModel.listStatements().next();
- try
- {
- getSecuredContainer().remove(s);
- 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()));
- }
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredLiteralTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredLiteralTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredLiteralTest.java
deleted file mode 100644
index 09ed40b..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredLiteralTest.java
+++ /dev/null
@@ -1,468 +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.model;
-
-import org.apache.jena.datatypes.DatatypeFormatException ;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.rdf.model.ResourceRequiredException ;
-import org.apache.jena.security.AccessDeniedException ;
-import org.apache.jena.security.MockSecurityEvaluator ;
-import org.apache.jena.security.SecurityEvaluator.Action ;
-import org.apache.jena.security.SecurityEvaluatorParameters ;
-import org.apache.jena.security.model.impl.SecuredLiteralImpl ;
-import org.apache.jena.shared.BadBooleanException ;
-import org.apache.jena.shared.BadCharLiteralException ;
-import org.junit.Assert ;
-import org.junit.Before ;
-import org.junit.Test ;
-import org.junit.runner.RunWith ;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredLiteralTest extends SecuredRDFNodeTest
-{
-
- public SecuredLiteralTest( final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- }
-
- private SecuredLiteral getSecuredLiteral()
- {
- return (SecuredLiteral) getSecuredRDFNode();
- }
-
- @Test
- public void sameValueAs()
- {
- try
- {
- getSecuredLiteral().sameValueAs(
- ResourceFactory.createPlainLiteral("Junk"));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Override
- @Before
- public void setup()
- {
- super.setup();
- Literal l = ResourceFactory.createTypedLiteral("literal");
- setSecuredRDFNode(SecuredLiteralImpl.getInstance(securedModel, l), l);
- }
-
- @Test
- public void testAsLiteral()
- {
- getSecuredLiteral().asLiteral();
- }
-
- @Test
- public void testAsResource()
- {
- try
- {
- getSecuredLiteral().asResource();
- Assert.fail("Should have thrown ResoruceRequiredException");
- }
- catch (final ResourceRequiredException e)
- {
- // expected
- }
- }
-
- @Test
- public void testGetBoolean()
- {
- try
- {
- getSecuredLiteral().getBoolean();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final DatatypeFormatException | BadBooleanException e )
- {
- // expected
- }
- }
-
- @Test
- public void testGetByte()
- {
- try
- {
- getSecuredLiteral().getByte();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final DatatypeFormatException | NumberFormatException e )
- {
- // expected
- }
- }
-
- @Test
- public void testGetChar()
- {
- try
- {
- getSecuredLiteral().getChar();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final DatatypeFormatException | BadCharLiteralException e )
- {
- // expected
- }
- }
-
- @Test
- public void testGetDatatype()
- {
- try
- {
- getSecuredLiteral().getDatatype();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDatatypeURI()
- {
- try
- {
- getSecuredLiteral().getDatatypeURI();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetDouble()
- {
- try
- {
- getSecuredLiteral().getDouble();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final DatatypeFormatException | NumberFormatException e )
- {
- // expected
- }
-
- }
-
- @Test
- public void testGetFloat()
- {
- try
- {
- getSecuredLiteral().getFloat();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final DatatypeFormatException | NumberFormatException e )
- {
- // expected
- }
- }
-
- @Test
- public void testGetInt()
- {
- try
- {
- getSecuredLiteral().getInt();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final DatatypeFormatException | NumberFormatException e )
- {
- // expected
- }
- }
-
- @Test
- public void testGetLanguage()
- {
- try
- {
- getSecuredLiteral().getLanguage();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetLexicalForm()
- {
- try
- {
- getSecuredLiteral().getLexicalForm();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetLong()
- {
- try
- {
- getSecuredLiteral().getLong();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final DatatypeFormatException | NumberFormatException e )
- {
- // expected
- }
- }
-
- @Test
- public void testGetShort()
- {
- try
- {
- getSecuredLiteral().getShort();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final DatatypeFormatException | NumberFormatException e )
- {
- // expected
- }
- }
-
- @Test
- public void testGetString()
- {
- try
- {
- getSecuredLiteral().getString();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final DatatypeFormatException | NumberFormatException e )
- {
- // expected
- }
- }
-
- @Test
- public void testGetValue()
- {
- try
- {
- getSecuredLiteral().getValue();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testIsWellFormedXML()
- {
- try
- {
- getSecuredLiteral().isWellFormedXML();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredModelDetailTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredModelDetailTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredModelDetailTest.java
deleted file mode 100644
index e96786f..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredModelDetailTest.java
+++ /dev/null
@@ -1,335 +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.model;
-
-import java.net.URL;
-import java.security.Principal;
-import java.util.Set;
-
-import org.apache.http.auth.BasicUserPrincipal;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.Factory;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.vocabulary.RDF ;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Tests secured model functions against graph where only partial data is
- * available to the user.
- *
- */
-public class SecuredModelDetailTest {
-
- private static String NS_FMT = "http://example.com/%s";
- private Model baseModel;
- private SecuredModel securedModel;
- private DetailEvaluator secEval;
- private Property pTo = ResourceFactory.createProperty("http://example.com/to");
- private Property pFrom = ResourceFactory
- .createProperty( "http://example.com/from");
-
- @Before
- public void setup()
- {
- baseModel = ModelFactory.createDefaultModel();
- baseModel.removeAll();
- URL url = SecuredModelDetailTest.class.getClassLoader().getResource( "org/apache/jena/security/model/detail.ttl");
- baseModel.read( url.toExternalForm() );
- secEval = new DetailEvaluator( baseModel );
- securedModel = Factory.getInstance(secEval,
- "http://example.com/detailModelTest", baseModel);
- }
-
-
- @Test
- public void testContains()
- {
- secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
- */
-
- Resource s = ResourceFactory.createResource( String.format( NS_FMT, "msg3") );
- Assert.assertTrue( "should contain msg3", baseModel.contains( s, null ));
- Assert.assertFalse( "should not see msg3", securedModel.contains( s, null ));
- Assert.assertTrue( "Sould contain a resource msg3", baseModel.containsResource( s));
- Assert.assertFalse( "Should not contain a resource msg3'", securedModel.containsResource( s) );
-
- s = ResourceFactory.createResource( String.format( NS_FMT, "msg4") );
- Assert.assertTrue( "should contain msg4", baseModel.contains( s, null ));
- Assert.assertTrue( "should see msg4", securedModel.contains( s, null ));
- Assert.assertTrue( "Sould contain a resource msg4", baseModel.containsResource( s));
- Assert.assertTrue( "Should contain a resource msg4'", securedModel.containsResource( s) );
-
- Assert.assertTrue( "Sould contain a to 'bob'", baseModel.contains( null, pTo, "bob"));
- Assert.assertFalse( "Should not see to 'bob'", securedModel.contains( null, pTo, "bob") );
-
- Assert.assertTrue( "Sould contain a from 'bob'", baseModel.contains( null, pFrom, "bob"));
- Assert.assertTrue( "Should see from 'bob'", securedModel.contains( null, pFrom, "bob") );
-
- }
-
- @Test
- public void testListObjects()
- {
- secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
- */
-
- Assert.assertTrue( baseModel.listObjects().toList().size() > 4);
- Assert.assertEquals( 4, securedModel.listObjects().toList().size());
-
- Assert.assertTrue( baseModel.listObjectsOfProperty( pFrom ).toList().size() > 1);
- Assert.assertEquals( 1, securedModel.listObjectsOfProperty( pFrom ).toList().size());
-
- Resource s = ResourceFactory.createResource( String.format( NS_FMT, "msg3"));
- Assert.assertEquals( 1, baseModel.listObjectsOfProperty( s, pFrom).toList().size());
- Assert.assertEquals( 0, securedModel.listObjectsOfProperty( s, pFrom ).toList().size());
-
- s = ResourceFactory.createResource( String.format( NS_FMT, "msg4"));
- Assert.assertEquals( 1, baseModel.listObjectsOfProperty( s, pFrom).toList().size());
- Assert.assertEquals( 1, securedModel.listObjectsOfProperty( s, pFrom ).toList().size());
- }
-
- @Test
- public void testListResources() {
- secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
- */
- Assert.assertEquals( 5, baseModel.listResourcesWithProperty( pFrom ).toList().size());
- Assert.assertEquals( 1, securedModel.listResourcesWithProperty( pFrom ).toList().size());
-
- RDFNode o = ResourceFactory.createPlainLiteral("bob");
- Assert.assertEquals( 3, baseModel.listResourcesWithProperty( pFrom, o ).toList().size());
- Assert.assertEquals( 1, securedModel.listResourcesWithProperty( pFrom, o ).toList().size());
- Assert.assertEquals( 1, baseModel.listResourcesWithProperty( pTo, o ).toList().size());
- Assert.assertEquals( 0, securedModel.listResourcesWithProperty( pTo, o ).toList().size());
-
- Assert.assertEquals( 4, baseModel.listResourcesWithProperty( null, o ).toList().size());
- Assert.assertEquals( 1, securedModel.listResourcesWithProperty( null, o ).toList().size());
-
- o = ResourceFactory.createPlainLiteral("alice");
- Assert.assertEquals( 4, baseModel.listResourcesWithProperty( null, o ).toList().size());
- Assert.assertEquals( 0, securedModel.listResourcesWithProperty( null, o ).toList().size());
- }
-
- @Test
- public void testListStatements()
- {
- secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
- */
- Assert.assertEquals( 20, baseModel.listStatements().toList().size());
- Assert.assertEquals( 4, securedModel.listStatements().toList().size());
-
- RDFNode o = ResourceFactory.createPlainLiteral("bob");
- Assert.assertEquals( 1, baseModel.listStatements( null, pTo, o).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( null, pTo, o).toList().size());
- Assert.assertEquals( 3, baseModel.listStatements( null, pFrom, o).toList().size());
- Assert.assertEquals( 1, securedModel.listStatements( null, pFrom, o).toList().size());
-
- Resource s = ResourceFactory.createResource( String.format( NS_FMT, "msg3"));
- Assert.assertEquals( 4, baseModel.listStatements( s, null, (RDFNode)null).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, null, (RDFNode)null).toList().size());
-
- Assert.assertEquals( 1, baseModel.listStatements( s, pTo, (RDFNode)null).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, pTo, (RDFNode)null).toList().size());
-
- Assert.assertEquals( 0, baseModel.listStatements( s, pTo, o).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, pTo, o).toList().size());
- o = ResourceFactory.createPlainLiteral("chuck");
- Assert.assertEquals( 1, baseModel.listStatements( s, pTo, o).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, pTo, o).toList().size());
-
-
- s = ResourceFactory.createResource( String.format( NS_FMT, "msg4"));
- Assert.assertEquals( 4, baseModel.listStatements( s, null, (RDFNode)null).toList().size());
- Assert.assertEquals( 4, securedModel.listStatements( s, null, (RDFNode)null).toList().size());
-
- Assert.assertEquals( 1, baseModel.listStatements( s, pTo, (RDFNode)null).toList().size());
- Assert.assertEquals( 1, securedModel.listStatements( s, pTo, (RDFNode)null).toList().size());
-
- Assert.assertEquals( 0, baseModel.listStatements( s, pTo, o).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, pTo, o).toList().size());
- o = ResourceFactory.createPlainLiteral("darla");
- Assert.assertEquals( 1, baseModel.listStatements( s, pTo, o).toList().size());
- Assert.assertEquals( 1, securedModel.listStatements( s, pTo, o).toList().size());
- }
-
- @Test
- public void testListSubjects()
- {
- secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
- */
- Assert.assertEquals( 5, baseModel.listSubjects().toList().size());
- Assert.assertEquals( 1, securedModel.listSubjects().toList().size());
-
- Assert.assertEquals( 5, baseModel.listSubjectsWithProperty( pTo ).toList().size());
- Assert.assertEquals( 1, securedModel.listSubjectsWithProperty( pTo ).toList().size());
-
- RDFNode o = ResourceFactory.createPlainLiteral("darla");
- Assert.assertEquals( 1, baseModel.listSubjectsWithProperty( pTo, o ).toList().size());
- Assert.assertEquals( 1, securedModel.listSubjectsWithProperty( pTo, o ).toList().size());
-
- o = ResourceFactory.createPlainLiteral("bob");
- Assert.assertEquals( 1, baseModel.listSubjectsWithProperty( pTo, o ).toList().size());
- Assert.assertEquals( 0, securedModel.listSubjectsWithProperty( pTo, o ).toList().size());
-
- Assert.assertEquals( 4, baseModel.listSubjectsWithProperty( null, o ).toList().size());
- Assert.assertEquals( 1, securedModel.listSubjectsWithProperty( null, o ).toList().size());
-
- }
-
- /**
- * An example evaluator that only provides access ot messages in the graph that
- * are from or to the principal.
- *
- */
- private class DetailEvaluator implements SecurityEvaluator {
-
- private Principal principal;
- private Model model;
- private RDFNode msgType = ResourceFactory.createResource( "http://example.com/msg" );
- private Property pTo = ResourceFactory.createProperty( "http://example.com/to" );
- private Property pFrom = ResourceFactory.createProperty( "http://example.com/from" );
-
- /**
- *
- * @param model The graph we are going to evaluate against.
- */
- public DetailEvaluator( Model model )
- {
- this.model = model;
- }
-
- @Override
- public boolean evaluate(Object principal, Action action, SecNode graphIRI) {
- // we allow any action on a graph.
- return true;
- }
-
- private boolean evaluate( Resource r )
- {
- // a message is only available to sender or recipient
- if (r.hasProperty( RDF.type, msgType ))
- {
- return r.hasProperty( pTo, ((Principal)principal).getName() ) ||
- r.hasProperty( pFrom, ((Principal)principal).getName());
- }
- return true;
- }
-
- private boolean evaluate( SecNode node )
- {
- if (node.equals( SecNode.ANY )) {
- return false; // all wild cards are false
- }
-
- if (node.getType().equals( SecNode.Type.URI)) {
- Resource r = model.createResource( node.getValue() );
- return evaluate( r );
- }
- else if (node.getType().equals( SecNode.Type.Anonymous)) {
- Resource r = model.getRDFNode( NodeFactory.createAnon( new AnonId( node.getValue()) ) ).asResource();
- return evaluate( r );
- }
- else
- {
- return true;
- }
-
- }
-
- private boolean evaluate( SecTriple triple ) {
- return evaluate( triple.getSubject()) &&
- evaluate( triple.getObject()) &&
- evaluate( triple.getPredicate());
- }
-
- @Override
- public boolean evaluate(Object principal, Action action, SecNode graphIRI, SecTriple triple) {
- return evaluate( triple );
- }
-
- @Override
- public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return evaluate( triple );
- }
-
- @Override
- public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return evaluate( triple );
- }
-
- @Override
- public boolean evaluateUpdate(Object principal, SecNode graphIRI, SecTriple from, SecTriple to) {
- return evaluate( from ) && evaluate( to );
- }
-
- public void setPrincipal( String userName )
- {
- if (userName == null)
- {
- principal = null;
- }
- principal = new BasicUserPrincipal( userName );
- }
- @Override
- public Principal getPrincipal() {
- return principal;
- }
-
- }
-
-}
[02/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredResourceTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredResourceTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredResourceTest.java
deleted file mode 100644
index a705518..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredResourceTest.java
+++ /dev/null
@@ -1,827 +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.model;
-
-import java.util.Set;
-
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.RDFNode ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.rdf.model.StmtIterator ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredResource;
-import org.apache.jena.security.model.impl.SecuredResourceImpl;
-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 SecuredResourceTest extends SecuredRDFNodeTest
-{
-
- public SecuredResourceTest( final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- }
-
- private SecuredResource getSecuredResource()
- {
- return (SecuredResource) getSecuredRDFNode();
- }
-
- @Override
- @Before
- public void setup()
- {
- super.setup();
- setSecuredRDFNode(SecuredResourceImpl.getInstance(securedModel,
- SecuredRDFNodeTest.s), SecuredRDFNodeTest.s);
- }
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
- */
- @Test
- public void testAddLiteralBoolean()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 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()));
- }
- }
- }
-
- public void testAddLiteralChar()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredResource().addLiteral(SecuredRDFNodeTest.p, '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()));
- }
- }
-}
-
- public void testAddLiteralDouble()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- try
- {
- getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 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()));
- }
- }
-}
-
- public void testAddLiteralFloat()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- try
- {
- getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 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()));
- }
- }
-}
-
- public void testAddLiteral()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- try
- {
- getSecuredResource().addLiteral(SecuredRDFNodeTest.p,
- ResourceFactory.createTypedLiteral("Yee haw"));
- 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()));
- }
- }
-}
-
- public void testAddLiteralLong()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- try
- {
- getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 1L);
- 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()));
- }
- }
-}
-
- public void testAddLiteralObject()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- final Object o = Integer.valueOf("1234");
- try
- {
- getSecuredResource().addLiteral(SecuredRDFNodeTest.p, o);
- 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 testAddProperty()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- final RDFNode rdfNode = ResourceFactory
- .createResource("http://example.com/newResource");
- try
- {
- getSecuredResource().addLiteral(SecuredRDFNodeTest.p, rdfNode);
- 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
- {
- getSecuredResource().addLiteral(SecuredRDFNodeTest.p, "string");
- 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()));
- }
- }
-
- final Literal l = ResourceFactory.createTypedLiteral( 3.14F );
- try
- {
- getSecuredResource().addProperty(SecuredRDFNodeTest.p,
- l.getLexicalForm(), l.getDatatype());
- 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
- {
- getSecuredResource().addProperty(SecuredRDFNodeTest.p, "dos", "sp");
- 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 testAnonFuncs()
- {
-
- final SecuredResource anonResource = securedModel.createResource();
- setSecuredRDFNode(anonResource, null);
-
- try
- {
- getSecuredResource().getId();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testAsResource()
- {
- getSecuredResource().asResource();
- }
-
- @Test
- public void testEquals()
- {
- try
- {
- getSecuredResource().equals(SecuredRDFNodeTest.s);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- public void testGetLocalName()
- {
- try
- {
- getSecuredResource().getLocalName();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- public void testGetNameSpace()
- {
- try
- {
- getSecuredResource().getNameSpace();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetProperty()
- {
- try
- {
- getSecuredResource().getProperty(SecuredRDFNodeTest.p);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().getPropertyResourceValue(SecuredRDFNodeTest.p);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().getRequiredProperty(SecuredRDFNodeTest.p);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final PropertyNotFoundException e)
- {
- // expected if (this, "p", ANY) is not in the base securedModel.
- final StmtIterator iter = baseModel.listStatements(
- getSecuredResource(), SecuredRDFNodeTest.p, (RDFNode) null);
- try
- {
- if (iter.hasNext())
- {
- throw e;
- }
- }
- finally
- {
- iter.close();
- }
- }
- }
-
- @Test
- public void testGetURI()
- {
- try
- {
- getSecuredResource().getURI();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testHasLiteral()
- {
- try
- {
- getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, true);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 'c');
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 3.14d);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 3.14f);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 6l);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- final Object o = 6;
- try
- {
- getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, o);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testHasProperty()
- {
-
- try
- {
- getSecuredResource().hasProperty(SecuredRDFNodeTest.p);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().hasProperty(SecuredRDFNodeTest.p,
- SecuredRDFNodeTest.o);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().hasProperty(SecuredRDFNodeTest.p, "yeee haw");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().hasProperty(SecuredRDFNodeTest.p, "dos", "sp");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testHasURI()
- {
- try
- {
- getSecuredResource().hasURI("http://example.com/yeeHaw");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testListProperties()
- {
- try
- {
- getSecuredResource().listProperties();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredResource().listProperties(SecuredRDFNodeTest.p);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testRemoveAll()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
- final int count = baseModel
- .listStatements(getBaseRDFNode().asResource(),
- SecuredRDFNodeTest.p, (RDFNode) null).toSet().size();
-
- try
- {
- getSecuredResource().removeAll(SecuredRDFNodeTest.p);
- // only throw on delete if count > 0
- if (!securityEvaluator.evaluate(Action.Update)
- || ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- 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 testRemoveProperties()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
- final int count = baseModel
- .listStatements(getBaseRDFNode().asResource(),
- SecuredRDFNodeTest.p, (RDFNode) null).toSet().size();
-
- try
- {
- getSecuredResource().removeProperties();
- // only throw on delete if count > 0
- if (!securityEvaluator.evaluate(Action.Update)
- || ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- 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()));
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredSeqTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredSeqTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredSeqTest.java
deleted file mode 100644
index 89cb39b..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredSeqTest.java
+++ /dev/null
@@ -1,1013 +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.model;
-
-import java.util.Set;
-
-import org.apache.jena.rdf.model.Alt ;
-import org.apache.jena.rdf.model.Bag ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.rdf.model.Seq ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredAlt;
-import org.apache.jena.security.model.SecuredBag;
-import org.apache.jena.security.model.SecuredSeq;
-import org.apache.jena.security.model.impl.SecuredSeqImpl;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredSeqTest extends SecuredContainerTest
-{
- private Seq seq;
-
- public SecuredSeqTest( final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- // TODO Auto-generated constructor stub
- }
-
- private SecuredSeq getSecuredSeq()
- {
- return (SecuredSeq) getSecuredRDFNode();
- }
-
- @Override
- @Before
- public void setup()
- {
- super.setup();
- seq = baseModel.getSeq("http://example.com/testContainer");
- setSecuredRDFNode(SecuredSeqImpl.getInstance(securedModel, seq), seq);
- }
-
- @Override
- @Test
- public void testAdd()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredSeq().add(2, 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
- {
- getSecuredSeq().add(2, '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
- {
- getSecuredSeq().add(2, 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
- {
- getSecuredSeq().add(2, 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
- {
- getSecuredSeq().add(2, 3L);
- 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 Object o = Integer.MAX_VALUE;
- getSecuredSeq().add(2, o);
- 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
- {
- getSecuredSeq().add(2, 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
- {
- getSecuredSeq().add(2, "Waa hoo");
- 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
- {
- getSecuredSeq().add(2, "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()));
- }
- }
- }
-
- @Test
- public void testGetAlt()
- {
- try
- {
- final Alt a = getSecuredSeq().getAlt(1);
- Assert.assertTrue("Should be a secured Alt",
- a instanceof SecuredAlt);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetBag()
- {
- try
- {
- final Bag a = getSecuredSeq().getBag(1);
- Assert.assertTrue("Should be a secured Bag",
- a instanceof SecuredBag);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetBoolean()
- {
- seq.add(2, true);
- try
- {
- getSecuredSeq().getBoolean(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetByte()
- {
- seq.add(2, Byte.MAX_VALUE);
- try
- {
- getSecuredSeq().getByte(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetChar()
- {
- seq.add(2, 'c');
- try
- {
- getSecuredSeq().getChar(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetDouble()
- {
- seq.add(2, 3.14D);
- try
- {
- getSecuredSeq().getDouble(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetFloat()
- {
- seq.add(2, 3.14F);
- try
- {
- getSecuredSeq().getFloat(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetInt()
- {
- seq.add(2, 2);
- try
- {
- getSecuredSeq().getInt(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetLanguage()
- {
- seq.add(2, "foo");
- try
- {
- getSecuredSeq().getLanguage(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetLiteral()
- {
- seq.add(2, "foo");
- try
- {
- getSecuredSeq().getLiteral(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetLong()
- {
- seq.add(2, 2L);
- try
- {
- getSecuredSeq().getLong(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetObject()
- {
- final Object o = Integer.MAX_VALUE;
- seq.add(2, o);
- try
- {
- getSecuredSeq().getObject(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetResource()
- {
- seq.add(2, ResourceFactory.createResource());
- try
- {
- getSecuredSeq().getResource(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- /*
- * @Test
- * public void testGetChar()
- * {
- * ResourceF f;
- * seq.add( 2, 'c' );
- * try
- * {
- * getSecuredSeq().getResource(2, f );
- * if (!securityEvaluator.evaluate(Action.Read))
- * {
- * Assert.fail("Should have thrown AccessDenied Exception");
- * }
- * }
- * catch (final AccessDeniedException e)
- * {
- * if (securityEvaluator.evaluate(Action.Read))
- * {
- * Assert.fail(String
- * .format("Should not have thrown AccessDenied Exception: %s - %s",
- * e, e.getTriple()));
- * }
- * }
- *
- * }
- */
- @Test
- public void testGetSeq()
- {
- seq.add(2, 'c');
- try
- {
- getSecuredSeq().getSeq(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetShort()
- {
- seq.add(2, Short.MAX_VALUE);
- try
- {
- getSecuredSeq().getShort(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetString()
- {
- seq.add(2, "Waaa hoo");
- try
- {
- getSecuredSeq().getString(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testIndexOf()
- {
- try
- {
- getSecuredSeq().indexOf(true);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredSeq().indexOf('c');
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredSeq().indexOf(3.14D);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredSeq().indexOf(3.14F);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredSeq().indexOf(3L);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- final Object o = Integer.MAX_VALUE;
- getSecuredSeq().indexOf(o);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
-
- getSecuredSeq()
- .indexOf(
- ResourceFactory
- .createResource("http://example.com/exampleResource"));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredSeq().indexOf("waaa hooo");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- getSecuredSeq().indexOf("dos", "es");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Override
- @Test
- public void testRemove()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
- try
- {
- getSecuredSeq().remove(1);
- 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 testSet()
- {
- final Set<Action> perms = SecurityEvaluator.Util
- .asSet(new Action[] { Action.Update });
- try
- {
- getSecuredSeq().set(1, 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
- {
- getSecuredSeq().set(1, '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
- {
- getSecuredSeq().set(1, 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
- {
- getSecuredSeq().set(1, 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
- {
- getSecuredSeq().set(1, 3L);
- 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 Object o = Integer.MAX_VALUE;
- getSecuredSeq().set(1, o);
- 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
- {
- getSecuredSeq().set(1, 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
- {
- getSecuredSeq().set(1, "Waa hoo");
- 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
- {
- getSecuredSeq().set(1, "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()));
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredStatementTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredStatementTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredStatementTest.java
deleted file mode 100644
index 4345aa7..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredStatementTest.java
+++ /dev/null
@@ -1,707 +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.model;
-
-import java.util.Set;
-
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.Factory;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredStatement;
-import org.apache.jena.security.model.impl.SecuredStatementImpl;
-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/b712fb28/jena-security/src/test/java/org/apache/jena/security/query/DataSetTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/query/DataSetTest.java b/jena-security/src/test/java/org/apache/jena/security/query/DataSetTest.java
deleted file mode 100644
index 47bcfbd..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/query/DataSetTest.java
+++ /dev/null
@@ -1,244 +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.query;
-
-import org.apache.jena.query.* ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.security.Factory;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
-import org.apache.jena.security.model.SecuredModel;
-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/b712fb28/jena-security/src/test/java/org/apache/jena/security/query/QueryEngineTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/query/QueryEngineTest.java b/jena-security/src/test/java/org/apache/jena/security/query/QueryEngineTest.java
deleted file mode 100644
index 7bee511..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/query/QueryEngineTest.java
+++ /dev/null
@@ -1,259 +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.query;
-
-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.security.Factory;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
-import org.apache.jena.security.model.SecuredModel;
-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/b712fb28/jena-security/src/test/java/org/apache/jena/security/query/rewriter/OpRewriterTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/query/rewriter/OpRewriterTest.java b/jena-security/src/test/java/org/apache/jena/security/query/rewriter/OpRewriterTest.java
deleted file mode 100644
index eaec4b7..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/query/rewriter/OpRewriterTest.java
+++ /dev/null
@@ -1,111 +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.query.rewriter;
-
-import java.util.Arrays;
-
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.query.rewriter.OpRewriter;
-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/b712fb28/jena-security/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/jena-security/src/test/resources/log4j.properties b/jena-security/src/test/resources/log4j.properties
deleted file mode 100644
index f3d6f5e..0000000
--- a/jena-security/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,15 +0,0 @@
-log4j.rootLogger=INFO, stdlog
-
-log4j.appender.stdlog=org.apache.log4j.ConsoleAppender
-## log4j.appender.stdlog.target=System.err
-log4j.appender.stdlog.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdlog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %-25c{1} :: %m%n
-
-# Execution logging
-log4j.logger.org.apache.jena.arq.info=INFO
-log4j.logger.org.apache.jena.arq.exec=INFO
-
-# Everything else in Jena
-log4j.logger.org.apache.jena=WARN
-log4j.logger.org.apache.jena=WARN
-log4j.logger.org.apache.jena.riot=INFO
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/resources/org/apache/jena/security/SecuredAssemblerTest.ttl
----------------------------------------------------------------------
diff --git a/jena-security/src/test/resources/org/apache/jena/security/SecuredAssemblerTest.ttl b/jena-security/src/test/resources/org/apache/jena/security/SecuredAssemblerTest.ttl
deleted file mode 100644
index b8289f7..0000000
--- a/jena-security/src/test/resources/org/apache/jena/security/SecuredAssemblerTest.ttl
+++ /dev/null
@@ -1,56 +0,0 @@
-@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
-@prefix owl: <http://www.w3.org/2002/07/owl#> .
-
-@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
-@prefix sec: <http://apache.org/jena/security/Assembler#> .
-@prefix my: <http://apache.org/jena/security/test#> .
-@prefix xsd: <http://www.w3.org/2001/XMLSchema#>
-
-<> ja:loadClass "org.apache.jena.security.SecuredAssembler" .
-
-sec:Model
- rdfs:subClassOf ja:NamedModel ;
- .
-
-my:baseModel
- a ja:MemoryModel;
- .
-
-my:secModel
- a sec:Model;
- sec:baseModel my:baseModel ;
- ja:modelName "http://example.com/securedModel" ;
- sec:evaluatorFactory "org.apache.jena.security.MockSecurityEvaluator" ;
- .
-
-my:secModel2
- a sec:Model;
- sec:baseModel my:baseModel ;
- ja:modelName "http://example.com/securedModel2" ;
- sec:evaluatorImpl my:secEvaluator ;
- .
-
-my:secEvaluator
- a sec:Evaluator ;
- sec:args [ rdf:_1 "bob" ;
- ] ;
- sec:evaluatorClass "org.apache.jena.security.StaticSecurityEvaluator" ;
- .
-
-my:secModel3
- a sec:Model;
- sec:baseModel my:baseModel ;
- ja:modelName "http://example.com/securedModel3" ;
- sec:evaluatorImpl my:secEvaluator2 ;
- .
-
- my:secEvaluator2
- a sec:Evaluator ;
- sec:args [ rdf:_1 my:baseModel ;
- ] ;
- sec:evaluatorClass "org.apache.jena.security.ModelBasedSecurityEvaluator" ;
- .
-
-
-
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/resources/org/apache/jena/security/model/detail.ttl
----------------------------------------------------------------------
diff --git a/jena-security/src/test/resources/org/apache/jena/security/model/detail.ttl b/jena-security/src/test/resources/org/apache/jena/security/model/detail.ttl
deleted file mode 100644
index 643c586..0000000
--- a/jena-security/src/test/resources/org/apache/jena/security/model/detail.ttl
+++ /dev/null
@@ -1,33 +0,0 @@
-@prefix ex: <http://example.com/> .
-@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-
-ex:msg1 rdf:type ex:msg;
- ex:to "bob";
- ex:from "alice" ;
- ex:subj "alice to bob 1";
- .
-
-ex:msg2 rdf:type ex:msg;
- ex:to "alice";
- ex:from "bob";
- ex:subj "bob to alice 1";
- .
-
-ex:msg3 rdf:type ex:msg;
- ex:to "chuck" ;
- ex:from "alice";
- ex:subj "alice to chuck 1";
- .
-
-ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
- .
-
-ex:msg5 rdf:type ex:msg;
- ex:to "alice";
- ex:from "bob";
- ex:subj "bob to alice 2";
- .
-
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/resources/org/apache/jena/security/model/test.ttl
----------------------------------------------------------------------
diff --git a/jena-security/src/test/resources/org/apache/jena/security/model/test.ttl b/jena-security/src/test/resources/org/apache/jena/security/model/test.ttl
deleted file mode 100644
index 2fbb4e3..0000000
--- a/jena-security/src/test/resources/org/apache/jena/security/model/test.ttl
+++ /dev/null
@@ -1,2 +0,0 @@
-@prefix rt: <http://example.com/readTest#> .
-rt:1 a rt:3 .
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/resources/org/apache/jena/security/model/test.xml
----------------------------------------------------------------------
diff --git a/jena-security/src/test/resources/org/apache/jena/security/model/test.xml b/jena-security/src/test/resources/org/apache/jena/security/model/test.xml
deleted file mode 100644
index 18ad45a..0000000
--- a/jena-security/src/test/resources/org/apache/jena/security/model/test.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:rt="http://example.com/readTest#" xmlns:j.0="http://example.com/readTest#3">
- <rdf:Description rdf:about="http://example.com/readTest#1">
- <rdf:type rdf:resource="http://example.com/readTest#3" />
- </rdf:Description>
-</rdf:RDF>
[09/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredProperty.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredProperty.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredProperty.java
deleted file mode 100644
index 6c9518f..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredProperty.java
+++ /dev/null
@@ -1,38 +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.model;
-
-import org.apache.jena.rdf.model.Property ;
-import org.apache.jena.security.AccessDeniedException;
-
-/**
- * The interface for secured Property instances.
- *
- * Use the SecuredProperty.Factory to create instances
- */
-public interface SecuredProperty extends SecuredResource, Property
-{
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public int getOrdinal() throws AccessDeniedException;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredRDFList.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredRDFList.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredRDFList.java
deleted file mode 100644
index 08bac61..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredRDFList.java
+++ /dev/null
@@ -1,414 +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.model;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-
-public interface SecuredRDFList extends RDFList, SecuredResource
-{
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple(SecNode.FUTURE, listFirst(), value)
- * @sec.triple Create SecTriple(SecNode.FUTURE, listFirst(), listNil())
- * @throws AccessDeniedException
- */
- @Override
- public void add( final RDFNode value ) throws AccessDeniedException;
-
- /**
- * Resulting list will contain the readable nodes from this list
- * concatenated with nodes
- * @sec.graph Update
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, value )
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.rest, this )
- */
- @Override
- public RDFList append( final Iterator<? extends RDFNode> nodes )
- throws AccessDeniedException;
-
- /**
- * Resulting list will contain the readable nodes from this list
- * concatenated
- * with the list argument
- * @sec.graph Update
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, value )
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.rest, this )
- */
- @Override
- public RDFList append( final RDFList list ) throws AccessDeniedException;
-
- /**
- * Uses the security settings for the application of the function calls.
- * Thus if the function reads data the Read must be allowed, etc.
- *
- * @sec.graph Read
- * @sec.triple Read (to be included in the calculation)
- * @sec.triple other permissions required by the function.
- * @throws AccessDeniedException
- * graph Read or other permissions are not met
- */
- @Override
- public void apply( final ApplyFn fn ) throws AccessDeniedException;
-
- /**
- * This method is intended to provide the capabilities to apply functions
- * that
- * need to do more than read the graph.
- *
- * If the user does not have constraints access to the item in the list the
- * item
- * is not included in the function.
- *
- * @param constraints
- * The permissions the user must have on the items in the list.
- * @param fn
- * The function to apply.
- *
- * @sec.graph Read
- * @sec.triple Read and constraints
- * @throws AccessDeniedException
- */
- public void apply( Set<Action> constraints, final ApplyFn fn )
- throws AccessDeniedException;
-
- /**
- * @sec.triple Read for triples containing the returned RDFNodes.
- * @return List<SecuredRDFNode>
- */
- @Override
- public List<RDFNode> asJavaList();
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, node ) for each
- * node in
- * nodes.
- * @throws AccessDeniedException
- */
- @Override
- public void concatenate( final Iterator<? extends RDFNode> nodes )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, node ) for each
- * node in
- * list.
- * @throws AccessDeniedException
- */
- @Override
- public void concatenate( final RDFList list ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, value )
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.rest, this )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredRDFList cons( final RDFNode value )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read for triple containing value.
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final RDFNode value ) throws AccessDeniedException;
-
- /**
- * Creates a copy of this list comprising the readable elements of this
- * list.
- * @sec.graph Read to read the items to copy
- * @sec.triple Read on each triple to be read.
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, value )
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.rest, this )
- */
- @Override
- public SecuredRDFList copy();
-
- /**
- * Answer the node that is the i'th element of the list, assuming that the
- * head is item zero. If the list is too
- * short to have an i'th element, throws a ListIndexException.
- *
- * List may be shortened by security constraints.
- *
- * @sec.graph Read
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public SecuredRDFNode get( final int i ) throws AccessDeniedException,
- EmptyListException, ListIndexException, InvalidListException;
-
- /**
- * The value that is at the head of the list.
- *
- * head may be shifted by security constraints.
- *
- * @sec.graph Read
- * @sec.triple Read for triple containing value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- */
- @Override
- public RDFNode getHead() throws AccessDeniedException, EmptyListException;
-
- /**
- * The value that is at the tail of the list.
- *
- * tail may be shifted by security constraints.
- *
- * @sec.graph Read
- * @sec.triple Read for triple containing value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public SecuredRDFList getTail() throws AccessDeniedException,
- EmptyListException, ListIndexException, InvalidListException;
-
- /**
- * @sec.graph Read
- */
- @Override
- public String getValidityErrorMessage() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read for triple containing value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public int indexOf( final RDFNode value ) throws AccessDeniedException,
- EmptyListException, ListIndexException, InvalidListException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read for triple containing value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public int indexOf( final RDFNode value, final int start )
- throws AccessDeniedException, EmptyListException,
- ListIndexException, InvalidListException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean isEmpty() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean isValid() throws AccessDeniedException, EmptyListException,
- ListIndexException, InvalidListException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read for triple containing value to be included in the result.
- * @throws AccessDeniedException
- */
- @Override
- public ExtendedIterator<RDFNode> iterator() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read + requiredPerms for triple containing value to be
- * included in the result.
- * @throws AccessDeniedException
- */
- public ExtendedIterator<RDFNode> iterator( Set<Action> requiredPerms )
- throws AccessDeniedException, EmptyListException,
- ListIndexException, InvalidListException;
-
- /**
- * Only readable triples will be passed to the function. If the function
- * does
- * any action other than read those permissions must also be granted.
- *
- * @sec.graph Read
- * @sec.triple Read for triple containing value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public Object reduce( final ReduceFn fn, final Object initial )
- throws AccessDeniedException, EmptyListException,
- ListIndexException, InvalidListException;
-
- /**
- * Only readable triples will be passed to the function. In addition,
- * only triples that pass the requiredActions tests will be passed to the
- * function.
- *
- * @sec.graph Read
- * @sec.triple Read for triple containing value.
- * @param requiredActions
- * The set of permission (in addition to Read) that the user must
- * have
- * @param fn
- * The reduction function
- * @param initial
- * The initial state for the ruduce value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- public Object reduce( Set<Action> requiredActions, final ReduceFn fn,
- final Object initial ) throws AccessDeniedException,
- EmptyListException, ListIndexException, InvalidListException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete for triple containing value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public RDFList remove( final RDFNode val ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete for all triples.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- @Deprecated
- public void removeAll() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete for the head triple.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public RDFList removeHead() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete for triple containing value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public void removeList() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update for triplie i, and value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public SecuredRDFNode replace( final int i, final RDFNode value )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read for triples included in the comparison.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public boolean sameListAs( final RDFList list )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create for triple containing value.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public SecuredRDFNode setHead( final RDFNode value )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public void setStrict( final boolean strict ) throws AccessDeniedException;
-
- /**
- * Size may be modified by security constraionts.
- *
- * @sec.graph Read
- * @sec.triple Read for triples counted in the result.
- * @throws AccessDeniedException
- * @throws EmptyListException
- * @throws ListIndexException
- * @throws InvalidListException
- */
- @Override
- public int size() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create for triple containing value.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredRDFList with( final RDFNode value )
- throws AccessDeniedException;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredRDFNode.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredRDFNode.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredRDFNode.java
deleted file mode 100644
index 5002366..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredRDFNode.java
+++ /dev/null
@@ -1,59 +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.model;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.RDFNode ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.impl.SecuredItem;
-
-/**
- * The interface for secured RDFNode instances.
- *
- * Use one the SecuredRDFNode derived class Factories to create instances
- */
-public interface SecuredRDFNode extends RDFNode, SecuredItem
-{
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public Node asNode() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public <T extends RDFNode> boolean canAs( final Class<T> view )
- throws AccessDeniedException;
-
- @Override
- public SecuredModel getModel();
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public RDFNode inModel( final Model m ) throws AccessDeniedException;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredReifiedStatement.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredReifiedStatement.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredReifiedStatement.java
deleted file mode 100644
index 67e33ad..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredReifiedStatement.java
+++ /dev/null
@@ -1,38 +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.model;
-
-import org.apache.jena.rdf.model.ReifiedStatement ;
-import org.apache.jena.security.AccessDeniedException;
-
-/**
- * The interface for secured ReifiedStatement instances.
- *
- * Use the SecuredReifiedStatement.Factory to create instances
- */
-public interface SecuredReifiedStatement extends ReifiedStatement,
- SecuredResource
-{
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement getStatement();
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredResource.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredResource.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredResource.java
deleted file mode 100644
index 18ba568..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredResource.java
+++ /dev/null
@@ -1,333 +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.model;
-
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.model.impl.SecuredStatementIterator;
-
-/**
- * The interface for secured Resource instances.
- *
- * Use the SecuredResource.Factory to create instances
- */
-public interface SecuredResource extends Resource, SecuredRDFNode
-{
-
- @Override
- public SecuredResource abort();
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource addLiteral( final Property p, final boolean o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addLiteral( final Property p, final char o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, value, d )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addLiteral( final Property value, final double d )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, value, d )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addLiteral( final Property value, final float d )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addLiteral( final Property p, final Literal o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addLiteral( final Property p, final long o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addLiteral( final Property p, final Object o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addProperty( final Property p, final RDFNode o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addProperty( final Property p, final String o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, literal(lexicalForm,datatype) )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addProperty( final Property p, final String lexicalForm,
- final RDFDatatype datatype ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public Resource addProperty( final Property p, final String o,
- final String l ) throws AccessDeniedException;
-
- @Override
- public SecuredResource asResource();
-
- @Override
- public SecuredResource begin();
-
- @Override
- public SecuredResource commit();
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean equals( final Object o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public AnonId getId() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getLocalName() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getNameSpace() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement getProperty( final Property p )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource getPropertyResourceValue( final Property p )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement getRequiredProperty( final Property p )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getURI() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasLiteral( final Property p, final boolean o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasLiteral( final Property p, final char o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasLiteral( final Property p, final double o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasLiteral( final Property p, final float o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasLiteral( final Property p, final long o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasLiteral( final Property p, final Object o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasProperty( final Property p ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasProperty( final Property p, final RDFNode o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasProperty( final Property p, final String o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this,p,literal(o,l))
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasProperty( final Property p, final String o, final String l )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasURI( final String uri ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read on returned Statements
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatementIterator listProperties()
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read on returned Statements
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatementIterator listProperties( final Property p )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete on associated Statements
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource removeAll( final Property p )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete on all Statements
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource removeProperties() throws AccessDeniedException;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredSeq.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredSeq.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredSeq.java
deleted file mode 100644
index 05977ea..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredSeq.java
+++ /dev/null
@@ -1,385 +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.model;
-
-import org.apache.jena.rdf.model.RDFNode ;
-import org.apache.jena.rdf.model.ResourceF ;
-import org.apache.jena.rdf.model.Seq ;
-import org.apache.jena.security.AccessDeniedException;
-
-/**
- * The interface for secured Seq instances.
- *
- * Use the SecuredSeq.Factory to create instances
- *
- * Sequence may have breaks in the order.
- * http://www.w3.org/TR/2004/REC-rdf-mt-20040210/#Containers
- *
- */
-public interface SecuredSeq extends Seq, SecuredContainer
-{
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq add( final int index, final boolean o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq add( final int index, final char o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq add( final int index, final double o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq add( final int index, final float o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq add( final int index, final long o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq add( final int index, final Object o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq add( final int index, final RDFNode o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq add( final int index, final String o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq add( final int index, final String o, final String l )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredAlt getAlt( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredBag getBag( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public boolean getBoolean( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public byte getByte( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public char getChar( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public double getDouble( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public float getFloat( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int getInt( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public String getLanguage( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredLiteral getLiteral( final int index )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public long getLong( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredRDFNode getObject( final int index )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredResource getResource( final int index )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- @Deprecated
- public SecuredResource getResource( final int index, final ResourceF f )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public SecuredSeq getSeq( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public short getShort( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public String getString( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int indexOf( final boolean o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int indexOf( final char o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int indexOf( final double o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int indexOf( final float o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int indexOf( final long o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int indexOf( final Object o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int indexOf( final RDFNode o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int indexOf( final String o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li(1), o )
- */
- @Override
- public int indexOf( final String o, final String l )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete SecTriple( this, RDF.li(1), o )
- * @sec.triple Update Triples after index
- */
- @Override
- public SecuredSeq remove( final int index ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
- * RDF.li(index), o )
- */
- @Override
- public SecuredSeq set( final int index, final boolean o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
- * RDF.li(index), o )
- */
- @Override
- public SecuredSeq set( final int index, final char o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
- * RDF.li(index), o )
- */
- @Override
- public SecuredSeq set( final int index, final double o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
- * RDF.li(index), o )
- */
- @Override
- public SecuredSeq set( final int index, final float o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
- * RDF.li(index), o )
- */
- @Override
- public SecuredSeq set( final int index, final long o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
- * RDF.li(index), o )
- */
- @Override
- public SecuredSeq set( final int index, final Object o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
- * RDF.li(index), o )
- */
- @Override
- public SecuredSeq set( final int index, final RDFNode o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
- * RDF.li(index), o )
- */
- @Override
- public SecuredSeq set( final int index, final String o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
- * RDF.li(index), o )
- */
- @Override
- public SecuredSeq set( final int index, final String o, final String l )
- throws AccessDeniedException;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredStatement.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredStatement.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredStatement.java
deleted file mode 100644
index 1f293fa..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredStatement.java
+++ /dev/null
@@ -1,295 +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.model;
-
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.impl.SecuredItem;
-
-/**
- * The interface for secured Statement instances.
- *
- * Use the SecuredStatement.Factory to create instances
- */
-public interface SecuredStatement extends Statement, SecuredItem
-{
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeLiteralObject( boolean o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeLiteralObject( char o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeLiteralObject( double o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeLiteralObject( float o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeLiteralObject( int o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeLiteralObject( long o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeObject( RDFNode o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeObject( String o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeObject( String o, boolean wellFormed )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeObject( String o, String l )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement changeObject( String o, String l, boolean wellFormed )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read, Update
- * @sec.triple Create
- * @throws AccessDeniedException
- */
- @Override
- public SecuredReifiedStatement createReifiedStatement()
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read, Update
- * @sec.triple Create
- * @throws AccessDeniedException
- */
- @Override
- public SecuredReifiedStatement createReifiedStatement( String uri )
- throws AccessDeniedException;
-
- @Override
- public SecuredAlt getAlt();
-
- @Override
- public SecuredBag getBag();
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean getBoolean() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public byte getByte() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public char getChar() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public double getDouble() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public float getFloat() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public int getInt() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getLanguage() throws AccessDeniedException;
-
- @Override
- public SecuredLiteral getLiteral();
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public long getLong() throws AccessDeniedException;
-
- @Override
- public SecuredModel getModel();
-
- @Override
- public SecuredRDFNode getObject();
-
- @Override
- public SecuredProperty getPredicate();
-
- @Override
- public SecuredStatement getProperty( Property p );
-
- @Override
- public SecuredResource getResource();
-
- @Override
- @Deprecated
- public SecuredResource getResource( ResourceF f );
-
- @Override
- public SecuredSeq getSeq();
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public short getShort() throws AccessDeniedException;
-
- @Override
- public SecuredStatement getStatementProperty( Property p );
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getString() throws AccessDeniedException;
-
- @Override
- public SecuredResource getSubject();
-
- /**
- * @sec.graph Read
- * @sec.triple Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean hasWellFormedXML() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean isReified() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read
- * @throws AccessDeniedException
- */
- @Override
- public RSIterator listReifiedStatements() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement remove() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete
- * @throws AccessDeniedException
- */
- @Override
- public void removeReification() throws AccessDeniedException;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredUnsupportedPolymorphismException.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredUnsupportedPolymorphismException.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredUnsupportedPolymorphismException.java
deleted file mode 100644
index 0fe619c..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredUnsupportedPolymorphismException.java
+++ /dev/null
@@ -1,36 +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.model;
-
-import org.apache.jena.enhanced.UnsupportedPolymorphismException ;
-import org.apache.jena.security.model.impl.SecuredRDFNodeImpl;
-
-/**
- * An extension to the UnsupportedPolymorphismException to handle
- * secured polymorphic changes.
- */
-public class SecuredUnsupportedPolymorphismException extends
- UnsupportedPolymorphismException
-{
-
- public SecuredUnsupportedPolymorphismException(
- final SecuredRDFNodeImpl node, final Class<?> type )
- {
- super( node, node.getModel() != null, type);
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredAltImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredAltImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredAltImpl.java
deleted file mode 100644
index 0d082fa..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredAltImpl.java
+++ /dev/null
@@ -1,339 +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.model.impl;
-
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemInvoker;
-import org.apache.jena.security.model.SecuredAlt;
-import org.apache.jena.security.model.SecuredBag;
-import org.apache.jena.security.model.SecuredLiteral;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredRDFNode;
-import org.apache.jena.security.model.SecuredResource;
-import org.apache.jena.security.model.SecuredSeq;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-
-/**
- * Implementation of SecuredAlt to be used by a SecuredItemInvoker proxy.
- */
-public class SecuredAltImpl extends SecuredContainerImpl implements SecuredAlt
-{
- /**
- * Get an instance of SecuredAlt.
- *
- * @param securedModel
- * the Secured Model to use.
- * @param alt
- * The Alt to be secured.
- * @return The secured Alt instance.
- */
- public static SecuredAlt getInstance( final SecuredModel securedModel,
- final Alt alt )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (alt == null)
- {
- throw new IllegalArgumentException("Alt may not be null");
- }
- final ItemHolder<Alt, SecuredAlt> holder = new ItemHolder<Alt, SecuredAlt>(
- alt);
- final SecuredAltImpl checker = new SecuredAltImpl(securedModel, holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (alt instanceof SecuredAlt)
- {
- if (checker.isEquivalent((SecuredAlt) alt))
- {
- return (SecuredAlt) alt;
- }
- }
- return holder.setSecuredItem(new SecuredItemInvoker(alt.getClass(),
- checker));
- }
-
- // The item holder holding this SecuredAlt
- private final ItemHolder<? extends Alt, ? extends SecuredAlt> holder;
-
- /**
- * Constructor.
- *
- * @param securedModel
- * the securedModel to use.
- * @param holder
- * The item holder that will hold this SecuredAlt.
- */
- protected SecuredAltImpl( final SecuredModel securedModel,
- final ItemHolder<? extends Alt, ? extends SecuredAlt> holder )
- {
- super(securedModel, holder);
- this.holder = holder;
- }
-
- @Override
- public SecuredRDFNode getDefault()
- {
- // getDefaultStatement() calls checkRead
- return SecuredRDFNodeImpl.getInstance(getModel(), getDefaultStatement()
- .getObject());
- }
-
- @Override
- public SecuredAlt getDefaultAlt()
- {
- // getDefaultStatement() calls checkRead
- return SecuredAltImpl.getInstance(getModel(), getDefaultStatement()
- .getAlt());
- }
-
- @Override
- public SecuredBag getDefaultBag()
- {
- // getDefaultStatement() calls checkRead
- return SecuredBagImpl.getInstance(getModel(), getDefaultStatement()
- .getBag());
- }
-
- @Override
- public boolean getDefaultBoolean()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getBoolean();
- }
-
- @Override
- public byte getDefaultByte()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getByte();
- }
-
- @Override
- public char getDefaultChar()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getChar();
- }
-
- @Override
- public double getDefaultDouble()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getDouble();
- }
-
- @Override
- public float getDefaultFloat()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getFloat();
- }
-
- @Override
- public int getDefaultInt()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getInt();
- }
-
- @Override
- public String getDefaultLanguage()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getLanguage();
- }
-
- @Override
- public SecuredLiteral getDefaultLiteral()
- {
- // getDefaultStatement() calls checkRead
- return SecuredLiteralImpl.getInstance(getModel(), getDefaultStatement()
- .getLiteral());
- }
-
- @Override
- public long getDefaultLong()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getLong();
- }
-
- @Override
- public SecuredResource getDefaultResource()
- {
- // getDefaultStatement() calls checkRead
- return SecuredResourceImpl.getInstance(getModel(),
- getDefaultStatement().getResource());
- }
-
- @Override
- @Deprecated
- public SecuredResource getDefaultResource( final ResourceF f )
- {
- // getDefaultStatement() calls checkRead
- return SecuredResourceImpl.getInstance(getModel(),
- getDefaultStatement().getResource(f));
- }
-
- @Override
- public SecuredSeq getDefaultSeq()
- {
- // getDefaultStatement() calls checkRead
- return SecuredSeqImpl.getInstance(getModel(), getDefaultStatement()
- .getSeq());
- }
-
- @Override
- public short getDefaultShort()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getShort();
-
- }
-
- private Statement getDefaultStatement()
- {
- checkRead();
- final ExtendedIterator<Statement> iter = getStatementIterator(Action.Read);
- try
- {
- if (iter.hasNext())
- {
- return iter.next();
- }
- throw new AltHasNoDefaultException(this);
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public String getDefaultString()
- {
- // getDefaultStatement() calls checkRead
- return getDefaultStatement().getString();
-
- }
-
- /*
- * private SecTriple getDefaultTriple()
- * {
- * final StmtIterator iter = holder.getBaseItem().getModel()
- * .listStatements(this, RDF.li(1), (RDFNode) null);
- * try
- * {
- * return iter.hasNext() ? iter.nextStatement().asTriple() : null;
- * }
- * finally
- * {
- * iter.close();
- * }
- *
- * }
- *
- * private SecTriple getNewTriple( final SecTriple t, final Object o )
- * {
- * return new SecTriple(t.getSubject(), t.getPredicate(),
- * SecNode.createLiteral(
- * String.valueOf(o), "", false));
- * }
- */
- @Override
- public SecuredAlt setDefault( final boolean o )
- {
- return setDefault( asObject( o ));
- }
-
- @Override
- public SecuredAlt setDefault( final char o )
- {
- return setDefault( asObject( o ));
- }
-
- @Override
- public SecuredAlt setDefault( final double o )
- {
- return setDefault( asObject( o ));
- }
-
- @Override
- public SecuredAlt setDefault( final float o )
- {
- return setDefault( asObject( o ));
- }
-
- @Override
- public SecuredAlt setDefault( final long o )
- {
- return setDefault( asObject( o ));
- }
-
- @Override
- public SecuredAlt setDefault( final Object o )
- {
- return setDefault( asObject( o ));
- }
-
- @Override
- public SecuredAlt setDefault( final RDFNode o )
- {
- checkUpdate();
- final ExtendedIterator<Statement> iter = getStatementIterator(Action.Read);
- try {
- if (iter.hasNext())
- {
- final Statement stmt = iter.next();
- final Triple t = stmt.asTriple();
- final Triple t2 = new Triple(t.getSubject(), t.getPredicate(),
- o.asNode());
- checkUpdate(t, t2);
- stmt.changeObject(o);
- return holder.getSecuredItem();
- }
- else
- {
- add( o );
- return holder.getSecuredItem();
- }
- }
- finally {
- iter.close();
- }
-
- }
-
- @Override
- public SecuredAlt setDefault( final String o )
- {
- return setDefault( asLiteral( o, "" ));
- }
-
- @Override
- public SecuredAlt setDefault( final String o, final String l )
- {
- return setDefault( asLiteral( o, l) );
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredBagImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredBagImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredBagImpl.java
deleted file mode 100644
index 9c8b3a1..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredBagImpl.java
+++ /dev/null
@@ -1,81 +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.model.impl;
-
-import org.apache.jena.rdf.model.Bag ;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemInvoker;
-import org.apache.jena.security.model.SecuredBag;
-import org.apache.jena.security.model.SecuredModel;
-
-/**
- * Implementation of SecuredBag to be used by a SecuredItemInvoker proxy.
- */
-public class SecuredBagImpl extends SecuredContainerImpl implements SecuredBag
-{
- /**
- * Get an instance of SecuredBag
- *
- * @param securedModel
- * The Secured Model to use.
- * @param bag
- * The bag to secure
- * @return The SecuredBag
- */
- public static SecuredBag getInstance( final SecuredModel securedModel,
- final Bag bag )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (bag == null)
- {
- throw new IllegalArgumentException("Bag may not be null");
- }
- final ItemHolder<Bag, SecuredBag> holder = new ItemHolder<Bag, SecuredBag>(
- bag);
- final SecuredBagImpl checker = new SecuredBagImpl(securedModel, holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (bag instanceof SecuredBag)
- {
- if (checker.isEquivalent((SecuredBag) bag))
- {
- return (SecuredBag) bag;
- }
- }
- return holder.setSecuredItem(new SecuredItemInvoker(bag.getClass(),
- checker));
- }
-
- /**
- * Constructor.
- *
- * @param securedModel
- * The Secured Model to use.
- * @param holder
- * The holder that will contain this SecuredBag.
- */
- protected SecuredBagImpl( final SecuredModel securedModel,
- final ItemHolder<? extends Bag, ? extends SecuredBag> holder )
- {
- super(securedModel, holder);
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredContainerImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredContainerImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredContainerImpl.java
deleted file mode 100644
index 2de34fa..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredContainerImpl.java
+++ /dev/null
@@ -1,576 +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.model.impl;
-
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemInvoker;
-import org.apache.jena.security.model.SecuredContainer;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.utils.ContainerFilter;
-import org.apache.jena.security.utils.PermStatementFilter;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.Map1 ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-import org.apache.jena.vocabulary.RDF ;
-
-/**
- * Implementation of SecuredContainer to be used by a SecuredItemInvoker proxy.
- */
-public class SecuredContainerImpl extends SecuredResourceImpl implements
- SecuredContainer
-{
- /**
- * Constructor
- *
- * @param securedModel
- * the Secured Model to use.
- * @param container
- * The container to secure.
- * @return The SecuredResource
- */
- public static SecuredContainer getInstance(
- final SecuredModel securedModel, final Container container )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (container == null)
- {
- throw new IllegalArgumentException("Container may not be null");
- }
-
- // check that resource has a securedModel.
- Container goodContainer = container;
- if (goodContainer.getModel() == null)
- {
- container.asNode();
- goodContainer = securedModel.createBag();
- }
-
- final ItemHolder<Container, SecuredContainer> holder = new ItemHolder<Container, SecuredContainer>(
- goodContainer);
-
- final SecuredContainerImpl checker = new SecuredContainerImpl(
- securedModel, holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (goodContainer instanceof SecuredContainer)
- {
- if (checker.isEquivalent((SecuredContainer) goodContainer))
- {
- return (SecuredContainer) goodContainer;
- }
- }
-
- return holder.setSecuredItem(new SecuredItemInvoker(container
- .getClass(), checker));
-
- }
-
- // the item holder that contains this SecuredContainer.
- private final ItemHolder<? extends Container, ? extends SecuredContainer> holder;
-
- /**
- * Constructor
- *
- * @param securedModel
- * the Secured Model to use.
- * @param holder
- * The item holder that will contain this SecuredContainer
- */
- protected SecuredContainerImpl(
- final SecuredModel securedModel,
- final ItemHolder<? extends Container, ? extends SecuredContainer> holder )
- {
- super(securedModel, holder);
- this.holder = holder;
- // listener=new ChangeListener();
- // holder.getBaseItem().getModel().register(listener);
- }
-
- protected RDFNode asObject( Object o )
- {
- return o instanceof RDFNode ? (RDFNode) o : ResourceFactory.createTypedLiteral( o );
- }
-
- protected RDFNode asLiteral( String o, String l )
- {
- return holder.getBaseItem().getModel().createLiteral(o, l);
- }
-
- @Override
- public SecuredContainer add( final boolean o )
- {
- return add( asObject( o ));
- }
-
- @Override
- public SecuredContainer add( final char o )
- {
- return add( asObject( o ));
- }
-
- @Override
- public SecuredContainer add( final double o )
- {
- return add( asObject( o ));
- }
-
- @Override
- public SecuredContainer add( final float o )
- {
- return add( asObject( o ));
- }
-
- @Override
- public SecuredContainer add( final long o )
- {
- return add( asObject( o ));
- }
-
- @Override
- public SecuredContainer add( final Object o )
- {
- return add( asObject( o ));
- }
-
- @Override
- public SecuredContainer add( final RDFNode o )
- {
- checkUpdate();
- final int pos = holder.getBaseItem().size();
- checkAdd(pos, o.asNode());
- holder.getBaseItem().add(o);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredContainer add( final String o )
- {
- return add( asLiteral( o, "" ));
- }
-
- @Override
- public SecuredContainer add( final String o, final String l )
- {
- return add( asLiteral( o, l));
- }
-
- protected void checkAdd( final int pos, final Literal literal )
- {
- checkAdd(pos, literal.asNode());
- }
-
- protected void checkAdd( final int pos, final Node node )
- {
- checkCreate(new Triple(holder.getBaseItem().asNode(), RDF.li(pos)
- .asNode(), node));
- }
-
- @Override
- public boolean contains( final boolean o )
- {
- return contains( asObject( o ) );
- }
-
- @Override
- public boolean contains( final char o )
- {
- return contains( asObject( o ) );
- }
-
- @Override
- public boolean contains( final double o )
- {
- return contains( asObject( o ) );
- }
-
- @Override
- public boolean contains( final float o )
- {
- return contains( asObject( o ) );
- }
-
- @Override
- public boolean contains( final long o )
- {
- return contains( asObject( o ) );
- }
-
- @Override
- public boolean contains( final Object o )
- {
- return contains( asObject( o ) );
- }
-
- @Override
- public boolean contains( final RDFNode o )
- {
- // iterator check reads
- final SecuredNodeIterator<RDFNode> iter = iterator();
- while (iter.hasNext())
- {
- if (iter.next().asNode().equals(o.asNode()))
- {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean contains( final String o )
- {
- return contains( asLiteral( o, "" ));
- }
-
- @Override
- public boolean contains( final String o, final String l )
- {
- return contains( asLiteral( o, l ));
- }
-
- protected int getAddIndex()
- {
- int pos = -1;
- final ExtendedIterator<Statement> iter = holder.getBaseItem()
- .listProperties();
- try
- {
- while (iter.hasNext())
- {
- pos = Math.max(pos, getIndex(iter.next().getPredicate()));
- }
- }
- finally
- {
- iter.close();
- }
- return pos + 1;
- }
-
- protected static int getIndex( final Property p )
- {
- if (p.getNameSpace().equals(RDF.getURI())
- && p.getLocalName().startsWith("_"))
- {
- try
- {
- return Integer.parseInt(p.getLocalName().substring(1));
- }
- catch (final NumberFormatException e)
- {
- // acceptable;
- }
- }
- return -1;
- }
-
- protected ExtendedIterator<Statement> getStatementIterator(
- final Action perm )
- {
- return holder.getBaseItem().listProperties()
- .filterKeep(new ContainerFilter())
- .filterKeep(new PermStatementFilter(perm, this));
- }
-
- protected ExtendedIterator<Statement> getStatementIterator(
- final Set<Action> perm )
- {
- return holder.getBaseItem().listProperties()
- .filterKeep(new ContainerFilter())
- .filterKeep(new PermStatementFilter(perm, this));
- }
-
- @Override
- public boolean isAlt()
- {
- return holder.getBaseItem().isAlt();
- }
-
- @Override
- public boolean isBag()
- {
- return holder.getBaseItem().isBag();
- }
-
- @Override
- public boolean isSeq()
- {
- return holder.getBaseItem().isSeq();
- }
-
- @Override
- public SecuredNodeIterator<RDFNode> iterator()
- {
- // listProperties calls checkRead();
- SecuredStatementIterator iter = listProperties();
- try {
- SortedSet<Statement> result = new TreeSet<Statement>( new ContainerComparator() );
- while (iter.hasNext()) {
- Statement stmt = iter.next();
- if (stmt.getPredicate().getOrdinal() > 0)
- {
- result.add( stmt );
- }
- }
- return new SecuredNodeIterator<RDFNode>(getModel(), new StatementRemovingIterator(result.iterator()).mapWith( new NodeMap() ) );
- }
- finally {
- iter.close();
- }
- }
-
- @Override
- public SecuredNodeIterator<RDFNode> iterator( final Set<Action> perms )
- {
- checkRead();
- final Set<Action> permsCopy = new HashSet<Action>(perms);
- permsCopy.add(Action.Read);
- final ExtendedIterator<RDFNode> ni = getStatementIterator(perms)
- .mapWith(new Map1<Statement, RDFNode>() {
-
- @Override
- public RDFNode map1( final Statement o )
- {
- return o.getObject();
- }
- });
- return new SecuredNodeIterator<RDFNode>(getModel(), ni);
-
- }
-
- @Override
- public SecuredContainer remove( final Statement s )
- {
- checkUpdate();
- checkDelete(s.asTriple());
- holder.getBaseItem().remove(s);
- return holder.getSecuredItem();
- }
-
- @Override
- public int size()
- {
- checkRead();
- return holder.getBaseItem().size();
- }
- /*
- * private synchronized void resetIndexes()
- * {
- * indexes.clear();
- * }
- */
- /*
- /**
- * find the position of i in the array
- *
- * @param i
- * @return the position or x<0 if not found.
- */
- /*
- * protected int mapValue( int i )
- * {
- * rebuildIndex();
- * return Collections.binarySearch( indexes, i );
- * }
- *
- * // return the value at position i
- * protected int unmapValue( int i )
- * {
- * return indexes.get(i);
- * }
- *
- *
- * private synchronized void rebuildIndex()
- * {
- * if (indexes.isEmpty())
- * {
- * ExtendedIterator<Statement> iter = getStatementIterator( Action.Read );
- * try {
- * while (iter.hasNext())
- * {
- * indexes.add( getIndex( iter.next().getPredicate() ) );
- * }
- * }
- * finally {
- * iter.close();
- * }
- * Collections.sort(indexes);
- * }
- * }
- *
- * private class ChangeListener implements ModelChangedListener
- * {
- *
- * private void checkStatement( Statement s )
- * {
- * if (indexes != null && s.getSubject().equals( holder.getBaseItem()))
- * {
- * resetIndexes();
- * }
- * }
- *
- * private void checkStatements( Iterator<Statement> iter )
- * {
- * while( indexes != null && iter.hasNext())
- * {
- * checkStatement( iter.next() );
- * }
- * }
- *
- * @Override
- * public void addedStatement( Statement s )
- * {
- * checkStatement( s );
- * }
- *
- * @Override
- * public void addedStatements( Statement[] statements )
- * {
- * checkStatements( Arrays.asList(statements).iterator() );
- * }
- *
- * @Override
- * public void addedStatements( List<Statement> statements )
- * {
- * checkStatements( statements.iterator() );
- * }
- *
- * @Override
- * public void addedStatements( StmtIterator statements )
- * {
- * try {
- * checkStatements( statements );
- * }
- * finally {
- * statements.close();
- * }
- * }
- *
- * @Override
- * public void addedStatements( Model baseModel )
- * {
- * addedStatements( baseModel.listStatements() );
- * }
- *
- * @Override
- * public void removedStatement( Statement s )
- * {
- * checkStatement( s );
- * }
- *
- * @Override
- * public void removedStatements( Statement[] statements )
- * {
- * checkStatements( Arrays.asList(statements).iterator() );
- * }
- *
- * @Override
- * public void removedStatements( List<Statement> statements )
- * {
- * checkStatements( statements.iterator() );
- * }
- *
- * @Override
- * public void removedStatements( StmtIterator statements )
- * {
- * try {
- * checkStatements( statements );
- * }
- * finally {
- * statements.close();
- * }
- * }
- *
- * @Override
- * public void removedStatements( Model baseModel )
- * {
- * removedStatements( baseModel.listStatements() );
- * }
- *
- * @Override
- * public void notifyEvent( Model baseModel, Object event )
- * {
- * // do nothing
- * }
- *
- * }
- */
-
- static class NodeMap implements Map1<Statement,RDFNode>
- {
-
- @Override
- public RDFNode map1( Statement o )
- {
- return o.getObject();
- }
-
- }
-
- static class ContainerComparator implements Comparator<Statement>
- {
-
- @Override
- public int compare( Statement arg0, Statement arg1 )
- {
- return Integer.valueOf(arg0.getPredicate().getOrdinal()).compareTo( arg1.getPredicate().getOrdinal());
- }
-
- }
-
- static class StatementRemovingIterator extends WrappedIterator<Statement>
- {
- private Statement stmt;
-
- public StatementRemovingIterator( Iterator<? extends Statement> base )
- {
- super(base);
- }
-
- @Override
- public Statement next()
- {
- stmt = super.next();
- return stmt;
- }
-
- @Override
- public void remove()
- {
- stmt.remove();
- super.remove();
- }
-
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredLiteralImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredLiteralImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredLiteralImpl.java
deleted file mode 100644
index 9d78388..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredLiteralImpl.java
+++ /dev/null
@@ -1,277 +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.model.impl;
-
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.RDFVisitor ;
-import org.apache.jena.rdf.model.ResourceRequiredException ;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemInvoker;
-import org.apache.jena.security.model.SecuredLiteral;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredResource;
-
-/**
- * Implementation of SecuredLiteral to be used by a SecuredItemInvoker proxy.
- */
-public class SecuredLiteralImpl extends SecuredRDFNodeImpl implements
- SecuredLiteral
-{
- /**
- * Get an instance of SecuredLiteral
- *
- * @param securedModel
- * the item providing the security context.
- * @param literal
- * the literal to secure
- * @return SecuredLiteral
- */
- public static SecuredLiteral getInstance( final SecuredModel securedModel,
- final Literal literal )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (literal == null)
- {
- throw new IllegalArgumentException("literal may not be null");
- }
-
- // check that literal has a securedModel.
- Literal goodLiteral = literal;
- if (goodLiteral.getModel() == null)
- {
- goodLiteral = securedModel.createTypedLiteral(
- literal.getLexicalForm(), literal.getDatatype());
- }
-
- final ItemHolder<Literal, SecuredLiteral> holder = new ItemHolder<Literal, SecuredLiteral>(
- goodLiteral);
- final SecuredLiteralImpl checker = new SecuredLiteralImpl(securedModel,
- holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (goodLiteral instanceof SecuredLiteral)
- {
- if (checker.isEquivalent((SecuredLiteral) goodLiteral))
- {
- return (SecuredLiteral) goodLiteral;
- }
- }
- return holder.setSecuredItem(new SecuredItemInvoker(literal.getClass(),
- checker));
- }
-
- // the item holder that contains this SecuredLiteral
- private final ItemHolder<? extends Literal, ? extends SecuredLiteral> holder;
-
- /**
- * Constructor
- *
- * @param securityEvaluator
- * The security evaluator to use.
- * @param graphIRI
- * the graph IRI to validate against.
- * @param holder
- * The item holder that will contain this SecuredLiteral.
- */
-
- private SecuredLiteralImpl( final SecuredModel securedModel,
- final ItemHolder<? extends Literal, ? extends SecuredLiteral> holder )
- {
- super(securedModel, holder);
- this.holder = holder;
- }
-
- @Override
- public SecuredLiteral asLiteral()
- {
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredResource asResource()
- {
- if (canRead())
- {
- throw new ResourceRequiredException(asNode());
- }
- else
- {
- throw new ResourceRequiredException(
- Node.createLiteral("Can not read"));
- }
- }
-
- @Override
- public boolean getBoolean()
- {
- checkRead();
- return holder.getBaseItem().getBoolean();
- }
-
- @Override
- public byte getByte()
- {
- checkRead();
- return holder.getBaseItem().getByte();
- }
-
- @Override
- public char getChar()
- {
- checkRead();
- return holder.getBaseItem().getChar();
- }
-
- /**
- * Return the datatype of the literal. This will be null in the
- * case of plain literals.
- */
- @Override
- public RDFDatatype getDatatype()
- {
- checkRead();
- return holder.getBaseItem().getDatatype();
- }
-
- /**
- * Return the uri of the datatype of the literal. This will be null in the
- * case of plain literals.
- */
- @Override
- public String getDatatypeURI()
- {
- checkRead();
- return holder.getBaseItem().getDatatypeURI();
- }
-
- @Override
- public double getDouble()
- {
- checkRead();
- return holder.getBaseItem().getDouble();
- }
-
- @Override
- public float getFloat()
- {
- checkRead();
- return holder.getBaseItem().getFloat();
- }
-
- @Override
- public int getInt()
- {
- checkRead();
- return holder.getBaseItem().getInt();
- }
-
- @Override
- public String getLanguage()
- {
- checkRead();
- return holder.getBaseItem().getLanguage();
- }
-
- /**
- * Return the lexical form of the literal.
- */
- @Override
- public String getLexicalForm()
- {
- checkRead();
- return holder.getBaseItem().getLexicalForm();
- }
-
- @Override
- public long getLong()
- {
- checkRead();
- return holder.getBaseItem().getLong();
- }
-
- @Override
- public short getShort()
- {
- checkRead();
- return holder.getBaseItem().getShort();
- }
-
- @Override
- public String getString()
- {
- checkRead();
- return holder.getBaseItem().getString();
- }
-
- /**
- * Return the value of the literal. In the case of plain literals
- * this will return the literal string. In the case of typed literals
- * it will return a java object representing the value. In the case
- * of typed literals representing a java primitive then the appropriate
- * java wrapper class (Integer etc) will be returned.
- */
- @Override
- public Object getValue()
- {
- checkRead();
- return holder.getBaseItem().getValue();
- }
-
- @Override
- public Literal inModel( final Model m )
- {
- checkRead();
- return m.createTypedLiteral(holder.getBaseItem().getLexicalForm(),
- holder.getBaseItem().getDatatype());
- }
-
- @Override
- public boolean isWellFormedXML()
- {
- checkRead();
- return holder.getBaseItem().isWellFormedXML();
- }
-
- /**
- * Test that two literals are semantically equivalent.
- * In some cases this may be the sames as equals, in others
- * equals is stricter. For example, two xsd:int literals with
- * the same value but different language tag are semantically
- * equivalent but distinguished by the java equality function
- * in order to support round tripping.
- */
- @Override
- public boolean sameValueAs( final Literal other )
- {
- checkRead();
- return holder.getBaseItem().sameValueAs(other);
- }
-
- @Override
- public Object visitWith( final RDFVisitor rv )
- {
- return rv.visitLiteral(this);
- }
-}
[23/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/SecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/SecurityEvaluator.java b/jena-permissions/src/main/java/org/apache/jena/security/SecurityEvaluator.java
new file mode 100644
index 0000000..c700090
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/SecurityEvaluator.java
@@ -0,0 +1,616 @@
+/*
+ * 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.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+
+/**
+ * SecurityEvaluator.
+ * <p>
+ * The security evaluator is the link between the graph security system and an
+ * external security system. This interface specifies the methods that are
+ * required by the graph security system. It is assumed that the implementation
+ * will handle tracking the current user and will query some underlying data
+ * source to determine what actions the user can and can not take.
+ * </p>
+ * <p>
+ * All questions of white listing or black listing will be handled in the
+ * concrete implementation.
+ * </p>
+ * <p>
+ * Implementations of this class should probably cache any evaluate calculations
+ * as the evaluate methods are called frequently. However, the underlying
+ * classes do cache results within a single method check.
+ * </p>
+ * <p>
+ * <dl>
+ * <dt>Secured operations</dt>
+ * <dd>The security system recognizes and secures each of the CRUD (Create,
+ * Read, Update and Delete) operations as represented by the Action enumeration.
+ * </dd>
+ * </dl>
+ * <dl>
+ * <dt>Levels of security</dt>
+ * <dd>The security interfaces operates at two (2) levels: graph (or Model) and
+ * triple.
+ * <p>
+ * At the the graph level the security evaluator may restrict CRUD access to the
+ * graph or model as a whole. When evaluating the restriction, if the user it
+ * not permitted to perform the operation on the graph or model access is
+ * denied. If the user is permitted any triple restrictions are evaluated.
+ * </p>
+ * <p>
+ * At the triple level the security evaluator may restrict CRUD access to
+ * specific triples. In order to skip potentially expensive triple security
+ * checks the system will generally ask if the user is permitted the CRUD action
+ * on any triple. This is represented by the SecTriple
+ * <code>(ANY, ANY, ANY)</code>.
+ * <ul>
+ * <li>
+ * If the system does not support triple level security the system should always
+ * return <code>true</code>.</li>
+ * If the system does support triple level security and is unable to verify that
+ * the user can execute the CRUD action against any arbitrary triple the system
+ * should return <code>false</code>. </li>
+ * <li>See <code>SecNode.ANY</code>, <code>SecNode.FUTURE</code>, and
+ * <code>SecNode.VARIABLE</code> for discussion of specifics of their respective
+ * usages.</li>
+ * </ul>
+ * </p>
+ * </dd>
+ * </dl>
+ * <dl>
+ * <dt>
+ *
+ * </p>
+ */
+public interface SecurityEvaluator {
+ /**
+ * Identifies a sepcific CRUD actions.
+ */
+ static enum Action {
+ /**
+ * Allow creation of the object in question.
+ */
+ Create,
+ /**
+ * Allow the user to read the object in question.
+ */
+ Read,
+ /**
+ * Allow the user to update the object in question
+ */
+ Update,
+ /**
+ * Allow the user to delete the object in question.
+ */
+ Delete
+
+ }
+
+ /**
+ * A node in the evaluation.
+ * <p>
+ * A node with no value represents a node of that type but unknown
+ * exactitude. (e.g. <code>SecNode(URI,"")</code> is a URI but of unknown
+ * value. Useful for systems that restrict type creation.
+ * </p>
+ * <p>
+ * <code>SecNode(Anonymous,"")</code> represents an anonymous node that will
+ * be created. Otherwise anonymous node values are the values within the
+ * secured graph.
+ * </p>
+ * <p>
+ * An "Any" node type matches any node.
+ * </p>
+ */
+ public static class SecNode implements Comparable<SecNode> {
+
+ /**
+ * The types of nodes.
+ */
+ public static enum Type {
+ /**
+ * A URI type node
+ */
+ URI,
+ /**
+ * A Literal node.
+ */
+ Literal,
+ /**
+ * An anonymous node. Also called a "blank" node.
+ */
+ Anonymous,
+ /**
+ * Any node.
+ */
+ Any
+ }
+
+ /**
+ * Matches any node in the security system.
+ * <p>
+ * Used in triple checks as follows:
+ * <dl>
+ * <dt><code>(ANY, ANY, ANY)</code></dt>
+ * <dd>Asks if the user may perform the action on any triple.</dd>
+ * <dt><code>(X, ANY, ANY)</code></dt>
+ * <dd>Asks if the user may perform the action against any triple where
+ * X is the subject.</dd>
+ * <dt><code>(ANY, X, ANY)</code></dt>
+ * <dd>Asks if the user may perform the action against any triple where
+ * X is the predicate.</dd>
+ * <dt><code>(SecNode.ANY, SecNode.ANY, SecNode.X)</code></dt>
+ * <dd>Asks if if the user may perform the action against any triple
+ * where X is the object.</dd>
+ * </dl>
+ * The <code>ANY</code> may occur multiple times and may occur with the
+ * <code>VARIABLE</code> and/or <code>FUTURE</code> nodes.
+ * </p>
+ */
+ public static final SecNode ANY = new SecNode(Type.Any, "any");
+
+ /**
+ * Indicates a variable in the triple.
+ * <p>
+ * </p>
+ * This differs from <code>ANY</code> in that the system is asking if
+ * there are any prohibitions not if the user may perform. Thus queries
+ * with the VARIABLE type node should return <code>true</code> where
+ * <code>ANY</code> returns <code>false</code>. In general this type is
+ * used in the query to determine if triple level filtering of results
+ * must be performed.
+ * <p>
+ * </p>
+ * <p>
+ * <dl>
+ * <dt><code>(VARIABLE, X, Y )</code></dt>
+ * <dd>
+ * Asks if there are any prohibitions against the user seeing all
+ * subjects that have property X and object Y.</dd>
+ * <dt>
+ * <code>(X, VARIABLE, Y )</code></dt>
+ * <dd>
+ * Asks if there are any prohibitions against the user seeing all
+ * predicates that have subject X and object Y.</dd>
+ * <dt>
+ * <code>(X, Y, VARIABLE)</code></dt>
+ * <dd>
+ * Asks if there are any prohibitions against the user seeing all
+ * objects that have subject X and predicate Y.</dd>
+ * </dl>
+ * The <code>VARIABLE</code> may occur multiple times and may occur with
+ * the <code>ANY</code> node.
+ * </p>
+ *
+ */
+ public static final SecNode VARIABLE = new SecNode(Type.Any, "variable");
+
+ /**
+ * This is an anonymous node that will be created in the future.
+ * <p>
+ * FUTURE is used to check that an anonymous node may be created in as
+ * specific position in a triple.
+ * </p>
+ * <p>
+ * <dl>
+ * <dt><code>(FUTURE, X, Y )</code></dt>
+ * <dd>
+ * Asks if there the user may create an anonymous node that has property
+ * X and object Y.</dd>
+ * <dt>
+ * <code>(X, Y, FUTURE)</code></dt>
+ * <dd>
+ * Asks if there the user may create an anonymous node that has subject
+ * X and property Y.</dd>
+ * </dl>
+ * The <code>FUTURE</code> may occur multiple times and may occur with
+ * the <code>ANY</code> node.
+ * </p>
+ */
+ public static final SecNode FUTURE = new SecNode(Type.Anonymous, "");
+
+ private final Type type;
+ private final String value;
+ private Integer hashCode;
+
+ /**
+ * Create a SecNode of the type and value.
+ *
+ * @param type
+ * The type of the node
+ * @param value
+ * The value of the node. A null is interpreted as an empty
+ * string.
+ */
+ public SecNode(final Type type, final String value) {
+ this.type = type;
+ this.value = value == null ? "" : value;
+ }
+
+ @Override
+ public int compareTo(final SecNode node) {
+ final int retval = type.compareTo(node.type);
+ return retval == 0 ? value.compareTo(node.value) : retval;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (o instanceof SecNode) {
+ return this.compareTo((SecNode) o) == 0;
+ }
+ return false;
+ }
+
+ /**
+ * Get the type of the node.
+ *
+ * @return The type of the node.
+ */
+ public Type getType() {
+ return type;
+ }
+
+ /**
+ * Get the value of the node.
+ *
+ * @return the value of the node
+ */
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public int hashCode() {
+ if (hashCode == null) {
+ hashCode = new HashCodeBuilder().append(type).append(value)
+ .toHashCode();
+ }
+ return hashCode;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[%s:%s]", getType(), getValue());
+ }
+ }
+
+ /**
+ * An immutable triple of SecNodes.
+ */
+ public static class SecTriple implements Comparable<SecTriple> {
+ private final SecNode subject;
+ private final SecNode predicate;
+ private final SecNode object;
+ private transient Integer hashCode;
+
+ /**
+ * The triple of <code>(ANY, ANY, ANY)</code>.
+ */
+ public static final SecTriple ANY = new SecTriple(SecNode.ANY,
+ SecNode.ANY, SecNode.ANY);
+
+ /**
+ * Create the sec triple
+ *
+ * @param subject
+ * The subject node.
+ * @param predicate
+ * The predicate node.
+ * @param object
+ * The object node.
+ * @throws IllegalArgumentException
+ * is any value is null.
+ */
+ public SecTriple(final SecNode subject, final SecNode predicate,
+ final SecNode object) {
+ if (subject == null) {
+ throw new IllegalArgumentException("Subject may not be null");
+ }
+ if (predicate == null) {
+ throw new IllegalArgumentException("Predicate may not be null");
+ }
+ if (object == null) {
+ throw new IllegalArgumentException("Object may not be null");
+ }
+ this.subject = subject;
+ this.predicate = predicate;
+ this.object = object;
+ }
+
+ @Override
+ public int compareTo(final SecTriple o) {
+ if (o == null) {
+ return 1;
+ }
+ int retval = subject.compareTo(o.subject);
+ if (retval == 0) {
+ retval = predicate.compareTo(o.predicate);
+ }
+ return retval == 0 ? object.compareTo(o.object) : retval;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (o instanceof SecTriple) {
+ return this.compareTo((SecTriple) o) == 0;
+ }
+ return false;
+ }
+
+ /**
+ * @return the object node.
+ */
+ public SecNode getObject() {
+ return object;
+ }
+
+ /**
+ * @return the predicate node.
+ */
+ public SecNode getPredicate() {
+ return predicate;
+ }
+
+ /**
+ * @return the subject node.
+ */
+ public SecNode getSubject() {
+ return subject;
+ }
+
+ @Override
+ public int hashCode() {
+ if (hashCode == null) {
+ hashCode = new HashCodeBuilder().append(object)
+ .append(predicate).append(subject).toHashCode();
+ }
+ return hashCode;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("( %s, %s, %s )", getSubject(),
+ getPredicate(), getObject());
+ }
+ }
+
+ /**
+ * A collection of utility functions for the SecurityEvaluator
+ * implementations.
+ */
+ public static class Util {
+ /**
+ * Return an array of actions as a set.
+ * <p>
+ * The order of the collection is preserved
+ * </p>
+ *
+ * @param actions
+ * The actions.
+ * @return The set of actions.
+ */
+ public static Set<Action> asSet(final Action[] actions) {
+ return Util.asSet(Arrays.asList(actions));
+ }
+
+ /**
+ * Return a collection of actions as a set.
+ * <p>
+ * The order of the collection is preserved
+ * </p>
+ *
+ * @param actions
+ * The collection of actions.
+ * @return The set of actions.
+ */
+ public static Set<Action> asSet(final Collection<Action> actions) {
+ if (actions instanceof Set) {
+ return (Set<Action>) actions;
+ }
+ else {
+ return new LinkedHashSet<Action>(actions);
+ }
+ }
+ }
+
+ /**
+ * Determine if the action is allowed on the graph.
+ *
+ * @param principal
+ * The principal that is attempting the action.
+ *
+ * @param action
+ * The action to perform
+ * @param graphIRI
+ * The IRI of the graph to check
+ * @return true if the action is allowed, false otherwise.
+ */
+ public boolean evaluate(Object principal, Action action, SecNode graphIRI);
+
+ /**
+ * Determine if the action is allowed on the triple within the graph.
+ * <p>
+ * The evaluation should be performed in the following order:
+ * <ol>
+ * <li>
+ * If the triple contains a <code>VARIABLE</code> then this method must
+ * return <code>true</code> if there are any restrictions where the
+ * remaining nodes are either constants or <code>ANY</code> nodes. This will
+ * force the system to use subsequent checks to verify access by
+ * substituting the value of the <code>VARIABLE</code>s.
+ * <em>If the system can not quickly verify the solution
+ * it is always acceptable to return <code>true</code>.</em>
+ * <li>
+ * Except as specified in the above check, if the triple contains an
+ * <code>ANY</code> then this method must return <code>false</code> if there
+ * are any restrictions where the remaining nodes are held constant and the
+ * ANY node is allowed to vary. This checks is used to avoid subsequent
+ * explicit triple checks.
+ * <em>If the system can not quickly verify the solution it is always
+ * acceptable to return <code>false</code>.</em></li>
+ * <li>All other triples are explict triples and the system must determine
+ * if the user is permitted to perform the action on the triple. If the
+ * triple contains a <code>FUTURE</code> node that node should be considered
+ * as an anonymous or blank node that is not yet created. It should only be
+ * used with <code>Create</code> actions and is asking if the user may
+ * create a blank node in that position in the triple.</li>
+ * </ol>
+ * </p>
+ *
+ * @param principal
+ * The principal that is attempting the action.
+ *
+ * @param action
+ * The action to perform
+ * @param graphIRI
+ * The IRI of the graph to the action is being taken upon. May be
+ * <code>ANY</code>.
+ * @param triple
+ * The triple to check
+ * @return true if the action is allowed, false otherwise.
+ * @throws IllegalArgumentException
+ * if any argument is null.
+ */
+ public boolean evaluate(Object principal, Action action, SecNode graphIRI,
+ SecTriple triple);
+
+ /**
+ * Determine if all actions are allowed on the graph.
+ *
+ * @param principal
+ * The principal that is attempting the action.
+ *
+ * @param actions
+ * The set of actions to perform
+ * @param graphIRI
+ * The IRI of the graph to the action is being taken upon. May be
+ * <code>ANY</code>.
+ * @return true if all the actions are allowed, false otherwise.
+ * @throws IllegalArgumentException
+ * if any argument is null.
+ */
+ public boolean evaluate(Object principal, Set<Action> actions,
+ SecNode graphIRI);
+
+ /**
+ * Determine if all the actions are allowed on the triple within the graph.
+ * <p>
+ * See evaluate( Action, SecNode, SecTriple ) for discussion of evaluation
+ * strategy.
+ * </p>
+ *
+ * @param actions
+ * The actions to perform.
+ * @param graphIRI
+ * The IRI of the graph to the action is being taken upon. May be
+ * <code>ANY</code>.
+ * @param triple
+ * The triple to check
+ * @return true if all the actions are allowed, false otherwise.
+ * @throws IllegalArgumentException
+ * if any argument is null.
+ */
+ public boolean evaluate(Object principal, Set<Action> actions,
+ SecNode graphIRI, SecTriple triple);
+
+ /**
+ * Determine if any of the actions are allowed on the graph.
+ *
+ * @param principal
+ * The principal that is attempting the action.
+ *
+ * @param actions
+ * The actions to perform
+ * @param graphIRI
+ * The IRI of the graph to the action is being taken upon. May be
+ * <code>ANY</code>.
+ * @return true true if any the actions are allowed, false otherwise.
+ * @throws IllegalArgumentException
+ * if any argument is null.
+ */
+ public boolean evaluateAny(Object principal, Set<Action> actions,
+ SecNode graphIRI);
+
+ /**
+ * Determine if any of the actions are allowed on the triple within the
+ * graph.
+ * <p>
+ * See evaluate( Action, SecNode, SecTriple ) for discussion of evaluation
+ * strategy.
+ * </p>
+ *
+ * @param principal
+ * The principal that is attempting the action.
+ *
+ * @param actions
+ * The actions to check.
+ * @param graphIRI
+ * The IRI of the graph to the action is being taken upon. May be
+ * <code>ANY</code>.
+ * @param triple
+ * The triple to check
+ * @return true if any the actions are allowed, false otherwise.
+ * @throws IllegalArgumentException
+ * if any argument is null.
+ */
+ public boolean evaluateAny(Object principal, Set<Action> actions,
+ SecNode graphIRI, SecTriple triple);
+
+ /**
+ * Determine if the user is allowed to update the "from" triple to the "to"
+ * triple.
+ * <p>
+ * Update is a special case since it modifies one triple to be another. So
+ * the user must have permissions to change the "from" triple into the "to"
+ * triple.
+ *
+ * @param principal
+ * The principal that is attempting the action.
+ * @param graphIRI
+ * The IRI of the graph to the action is being taken upon. May be
+ * <code>ANY</code>.
+ * @param from
+ * The triple to be changed
+ * @param to
+ * The value to change it to.
+ * @return true if the user may make the change, false otherwise.
+ * @throws IllegalArgumentException
+ * if any argument is null.
+ */
+ public boolean evaluateUpdate(Object principal, SecNode graphIRI,
+ SecTriple from, SecTriple to);
+
+ /**
+ * returns the current principal or null if there is no current principal.
+ *
+ * All security evaluation methods use this method to determine who the call
+ * is being executed as. This allows subsystems (like the listener system)
+ * to capture the current user and evaluate later calls in terms of that
+ * user.
+ *
+ * @return The current principal
+ */
+ public Object getPrincipal();
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/SecurityEvaluatorAssembler.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/SecurityEvaluatorAssembler.java b/jena-permissions/src/main/java/org/apache/jena/security/SecurityEvaluatorAssembler.java
new file mode 100644
index 0000000..57f6dfd
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/SecurityEvaluatorAssembler.java
@@ -0,0 +1,183 @@
+/*
+ * 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.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jena.assembler.Assembler ;
+import org.apache.jena.assembler.Mode ;
+import org.apache.jena.assembler.assemblers.AssemblerBase ;
+import org.apache.jena.assembler.exceptions.AssemblerException ;
+import org.apache.jena.rdf.model.* ;
+
+/**
+ * A simple assembler for a SecurityEvaluator
+ * <p>
+ * This assembler load the specified class, locates the first constructor that accepts
+ * the number of arguments in the assembler file, and calls it passing the arguments.
+ * Generally the result of this assembler is passed to a sec:Model construction.
+ * @see SecuredAssembler
+ * </p>
+ * <ul>
+ * <li>The evaluator must have one and only one public constructor
+ * that takes the number of arguments specified in the assembler file.
+ * </li>
+ *
+ * <li>
+ * The evaluator may have more constructors but they may not have the same
+ * number of arguments as specified in the assembler file.
+ * </li>
+ *
+ * <li>
+ * The arguments must be specified in the assembler file in the order that they
+ * should be passed to the constructor.
+ * </li>
+ * </ul>
+ *
+ * <p>
+ * Literal arguments are converted to their data type before calling the constructor. For example
+ * "13"^^xsd:int will be converted to an Integer with the value of 13.
+ * </p>
+ * The assembler file should include the following
+ * <code><pre>
+ * @prefix xsd: <http://www.w3.org/2001/XMLSchema#>
+ *
+ * <>; ja:loadClass "org.apache.jena.security.SecuredAssembler" .
+ *
+ * sec:Model rdfs:subClassOf ja:NamedModel .
+ *
+ * </pre></code>
+ *
+ * The model definition should include something like.
+ *
+ * <code><pre>
+ * ex:myEvaluator a sec:Evaluator ;
+ * sec:args [ rdf:_1 "argument 1 for my evaluator constructor" ;
+ * rdf:_2 "13"^^xsd:int ; ];
+ * sec:evaluatorClass "evaluatorClassname";
+ * .
+ * </pre></code>
+ *
+ * Terms used in above example:
+ *
+ * <dl>
+ * <dt>my:secEvaluator</dt>
+ * <dd>The security evaluator as referenced in the assembler file.</dd>
+ *
+ * <dt>sec:Evaluator</dt>
+ * <dd>Identifies my:secEvaluator as a SecurityEvaluator</dd>
+ *
+ * <dt>sec:args</dt>
+ * <dd>Identifies the argument list</dd>
+ *
+ * <dt>rdf:_1</dt>
+ * <dd>The first argument</dd>
+ *
+ * <dt>rdf:_2</dt>
+ * <dd>The second argument (an integer in this case</dd>
+ *
+ * <dt>sec:evaluatorClass</dt>
+ * <dd>The fully qualified name of the SecurityEvaluator class to call. This class must extend
+ * SecurityEvaluator, and must have one and only one constructor that takes the number of arguments
+ * specified in sec:args</dd>
+ *
+ * </p>
+ *
+ */
+public class SecurityEvaluatorAssembler extends AssemblerBase implements Assembler, AssemblerConstants {
+ // initialization and registration is performed by SecuredAssembler
+
+ @Override
+ public SecurityEvaluator open(Assembler a, Resource root, Mode mode) {
+
+ Literal className = getUniqueLiteral( root, EVALUATOR_CLASS );
+ if (className == null)
+ {
+ throw new AssemblerException( root, String.format( NO_X_PROVIDED, EVALUATOR_CLASS, root ));
+ }
+
+ Class<?> clazz;
+ try {
+ clazz = Class.forName(className.getString());
+ } catch (ClassNotFoundException e1) {
+ throw new AssemblerException( root, String.format( "Can not locate class %s as specified by %s in %s", className, EVALUATOR_CLASS, root ));
+ }
+ if ( ! SecurityEvaluator.class.isAssignableFrom( clazz ))
+ {
+ throw new AssemblerException( root, String.format( "Class %s as specified by %s in %s does not implement SecurityEvaluator", className, EVALUATOR_CLASS, root ));
+ }
+
+ // get the arguments as specified.
+ List<Object> args = new ArrayList<Object>();
+ Resource argRes = getUniqueResource( root, ARGUMENT_LIST );
+ if (argRes != null)
+ {
+ Seq seq = argRes.as( Seq.class );
+ NodeIterator iter = seq.iterator();
+ RDFNode n = null;
+ while (iter.hasNext())
+ {
+ n = iter.next();
+ if (n.isLiteral())
+ {
+ args.add( n.asLiteral().getValue());
+ }
+ else if (n.isResource())
+ {
+ args.add( a.open( a, n.asResource(), mode ) );
+ }
+ else
+ {
+ throw new AssemblerException( root, String.format( "%s must be a literal or a resource", n ));
+ }
+ }
+ }
+
+ for (Constructor<?> c : clazz.getConstructors())
+ {
+ if (c.getParameterTypes().length == args.size())
+ {
+ try {
+ if (args.size() == 0)
+ {
+ return (SecurityEvaluator) c.newInstance();
+ }
+ else
+ {
+ return (SecurityEvaluator) c.newInstance( args.toArray() );
+ }
+ } catch (InstantiationException e) {
+ throw new AssemblerException( root, e.getMessage(), e );
+ } catch (IllegalAccessException e) {
+ throw new AssemblerException( root, e.getMessage(), e );
+ } catch (IllegalArgumentException e) {
+ throw new AssemblerException( root, e.getMessage(), e );
+ } catch (InvocationTargetException e) {
+ throw new AssemblerException( root, e.getMessage(), e );
+ }
+ }
+
+ }
+ throw new AssemblerException( root, String.format( "Class %s does not have a %s argument constructor", className, args.size() ));
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredBulkUpdateHandler.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredBulkUpdateHandler.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredBulkUpdateHandler.java
new file mode 100644
index 0000000..6263af9
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredBulkUpdateHandler.java
@@ -0,0 +1,148 @@
+/*
+ * 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.graph;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.jena.graph.BulkUpdateHandler ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.impl.SecuredItem;
+
+/**
+ * The interface for secured BulkUpdateHanlder instances.
+ *
+ * Use the SecuredBulkUpdateHandler.Factory to create instances
+ */
+public interface SecuredBulkUpdateHandler extends BulkUpdateHandler,
+ SecuredItem
+{
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void add( final Graph g ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public void add( final Graph g, final boolean withReifications )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public void add( final Iterator<Triple> it ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public void add( final List<Triple> triples ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public void add( final Triple[] triples ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void delete( final Graph g ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public void delete( final Graph g, final boolean withReifications )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public void delete( final Iterator<Triple> it )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public void delete( final List<Triple> triples )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public void delete( final Triple[] triples ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void remove( final Node s, final Node p, final Node o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void removeAll() throws AccessDeniedException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredCapabilities.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredCapabilities.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredCapabilities.java
new file mode 100644
index 0000000..6a12fa1
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredCapabilities.java
@@ -0,0 +1,151 @@
+/*
+ * 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.graph;
+
+import org.apache.jena.graph.Capabilities ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.SecurityEvaluator.SecTriple;
+import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
+
+/**
+ * The interface for secured Capabilities instances.
+ *
+ */
+public class SecuredCapabilities implements Capabilities
+{
+ // the security evaluator in use
+ private final SecurityEvaluator securityEvaluator;
+ // the graphIRI that the capabilities belong to.
+ private final SecNode graphIRI;
+ // the unsecured capabilities.
+ private final Capabilities capabilities;
+
+ /**
+ * Constructor.
+ *
+ * @param securityEvaluator
+ * The security evaluator in use.
+ * @param graphURI
+ * The graphIRI that the capabilities describe.
+ * @param capabilities
+ * The unsecured capabilities.
+ */
+ public SecuredCapabilities( final SecurityEvaluator securityEvaluator,
+ final String graphURI, final Capabilities capabilities )
+ {
+ this.securityEvaluator = securityEvaluator;
+ this.graphIRI = new SecNode(Type.URI, graphURI);
+ this.capabilities = capabilities;
+ }
+
+ /**
+ * @sec.graph Update
+ */
+ @Override
+ public boolean addAllowed()
+ {
+ return securityEvaluator.evaluate(securityEvaluator.getPrincipal(), Action.Update, graphIRI)
+ && capabilities.addAllowed();
+ }
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (if everyTriple is true)
+ */
+ @Override
+ public boolean addAllowed( final boolean everyTriple )
+ {
+ Object principal = securityEvaluator.getPrincipal();
+
+ boolean retval = securityEvaluator.evaluate(principal, Action.Update, graphIRI)
+ && capabilities.addAllowed(everyTriple);
+ if (retval && everyTriple)
+ {
+ // special security check
+ retval = securityEvaluator.evaluate(principal, Action.Create, graphIRI,
+ SecTriple.ANY);
+ }
+ return retval;
+ }
+
+ @Override
+ public boolean canBeEmpty()
+ {
+ return capabilities.canBeEmpty();
+ }
+
+ /**
+ * @sec.graph Update
+ */
+ @Override
+ public boolean deleteAllowed()
+ {
+ return securityEvaluator.evaluate(securityEvaluator.getPrincipal(), Action.Update, graphIRI)
+ && capabilities.deleteAllowed();
+ }
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete (if everyTriple is true)
+ */
+ @Override
+ public boolean deleteAllowed( final boolean everyTriple )
+ {
+ Object principal = securityEvaluator.getPrincipal();
+
+ boolean retval = securityEvaluator.evaluate(principal, Action.Update, graphIRI)
+ && capabilities.addAllowed(everyTriple);
+ if (retval && everyTriple)
+ {
+ // special security check
+ retval = securityEvaluator.evaluate(principal, Action.Delete, graphIRI,
+ SecTriple.ANY);
+ }
+ return retval;
+ }
+
+ @Override
+ public boolean findContractSafe()
+ {
+ return capabilities.findContractSafe();
+ }
+
+ @Override
+ public boolean handlesLiteralTyping()
+ {
+ return capabilities.handlesLiteralTyping();
+ }
+
+ /**
+ * @sec.graph Update
+ */
+ @Override
+ public boolean iteratorRemoveAllowed()
+ {
+ return securityEvaluator.evaluate(securityEvaluator.getPrincipal(), Action.Update, graphIRI)
+ && capabilities.iteratorRemoveAllowed();
+ }
+
+ @Override
+ public boolean sizeAccurate()
+ {
+ return capabilities.sizeAccurate();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredGraph.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredGraph.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredGraph.java
new file mode 100644
index 0000000..afdfdc8
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredGraph.java
@@ -0,0 +1,176 @@
+/*
+ * 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.graph;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.GraphStatisticsHandler ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.security.AccessDeniedException ;
+import org.apache.jena.security.SecurityEvaluator ;
+import org.apache.jena.security.SecurityEvaluator.SecNode ;
+import org.apache.jena.shared.AddDeniedException ;
+import org.apache.jena.shared.DeleteDeniedException ;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+
+/**
+ * The interface for secured Graph instances.
+ *
+ * Use the SecuredGraph.Factory to create instances
+ */
+public interface SecuredGraph extends Graph
+{
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create
+ * @throws AccessDeniedException
+ * @throws AddDeniedException
+ */
+ @Override
+ public void add( final Triple t ) throws AddDeniedException,
+ AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final Node s, final Node p, final Node o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final Triple t ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ * @throws DeleteDeniedException
+ */
+ @Override
+ public void delete( final Triple t ) throws DeleteDeniedException,
+ AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean dependsOn( final Graph other ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read, otherwise filtered from iterator.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public ExtendedIterator<Triple> find( final Node s, final Node p,
+ final Node o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read, otherwise filtered from iterator.
+ * @throws AccessDeniedException
+ * @deprecated Use {@link #find(Triple)}
+ */
+ @Deprecated
+ @Override
+ public ExtendedIterator<Triple> find( final org.apache.jena.graph.TripleMatch triple )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read, otherwise filtered from iterator.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public ExtendedIterator<Triple> find( final Triple triple )
+ throws AccessDeniedException;
+
+ @Override
+ public SecuredBulkUpdateHandler getBulkUpdateHandler();
+
+ @Override
+ public SecuredCapabilities getCapabilities();
+
+ @Override
+ public SecuredGraphEventManager getEventManager();
+
+ public SecNode getModelNode();
+
+ @Override
+ public SecuredPrefixMapping getPrefixMapping();
+
+ public SecurityEvaluator getSecurityEvaluator();
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public GraphStatisticsHandler getStatisticsHandler()
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean isEmpty() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean isIsomorphicWith( final Graph g )
+ throws AccessDeniedException;
+
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public int size() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete for every triple
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void clear();
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete (s, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void remove( Node s, Node p, Node o );
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredGraphEventManager.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredGraphEventManager.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredGraphEventManager.java
new file mode 100644
index 0000000..9c62127
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredGraphEventManager.java
@@ -0,0 +1,608 @@
+/*
+ * 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.graph;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.GraphEventManager ;
+import org.apache.jena.graph.GraphListener ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.CollectionGraph ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.graph.impl.SecuredGraphImpl;
+import org.apache.jena.security.impl.CachedSecurityEvaluator;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.security.utils.PermTripleFilter;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.NiceIterator ;
+import org.apache.jena.util.iterator.WrappedIterator ;
+
+/**
+ * Since we sit between the graph and other items we have to determine when the
+ * message is first seen and send it to the underlying graph if necessary.
+ */
+public class SecuredGraphEventManager implements GraphEventManager {
+ private class SecuredGraphListener implements GraphListener {
+ private final GraphListener wrapped;
+ private final Object runAs;
+
+ SecuredGraphListener(final GraphListener wrapped) {
+ if (wrapped == null) {
+ throw new IllegalArgumentException(
+ "Wrapped listener may not be null");
+ }
+ this.wrapped = wrapped;
+ this.runAs = securedGraph.getSecurityEvaluator().getPrincipal();
+ }
+
+ private Triple[] getArray(final Graph g, final Triple[] triples,
+ final Set<Action> perms) {
+ Triple[] retval = triples;
+ if (g instanceof SecuredGraphImpl) {
+ final SecuredGraphImpl sg = (SecuredGraphImpl) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ if (evaluator.evaluateAny(runAs, perms, sg.getModelNode())) {
+ if (!evaluator.evaluateAny(runAs, perms, sg.getModelNode(),
+ SecuredItemImpl.convert(Triple.ANY))) {
+ final List<Triple> list = wrapPermIterator(sg,
+ Arrays.asList(triples).iterator(), perms)
+ .toList();
+ retval = list.toArray(new Triple[list.size()]);
+ }
+ else {
+ retval = triples;
+ }
+ }
+ else {
+ retval = new Triple[0];
+ }
+ }
+ return retval;
+ }
+
+ @Override
+ public void notifyAddArray(final Graph g, final Triple[] triples) {
+ final Triple[] added = getArray(g, triples,
+ SecuredGraphEventManager.ADD);
+
+ if (added.length > 0) {
+ wrapped.notifyAddArray(g, added);
+ }
+ }
+
+ @Override
+ public void notifyAddGraph(final Graph g, final Graph added) {
+ Graph addGraph = added;
+ if (g instanceof SecuredGraph) {
+ final SecuredGraph sg = (SecuredGraph) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ if (evaluator.evaluateAny(runAs, SecuredGraphEventManager.ADD,
+ sg.getModelNode())) {
+ if (!evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.ADD, sg.getModelNode(),
+ SecuredItemImpl.convert(Triple.ANY))) {
+ final List<Triple> lst = added.find(Triple.ANY)
+ .toList();
+ addGraph = new CollectionGraph(Arrays.asList(getArray(
+ g, lst.toArray(new Triple[lst.size()]),
+ SecuredGraphEventManager.ADD)));
+ }
+ else {
+ addGraph = added;
+ }
+ }
+ else {
+ addGraph = new CollectionGraph(
+ Collections.<Triple> emptyList());
+ }
+ }
+ if (addGraph.size() > 0) {
+ wrapped.notifyAddGraph(g, addGraph);
+
+ }
+ }
+
+ @Override
+ public void notifyAddIterator(final Graph g, final Iterator<Triple> it) {
+
+ if (g instanceof SecuredGraphImpl) {
+ final SecuredGraphImpl sg = (SecuredGraphImpl) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ // only report if we can write to the graph
+ if (evaluator.evaluateAny(runAs, SecuredGraphEventManager.ADD,
+ sg.getModelNode())) {
+ final ExtendedIterator<Triple> iter = wrapPermIterator(sg,
+ it, SecuredGraphEventManager.ADD);
+ try {
+ wrapped.notifyAddIterator(g, iter);
+ } finally {
+ iter.close();
+ }
+ }
+ }
+ else {
+ wrapped.notifyAddIterator(g, it);
+ }
+
+ }
+
+ @Override
+ public void notifyAddList(final Graph g, final List<Triple> triples) {
+ List<Triple> list = triples;
+ if (g instanceof SecuredGraphImpl) {
+ final SecuredGraphImpl sg = (SecuredGraphImpl) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ if (evaluator.evaluateAny(runAs, SecuredGraphEventManager.ADD,
+ sg.getModelNode())) {
+ if (!evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.ADD, sg.getModelNode(),
+ SecuredItemImpl.convert(Triple.ANY))) {
+ list = wrapPermIterator(sg, triples.iterator(),
+ SecuredGraphEventManager.ADD).toList();
+ }
+ else {
+ list = triples;
+ }
+ }
+ else {
+ list = Collections.emptyList();
+ }
+ }
+
+ if (list.size() > 0) {
+
+ wrapped.notifyAddList(g, list);
+ }
+ }
+
+ @Override
+ public void notifyAddTriple(final Graph g, final Triple t) {
+ boolean notify = false;
+ if (g instanceof SecuredGraph) {
+ final SecuredGraph sg = (SecuredGraph) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ notify = evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.ADD, sg.getModelNode());
+ if (notify) {
+ notify = evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.ADD, sg.getModelNode(),
+ SecuredItemImpl.convert(t));
+ }
+ }
+ else {
+ notify = true;
+ }
+ if (notify) {
+ wrapped.notifyAddTriple(g, t);
+ }
+ }
+
+ @Override
+ public void notifyDeleteArray(final Graph g, final Triple[] triples) {
+ Triple[] deleted = triples;
+ if (g instanceof SecuredGraphImpl) {
+ final SecuredGraphImpl sg = (SecuredGraphImpl) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ if (evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode())) {
+ if (!evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode(),
+ SecuredItemImpl.convert(Triple.ANY))) {
+ final List<Triple> list = wrapPermIterator(sg,
+ Arrays.asList(triples).iterator(),
+ SecuredGraphEventManager.DELETE).toList();
+ deleted = list.toArray(new Triple[list.size()]);
+ }
+ else {
+ deleted = triples;
+ }
+ }
+ else {
+ deleted = new Triple[0];
+ }
+ }
+
+ if (deleted.length > 0) {
+ wrapped.notifyDeleteArray(g, deleted);
+ }
+ }
+
+ @Override
+ public void notifyDeleteGraph(final Graph g, final Graph removed) {
+ if (g instanceof SecuredGraphImpl) {
+ final SecuredGraphImpl sg = (SecuredGraphImpl) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ if (evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode())) {
+ Graph g2 = removed;
+ if (!evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode(),
+ SecuredItemImpl.convert(Triple.ANY))) {
+ g2 = new CollectionGraph(
+ removed.find(Triple.ANY)
+ .filterKeep(
+ new PermTripleFilter(
+ SecuredGraphEventManager.DELETE,
+ sg, evaluator))
+ .toList());
+
+ }
+ wrapped.notifyDeleteGraph(g, g2);
+ }
+ else {
+ // do nothing.
+ }
+ }
+ else {
+ wrapped.notifyDeleteGraph(g, removed);
+ }
+ }
+
+ @Override
+ public void notifyDeleteIterator(final Graph g,
+ final Iterator<Triple> it) {
+ Iterator<Triple> iter = it;
+ if (g instanceof SecuredGraphImpl) {
+ final SecuredGraphImpl sg = (SecuredGraphImpl) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ if (evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode())) {
+
+ if (!evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode(),
+ SecuredItemImpl.convert(Triple.ANY))) {
+ iter = WrappedIterator.create(it).filterKeep(
+ new PermTripleFilter(
+ SecuredGraphEventManager.DELETE, sg,
+ evaluator));
+ }
+ // else use the default list as all can bee seen
+ wrapped.notifyDeleteIterator(g, iter);
+ }
+ else {
+ // do nothing.
+ }
+ }
+ else {
+ wrapped.notifyDeleteIterator(g, iter);
+ }
+
+ }
+
+ @Override
+ public void notifyDeleteList(final Graph g, final List<Triple> triples) {
+ List<Triple> list = triples;
+ if (g instanceof SecuredGraphImpl) {
+ final SecuredGraphImpl sg = (SecuredGraphImpl) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ if (evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode())) {
+ if (!evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode(),
+ SecuredItemImpl.convert(Triple.ANY))) {
+ list = WrappedIterator
+ .create(triples.iterator())
+ .filterKeep(
+ new PermTripleFilter(
+ SecuredGraphEventManager.DELETE,
+ sg, evaluator)).toList();
+ }
+ // else use the default list as all can bee seen
+ }
+ else {
+ list = Collections.emptyList();
+ }
+ }
+
+ if (list.size() > 0) {
+ wrapped.notifyDeleteList(g, list);
+ }
+ }
+
+ @Override
+ public void notifyDeleteTriple(final Graph g, final Triple t) {
+ boolean notify = false;
+ if (g instanceof SecuredGraph) {
+ final SecuredGraph sg = (SecuredGraph) g;
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ notify = evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode());
+ if (notify) {
+ notify = evaluator.evaluateAny(runAs,
+ SecuredGraphEventManager.DELETE, sg.getModelNode(),
+ SecuredItemImpl.convert(t));
+ }
+ }
+ else {
+ notify = true;
+ }
+ if (notify) {
+ wrapped.notifyDeleteTriple(g, t);
+ }
+ }
+
+ @Override
+ public void notifyEvent(final Graph source, final Object value) {
+ wrapped.notifyEvent(source, value);
+ }
+
+ private ExtendedIterator<Triple> wrapPermIterator(
+ final SecuredGraphImpl sg, final Iterator<Triple> it,
+ final Set<Action> perms) {
+ final SecurityEvaluator evaluator = new CachedSecurityEvaluator(sg.getSecurityEvaluator(), runAs);
+ if (!evaluator.evaluateAny(runAs, perms, sg.getModelNode(),
+ SecuredItemImpl.convert(Triple.ANY))) {
+ // nope so wrap the iterator with security iterator
+ return WrappedIterator.create(it).filterKeep(
+ new PermTripleFilter(perms, sg, evaluator));
+ }
+ return WrappedIterator.create(it);
+ }
+
+ }
+
+ // the security evaluator in use
+ private final SecuredGraph securedGraph;
+ private final Graph baseGraph;
+ private final Map<GraphListener, Stack<SecuredGraphListener>> listenerMap = new HashMap<GraphListener, Stack<SecuredGraphListener>>();
+ private static Set<Action> DELETE;
+
+ private static Set<Action> ADD;
+
+ static {
+ SecuredGraphEventManager.ADD = new HashSet<Action>(
+ Arrays.asList(new Action[] {
+ Action.Create, Action.Read
+ }));
+ SecuredGraphEventManager.DELETE = new HashSet<Action>(
+ Arrays.asList(new Action[] {
+ Action.Delete, Action.Read
+ }));
+ }
+
+ public SecuredGraphEventManager(final SecuredGraph securedGraph,
+ final Graph baseGraph, final GraphEventManager manager) {
+ this.securedGraph = securedGraph;
+ this.baseGraph = baseGraph;
+ manager.register(this);
+ }
+
+ private synchronized Collection<SecuredGraphListener> getListenerCollection() {
+ ExtendedIterator<SecuredGraphListener> retval = NiceIterator
+ .emptyIterator();
+ for (final Collection<SecuredGraphListener> coll : listenerMap.values()) {
+ retval = retval.andThen(coll.iterator());
+ }
+ return retval.toList();
+ }
+
+ @Override
+ public boolean listening() {
+ return !listenerMap.isEmpty();
+ }
+
+ @Override
+ public void notifyAddArray(final Graph g, final Triple[] triples) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyAddArray(securedGraph, triples);
+ }
+ else {
+ sgl.notifyAddArray(g, triples);
+ }
+ }
+ }
+
+ @Override
+ public void notifyAddGraph(final Graph g, final Graph added) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyAddGraph(securedGraph, added);
+ }
+ else {
+ sgl.notifyAddGraph(g, added);
+ }
+ }
+ }
+
+ @Override
+ public void notifyAddIterator(final Graph g, final Iterator<Triple> it) {
+ notifyAddIterator(g, WrappedIterator.create(it).toList());
+ baseGraph.equals(g);
+ }
+
+ @Override
+ public void notifyAddIterator(final Graph g, final List<Triple> triples) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyAddIterator(securedGraph, triples.iterator());
+ }
+ else {
+ sgl.notifyAddIterator(g, triples.iterator());
+ }
+ }
+ }
+
+ @Override
+ public void notifyAddList(final Graph g, final List<Triple> triples) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyAddList(securedGraph, triples);
+ }
+ else {
+ sgl.notifyAddList(g, triples);
+ }
+ }
+ }
+
+ @Override
+ public void notifyAddTriple(final Graph g, final Triple t) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyAddTriple(securedGraph, t);
+ }
+ else {
+ sgl.notifyAddTriple(g, t);
+ }
+ }
+ }
+
+ @Override
+ public void notifyDeleteArray(final Graph g, final Triple[] triples) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyDeleteArray(securedGraph, triples);
+ }
+ else {
+ sgl.notifyDeleteArray(g, triples);
+ }
+ }
+ }
+
+ @Override
+ public void notifyDeleteGraph(final Graph g, final Graph removed) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyDeleteGraph(securedGraph, removed);
+ }
+ else {
+ sgl.notifyDeleteGraph(g, removed);
+ }
+ }
+ }
+
+ @Override
+ public void notifyDeleteIterator(final Graph g, final Iterator<Triple> it) {
+ notifyDeleteIterator(g, WrappedIterator.create(it).toList());
+ }
+
+ @Override
+ public void notifyDeleteIterator(final Graph g, final List<Triple> triples) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyDeleteIterator(securedGraph, triples.iterator());
+ }
+ else {
+ sgl.notifyDeleteIterator(g, triples.iterator());
+ }
+ }
+ }
+
+ @Override
+ public void notifyDeleteList(final Graph g, final List<Triple> L) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyDeleteList(securedGraph, L);
+ }
+ else {
+ sgl.notifyDeleteList(g, L);
+ }
+ }
+ }
+
+ @Override
+ public void notifyDeleteTriple(final Graph g, final Triple t) {
+ final boolean wrap = baseGraph.equals(g);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyDeleteTriple(securedGraph, t);
+ }
+ else {
+ sgl.notifyDeleteTriple(g, t);
+ }
+ }
+ }
+
+ @Override
+ public void notifyEvent(final Graph source, final Object value) {
+ if ((source instanceof SecuredGraph) && securedGraph.equals(source)) {
+ baseGraph.getEventManager().notifyEvent(baseGraph, value);
+ }
+ else {
+
+ final boolean wrap = baseGraph.equals(source);
+
+ for (final SecuredGraphListener sgl : getListenerCollection()) {
+ if (wrap) {
+ sgl.notifyEvent(securedGraph, value);
+ }
+ else {
+ sgl.notifyEvent(source, value);
+ }
+ }
+ }
+ }
+
+ @Override
+ public synchronized GraphEventManager register(final GraphListener listener) {
+ Stack<SecuredGraphListener> sgl = listenerMap.get(listener);
+ if (sgl == null) {
+ sgl = new Stack<SecuredGraphListener>();
+ }
+ sgl.push(new SecuredGraphListener(listener));
+ listenerMap.put(listener, sgl);
+ return this;
+ }
+
+ @Override
+ public synchronized GraphEventManager unregister(
+ final GraphListener listener) {
+ final Stack<SecuredGraphListener> sgl = listenerMap.get(listener);
+ if (sgl != null) {
+ if (sgl.size() == 1) {
+ listenerMap.remove(listener);
+ }
+ else {
+ sgl.pop();
+ listenerMap.put(listener, sgl);
+ }
+ }
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredPrefixMapping.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredPrefixMapping.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredPrefixMapping.java
new file mode 100644
index 0000000..61c2544
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/SecuredPrefixMapping.java
@@ -0,0 +1,133 @@
+/*
+ * 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.graph;
+
+import java.util.Map;
+
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.impl.SecuredItem;
+import org.apache.jena.shared.PrefixMapping ;
+
+/**
+ * The interface for secured PrefixMapping instances.
+ *
+ * Use the SecuredPrefixMapping.Factory to create instances
+ */
+public interface SecuredPrefixMapping extends PrefixMapping, SecuredItem
+{
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String expandPrefix( final String prefixed )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Map<String, String> getNsPrefixMap() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getNsPrefixURI( final String prefix )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getNsURIPrefix( final String uri )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredPrefixMapping lock() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String qnameFor( final String uri ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredPrefixMapping removeNsPrefix( final String prefix )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean samePrefixMappingAs( final PrefixMapping other )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredPrefixMapping setNsPrefix( final String prefix,
+ final String uri ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredPrefixMapping setNsPrefixes( final Map<String, String> map )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredPrefixMapping setNsPrefixes( final PrefixMapping other )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String shortForm( final String uri ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredPrefixMapping withDefaultMappings( final PrefixMapping map )
+ throws AccessDeniedException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/Factory.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/Factory.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/Factory.java
new file mode 100644
index 0000000..d66d46e
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/Factory.java
@@ -0,0 +1,129 @@
+/*
+ * 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.graph.impl;
+
+import org.apache.jena.graph.BulkUpdateHandler ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.graph.SecuredBulkUpdateHandler;
+import org.apache.jena.security.graph.SecuredGraph;
+import org.apache.jena.security.graph.SecuredPrefixMapping;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemInvoker;
+import org.apache.jena.shared.PrefixMapping ;
+
+public class Factory
+{
+
+ /**
+ * Create an instance of the SecuredBulkUpdateHandler
+ *
+ * @param graph
+ * The SecuredGraph that created the handler
+ * @param handler
+ * The unsecured handler from the base graph.
+ * @return SecuredBulkUpdateHandler.
+ */
+ static SecuredBulkUpdateHandler getInstance( final SecuredGraphImpl graph,
+ final Graph baseGraph, final BulkUpdateHandler handler )
+ {
+ final ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler> holder = new ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler>(
+ handler);
+
+ final SecuredBulkUpdateHandlerImpl checker = new SecuredBulkUpdateHandlerImpl(
+ graph, baseGraph, holder);
+
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (handler instanceof SecuredBulkUpdateHandler)
+ {
+ if (checker.isEquivalent((SecuredBulkUpdateHandler) handler))
+ {
+ return (SecuredBulkUpdateHandler) handler;
+ }
+ }
+
+ return holder.setSecuredItem(new SecuredItemInvoker(handler.getClass(),
+ checker));
+ }
+
+ /**
+ * Create an instance of SecuredPrefixMapping
+ *
+ * @param graph
+ * The SecuredGraph that contains the prefixmapping.
+ * @param prefixMapping
+ * The prefixmapping returned from the base graph.
+ * @return The SecuredPrefixMapping.
+ */
+ static SecuredPrefixMapping getInstance( final SecuredGraphImpl graph,
+ final PrefixMapping prefixMapping )
+ {
+
+ final ItemHolder<PrefixMapping, SecuredPrefixMapping> holder = new ItemHolder<PrefixMapping, SecuredPrefixMapping>(
+ prefixMapping);
+ final SecuredPrefixMappingImpl checker = new SecuredPrefixMappingImpl(
+ graph, holder);
+ // if we are going to create a duplicate proxy just return this one.
+ if (prefixMapping instanceof SecuredPrefixMapping)
+ {
+ if (checker.isEquivalent((SecuredPrefixMapping) prefixMapping))
+ {
+ return (SecuredPrefixMapping) prefixMapping;
+ }
+ }
+
+ return holder.setSecuredItem(new SecuredItemInvoker(prefixMapping
+ .getClass(), checker));
+ }
+
+ /**
+ * 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, SecuredGraphImpl>(
+ 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));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredBulkUpdateHandlerImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredBulkUpdateHandlerImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredBulkUpdateHandlerImpl.java
new file mode 100644
index 0000000..9d0d990
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredBulkUpdateHandlerImpl.java
@@ -0,0 +1,242 @@
+/*
+ * 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.graph.impl;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.jena.graph.BulkUpdateHandler ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.security.graph.SecuredBulkUpdateHandler;
+import org.apache.jena.security.graph.SecuredGraph;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.WrappedIterator ;
+
+/**
+ * Implementation of SecuredBulkUpdateHandler to be used by a SecuredItemInvoker
+ * proxy.
+ */
+@SuppressWarnings("deprecation")
+public class SecuredBulkUpdateHandlerImpl extends SecuredItemImpl implements
+ SecuredBulkUpdateHandler
+{
+ // the base graph for he secured graph.
+ private final Graph baseGraph;
+ // the graph this handler is for.
+ private final SecuredGraph graph;
+ // the item holder holding this SecuredBulkUpdateHandler.
+ private final ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler> holder;
+
+ /**
+ * Constructor.
+ *
+ * @param graph
+ * The graph handler is for.
+ * @param holder
+ * The item holder that will hold this SecuredBulkUpdateHandler.
+ */
+ SecuredBulkUpdateHandlerImpl( final SecuredGraphImpl graph,
+ final Graph baseGraph,
+ final ItemHolder<BulkUpdateHandler, SecuredBulkUpdateHandler> holder )
+ {
+ super(graph, holder);
+ this.holder = holder;
+ this.graph = graph;
+ this.baseGraph = baseGraph;
+ }
+
+ @Override
+ public void add( final Graph g )
+ {
+ checkUpdate();
+ final Graph g2 = g;
+ if (!canCreate(Triple.ANY))
+ {
+ checkCreateTriples(g.find(Triple.ANY));
+ }
+ holder.getBaseItem().add(g2);
+ }
+
+ @Override
+ @Deprecated
+ public void add( final Graph g, final boolean withReifications )
+ {
+ checkUpdate();
+
+ if (!canCreate(Triple.ANY))
+ {
+ checkCreateTriples(g.find(Triple.ANY));
+ }
+ holder.getBaseItem().add(g, withReifications);
+ }
+
+ @Override
+ @Deprecated
+ public void add( final Iterator<Triple> it )
+ {
+ checkUpdate();
+ if (canCreate(Triple.ANY))
+ {
+ holder.getBaseItem().add(it);
+ }
+ else
+ {
+ final List<Triple> lst = WrappedIterator.create(it).toList();
+ for (final Triple t : lst)
+ {
+ checkCreate(t);
+ }
+ holder.getBaseItem().add(lst.iterator());
+ }
+ }
+
+ @Override
+ @Deprecated
+ public void add( final List<Triple> triples )
+ {
+ checkUpdate();
+ if (!canCreate(Triple.ANY))
+ {
+ checkCreateTriples(WrappedIterator.create(triples.iterator()));
+ }
+ holder.getBaseItem().add(triples);
+ }
+
+ @Override
+ @Deprecated
+ public void add( final Triple[] triples )
+ {
+ checkUpdate();
+ if (!canCreate(Triple.ANY))
+ {
+ checkCreateTriples(WrappedIterator.create(Arrays.asList(triples)
+ .iterator()));
+ }
+ holder.getBaseItem().add(triples);
+ }
+
+ private void checkExtendedTripleDelete( final Triple t )
+ {
+ final ExtendedIterator<Triple> iter = baseGraph.find(t);
+ try
+ {
+ while (iter.hasNext())
+ {
+ checkDelete(iter.next());
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public void delete( final Graph g )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ checkDeleteTriples(g.find(Triple.ANY));
+ }
+ holder.getBaseItem().delete(g);
+
+ }
+
+ @Override
+ @Deprecated
+ public void delete( final Graph g, final boolean withReifications )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ checkDeleteTriples(g.find(Triple.ANY));
+ }
+ holder.getBaseItem().delete(g, withReifications);
+
+ }
+
+ @Override
+ @Deprecated
+ public void delete( final Iterator<Triple> it )
+ {
+ checkUpdate();
+ final List<Triple> lst = WrappedIterator.create(it).toList();
+ if (!canDelete(Triple.ANY))
+ {
+ checkDeleteTriples(WrappedIterator.create(lst.iterator()));
+ }
+ holder.getBaseItem().delete(lst.iterator());
+ }
+
+ @Override
+ @Deprecated
+ public void delete( final List<Triple> triples )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ checkDeleteTriples(WrappedIterator.create(triples.iterator()));
+ }
+ holder.getBaseItem().delete(triples);
+ }
+
+ @Override
+ @Deprecated
+ public void delete( final Triple[] triples )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ checkDeleteTriples(WrappedIterator.create(Arrays.asList(triples)
+ .iterator()));
+ }
+ holder.getBaseItem().delete(triples);
+ }
+
+ @Override
+ public void remove( final Node s, final Node p, final Node o )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ // the remove can be a pattern so expand it.
+ checkExtendedTripleDelete(new Triple(s, p, o));
+ }
+ holder.getBaseItem().remove(s, p, o);
+ }
+
+ @Override
+ public void removeAll()
+ {
+ checkUpdate();
+
+ if (!canDelete(Triple.ANY))
+ {
+ checkDeleteTriples(graph.find(Triple.ANY));
+ }
+
+ holder.getBaseItem().removeAll();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredGraphImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredGraphImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredGraphImpl.java
new file mode 100644
index 0000000..9725236
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredGraphImpl.java
@@ -0,0 +1,303 @@
+/*
+ * 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.graph.impl;
+
+import org.apache.jena.graph.* ;
+import org.apache.jena.security.SecurityEvaluator ;
+import org.apache.jena.security.SecurityEvaluator.Action ;
+import org.apache.jena.security.graph.* ;
+import org.apache.jena.security.impl.ItemHolder ;
+import org.apache.jena.security.impl.SecuredItem ;
+import org.apache.jena.security.impl.SecuredItemImpl ;
+import org.apache.jena.security.utils.PermTripleFilter ;
+import org.apache.jena.shared.AddDeniedException ;
+import org.apache.jena.shared.DeleteDeniedException ;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+
+/**
+ * Implementation of SecuredGraph to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredGraphImpl extends SecuredItemImpl implements SecuredGraph
+{
+
+ // the prefixMapping for this graph.
+ private SecuredPrefixMapping prefixMapping;
+ // the item holder that contains this SecuredGraph
+ private final ItemHolder<Graph, SecuredGraphImpl> holder;
+
+ private final SecuredGraphEventManager eventManager;
+
+ /**
+ * Constructor
+ *
+ * @param securityEvaluator
+ * The security evaluator to use
+ * @param graphIRI
+ * The IRI for the graph
+ * @param holder
+ * The item holder that will contain this SecuredGraph.
+ */
+ SecuredGraphImpl( final SecuredItem securedItem,
+ final ItemHolder<Graph, SecuredGraphImpl> holder )
+ {
+ super(securedItem, holder);
+ this.holder = holder;
+ this.eventManager = new SecuredGraphEventManager(this,
+ holder.getBaseItem(), holder.getBaseItem().getEventManager());
+ }
+
+ SecuredGraphImpl( final SecurityEvaluator securityEvaluator,
+ final String modelURI,
+ final ItemHolder<Graph, SecuredGraphImpl> holder )
+ {
+ super(securityEvaluator, modelURI, holder);
+ this.holder = holder;
+ this.eventManager = new SecuredGraphEventManager(this,
+ holder.getBaseItem(), holder.getBaseItem().getEventManager());
+ }
+
+ @Override
+ public void add( final Triple t ) throws AddDeniedException
+ {
+ checkUpdate();
+ checkCreate(t);
+ holder.getBaseItem().add(t);
+ }
+
+ @Override
+ public void close()
+ {
+ holder.getBaseItem().close();
+ }
+
+ @Override
+ public boolean contains( final Node s, final Node p, final Node o )
+ {
+ return contains(new Triple(s, p, o));
+ }
+
+ @Override
+ public boolean contains( final Triple t )
+ {
+ checkRead();
+ if (canRead(t))
+ {
+ return holder.getBaseItem().contains(t);
+ }
+ final ExtendedIterator<Triple> iter = holder.getBaseItem().find(t);
+ try
+ {
+ while (iter.hasNext())
+ {
+ if (canRead(iter.next()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ finally
+ {
+ iter.close();
+ }
+
+ }
+
+ private synchronized void createPrefixMapping()
+ {
+ if (prefixMapping == null)
+ {
+ prefixMapping = org.apache.jena.security.graph.impl.Factory
+ .getInstance(this, holder.getBaseItem().getPrefixMapping());
+ }
+ }
+
+ @Override
+ public void delete( final Triple t ) throws DeleteDeniedException
+ {
+ checkUpdate();
+ checkDelete(t);
+ holder.getBaseItem().delete(t);
+ }
+
+ @Override
+ public boolean dependsOn( final Graph other )
+ {
+ checkRead();
+ if (other.equals(holder.getBaseItem()))
+ {
+ return true;
+ }
+ return holder.getBaseItem().dependsOn(other);
+ }
+
+ @Override
+ public ExtendedIterator<Triple> find( final Node s, final Node p,
+ final Node o )
+ {
+ checkRead();
+ ExtendedIterator<Triple> retval = holder.getBaseItem().find(s, p, o);
+ if (!canRead(Triple.ANY))
+ {
+ retval = retval.filterKeep(new PermTripleFilter(Action.Read, this));
+ }
+ return retval;
+ }
+
+ /** @deprecated Use/implement {@link #find(Triple)} */
+ @Deprecated
+ @Override
+ public ExtendedIterator<Triple> find( final TripleMatch m ) {
+ return find(Triple.createMatch(m.getMatchSubject(),
+ m.getMatchPredicate(),
+ m.getMatchObject())) ;
+ }
+
+ @Override
+ public ExtendedIterator<Triple> find( final Triple m )
+ {
+ checkRead();
+ ExtendedIterator<Triple> retval = holder.getBaseItem().find(m);
+ if (!canRead(Triple.ANY))
+ {
+ retval = retval.filterKeep(new PermTripleFilter(Action.Read, this));
+ }
+ return retval;
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public SecuredBulkUpdateHandler getBulkUpdateHandler()
+ {
+ return org.apache.jena.security.graph.impl.Factory.getInstance(this,
+ holder.getBaseItem(), holder.getBaseItem()
+ .getBulkUpdateHandler());
+ }
+
+ @Override
+ public SecuredCapabilities getCapabilities()
+ {
+ return new SecuredCapabilities(getSecurityEvaluator(), getModelIRI(),
+ holder.getBaseItem().getCapabilities());
+ }
+
+ @Override
+ public SecuredGraphEventManager getEventManager()
+ {
+ return eventManager;
+ }
+
+ @Override
+ public SecuredPrefixMapping getPrefixMapping()
+ {
+ if (prefixMapping == null)
+ {
+ createPrefixMapping();
+ }
+ return prefixMapping;
+ }
+
+ @Override
+ public GraphStatisticsHandler getStatisticsHandler()
+ {
+ checkRead();
+ return holder.getBaseItem().getStatisticsHandler();
+ }
+
+ @Override
+ public TransactionHandler getTransactionHandler()
+ {
+ return holder.getBaseItem().getTransactionHandler();
+ }
+
+ @Override
+ public boolean isClosed()
+ {
+ return holder.getBaseItem().isClosed();
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ checkRead();
+ return holder.getBaseItem().isEmpty();
+ }
+
+ @Override
+ public boolean isIsomorphicWith( final Graph g )
+ {
+ checkRead();
+ if (g.size() != holder.getBaseItem().size())
+ {
+ return false;
+ }
+ final Triple t = new Triple(Node.ANY, Node.ANY, Node.ANY);
+ if (!canRead(t))
+ {
+ final ExtendedIterator<Triple> iter = g.find(t);
+ while (iter.hasNext())
+ {
+ checkRead(iter.next());
+ }
+ }
+ return holder.getBaseItem().isIsomorphicWith(g);
+ }
+
+ @Override
+ public int size()
+ {
+ checkRead();
+ return holder.getBaseItem().size();
+ }
+
+ @Override
+ public void clear()
+ {
+ checkUpdate();
+ if (! canDelete( Triple.ANY ))
+ {
+ ExtendedIterator<Triple> iter = holder.getBaseItem().find( Triple.ANY );
+ while (iter.hasNext())
+ {
+ checkDelete( iter.next() );
+ }
+ }
+ holder.getBaseItem().clear();
+ }
+
+ @Override
+ public void remove( Node s, Node p, Node o )
+ {
+ checkUpdate();
+ Triple t = new Triple( s, p, o );
+ if (t.isConcrete())
+ {
+ checkDelete( t );
+ }
+ else
+ {
+ ExtendedIterator<Triple> iter = holder.getBaseItem().find( Triple.ANY );
+ while (iter.hasNext())
+ {
+ checkDelete( iter.next() );
+ }
+ }
+ holder.getBaseItem().remove(s, p, o);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredPrefixMappingImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredPrefixMappingImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredPrefixMappingImpl.java
new file mode 100644
index 0000000..46d9657
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/graph/impl/SecuredPrefixMappingImpl.java
@@ -0,0 +1,167 @@
+/*
+ * 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.graph.impl;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.jena.security.graph.SecuredPrefixMapping;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+
+/**
+ * Implementation of SecuredPrefixMapping to be used by a SecuredItemInvoker
+ * proxy.
+ */
+public class SecuredPrefixMappingImpl extends SecuredItemImpl implements
+ SecuredPrefixMapping
+{
+ // the item holder that holds this SecuredPrefixMapping
+ private final ItemHolder<PrefixMapping, SecuredPrefixMapping> holder;
+
+ /**
+ * Constructor
+ *
+ * @param graph
+ * The Secured graph this mapping is for.
+ * @param holder
+ * The item holder that will contain this SecuredPrefixMapping.
+ */
+ SecuredPrefixMappingImpl( final SecuredGraphImpl graph,
+ final ItemHolder<PrefixMapping, SecuredPrefixMapping> holder )
+ {
+ super(graph, holder);
+ this.holder = holder;
+ }
+
+ @Override
+ public String expandPrefix( final String prefixed )
+ {
+ checkRead();
+ return holder.getBaseItem().expandPrefix(prefixed);
+ }
+
+ @Override
+ public Map<String, String> getNsPrefixMap()
+ {
+ checkRead();
+ return holder.getBaseItem().getNsPrefixMap();
+ }
+
+ @Override
+ public String getNsPrefixURI( final String prefix )
+ {
+ checkRead();
+ return holder.getBaseItem().getNsPrefixURI(prefix);
+ }
+
+ @Override
+ public String getNsURIPrefix( final String uri )
+ {
+ checkRead();
+ return holder.getBaseItem().getNsURIPrefix(uri);
+ }
+
+ @Override
+ public SecuredPrefixMapping lock()
+ {
+ checkUpdate();
+ holder.getBaseItem().lock();
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public String qnameFor( final String uri )
+ {
+ checkRead();
+ return holder.getBaseItem().qnameFor(uri);
+ }
+
+ @Override
+ public SecuredPrefixMapping removeNsPrefix( final String prefix )
+ {
+ checkUpdate();
+ holder.getBaseItem().removeNsPrefix(prefix);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public boolean samePrefixMappingAs( final PrefixMapping other )
+ {
+ checkRead();
+ return holder.getBaseItem().samePrefixMappingAs(other);
+ }
+
+ @Override
+ public SecuredPrefixMapping setNsPrefix( final String prefix,
+ final String uri )
+ {
+ checkUpdate();
+ holder.getBaseItem().setNsPrefix(prefix, uri);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredPrefixMapping setNsPrefixes( final Map<String, String> map )
+ {
+ checkUpdate();
+ holder.getBaseItem().setNsPrefixes(map);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredPrefixMapping setNsPrefixes( final PrefixMapping other )
+ {
+ checkUpdate();
+ holder.getBaseItem().setNsPrefixes(other);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public String shortForm( final String uri )
+ {
+ checkRead();
+ return holder.getBaseItem().shortForm(uri);
+ }
+
+ @Override
+ public SecuredPrefixMapping withDefaultMappings( final PrefixMapping map )
+ {
+ // mapping only updates if there are map entries to add. Since this gets called
+ // when we are doing deep triple checks while writing we need to attempt the
+ // update only if there are new updates to add.
+
+ PrefixMapping m = holder.getBaseItem();
+ PrefixMappingImpl pm = new PrefixMappingImpl();
+ for ( Entry<String, String> e : map.getNsPrefixMap().entrySet())
+ {
+ if (m.getNsPrefixURI(e.getKey()) == null && m.getNsURIPrefix(e.getValue()) == null )
+ {
+ pm.setNsPrefix( e.getKey(), e.getValue() );
+ }
+ }
+ if ( !pm.getNsPrefixMap().isEmpty())
+ {
+ checkUpdate();
+ holder.getBaseItem().withDefaultMappings(pm);
+ }
+ return holder.getSecuredItem();
+ }
+}
\ No newline at end of file
[13/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredResourceTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredResourceTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredResourceTest.java
new file mode 100644
index 0000000..a705518
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredResourceTest.java
@@ -0,0 +1,827 @@
+/*
+ * 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.model;
+
+import java.util.Set;
+
+import org.apache.jena.rdf.model.Literal ;
+import org.apache.jena.rdf.model.RDFNode ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+import org.apache.jena.rdf.model.StmtIterator ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredResource;
+import org.apache.jena.security.model.impl.SecuredResourceImpl;
+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 SecuredResourceTest extends SecuredRDFNodeTest
+{
+
+ public SecuredResourceTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ }
+
+ private SecuredResource getSecuredResource()
+ {
+ return (SecuredResource) getSecuredRDFNode();
+ }
+
+ @Override
+ @Before
+ public void setup()
+ {
+ super.setup();
+ setSecuredRDFNode(SecuredResourceImpl.getInstance(securedModel,
+ SecuredRDFNodeTest.s), SecuredRDFNodeTest.s);
+ }
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, o )
+ * @throws AccessDeniedException
+ */
+ @Test
+ public void testAddLiteralBoolean()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 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()));
+ }
+ }
+ }
+
+ public void testAddLiteralChar()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredResource().addLiteral(SecuredRDFNodeTest.p, '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()));
+ }
+ }
+}
+
+ public void testAddLiteralDouble()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ try
+ {
+ getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 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()));
+ }
+ }
+}
+
+ public void testAddLiteralFloat()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ try
+ {
+ getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 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()));
+ }
+ }
+}
+
+ public void testAddLiteral()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ try
+ {
+ getSecuredResource().addLiteral(SecuredRDFNodeTest.p,
+ ResourceFactory.createTypedLiteral("Yee haw"));
+ 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()));
+ }
+ }
+}
+
+ public void testAddLiteralLong()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ try
+ {
+ getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 1L);
+ 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()));
+ }
+ }
+}
+
+ public void testAddLiteralObject()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ final Object o = Integer.valueOf("1234");
+ try
+ {
+ getSecuredResource().addLiteral(SecuredRDFNodeTest.p, o);
+ 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 testAddProperty()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+
+ final RDFNode rdfNode = ResourceFactory
+ .createResource("http://example.com/newResource");
+ try
+ {
+ getSecuredResource().addLiteral(SecuredRDFNodeTest.p, rdfNode);
+ 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
+ {
+ getSecuredResource().addLiteral(SecuredRDFNodeTest.p, "string");
+ 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()));
+ }
+ }
+
+ final Literal l = ResourceFactory.createTypedLiteral( 3.14F );
+ try
+ {
+ getSecuredResource().addProperty(SecuredRDFNodeTest.p,
+ l.getLexicalForm(), l.getDatatype());
+ 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
+ {
+ getSecuredResource().addProperty(SecuredRDFNodeTest.p, "dos", "sp");
+ 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 testAnonFuncs()
+ {
+
+ final SecuredResource anonResource = securedModel.createResource();
+ setSecuredRDFNode(anonResource, null);
+
+ try
+ {
+ getSecuredResource().getId();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testAsResource()
+ {
+ getSecuredResource().asResource();
+ }
+
+ @Test
+ public void testEquals()
+ {
+ try
+ {
+ getSecuredResource().equals(SecuredRDFNodeTest.s);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ public void testGetLocalName()
+ {
+ try
+ {
+ getSecuredResource().getLocalName();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ public void testGetNameSpace()
+ {
+ try
+ {
+ getSecuredResource().getNameSpace();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetProperty()
+ {
+ try
+ {
+ getSecuredResource().getProperty(SecuredRDFNodeTest.p);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().getPropertyResourceValue(SecuredRDFNodeTest.p);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().getRequiredProperty(SecuredRDFNodeTest.p);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final PropertyNotFoundException e)
+ {
+ // expected if (this, "p", ANY) is not in the base securedModel.
+ final StmtIterator iter = baseModel.listStatements(
+ getSecuredResource(), SecuredRDFNodeTest.p, (RDFNode) null);
+ try
+ {
+ if (iter.hasNext())
+ {
+ throw e;
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ }
+
+ @Test
+ public void testGetURI()
+ {
+ try
+ {
+ getSecuredResource().getURI();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testHasLiteral()
+ {
+ try
+ {
+ getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, true);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 'c');
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 3.14d);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 3.14f);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 6l);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ final Object o = 6;
+ try
+ {
+ getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, o);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testHasProperty()
+ {
+
+ try
+ {
+ getSecuredResource().hasProperty(SecuredRDFNodeTest.p);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().hasProperty(SecuredRDFNodeTest.p,
+ SecuredRDFNodeTest.o);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().hasProperty(SecuredRDFNodeTest.p, "yeee haw");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().hasProperty(SecuredRDFNodeTest.p, "dos", "sp");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testHasURI()
+ {
+ try
+ {
+ getSecuredResource().hasURI("http://example.com/yeeHaw");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testListProperties()
+ {
+ try
+ {
+ getSecuredResource().listProperties();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredResource().listProperties(SecuredRDFNodeTest.p);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testRemoveAll()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Delete });
+ final int count = baseModel
+ .listStatements(getBaseRDFNode().asResource(),
+ SecuredRDFNodeTest.p, (RDFNode) null).toSet().size();
+
+ try
+ {
+ getSecuredResource().removeAll(SecuredRDFNodeTest.p);
+ // only throw on delete if count > 0
+ if (!securityEvaluator.evaluate(Action.Update)
+ || ((count > 0) && !securityEvaluator
+ .evaluate(Action.Delete)))
+ {
+ 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 testRemoveProperties()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Delete });
+ final int count = baseModel
+ .listStatements(getBaseRDFNode().asResource(),
+ SecuredRDFNodeTest.p, (RDFNode) null).toSet().size();
+
+ try
+ {
+ getSecuredResource().removeProperties();
+ // only throw on delete if count > 0
+ if (!securityEvaluator.evaluate(Action.Update)
+ || ((count > 0) && !securityEvaluator
+ .evaluate(Action.Delete)))
+ {
+ 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()));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredSeqTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredSeqTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredSeqTest.java
new file mode 100644
index 0000000..89cb39b
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredSeqTest.java
@@ -0,0 +1,1013 @@
+/*
+ * 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.model;
+
+import java.util.Set;
+
+import org.apache.jena.rdf.model.Alt ;
+import org.apache.jena.rdf.model.Bag ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+import org.apache.jena.rdf.model.Seq ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredAlt;
+import org.apache.jena.security.model.SecuredBag;
+import org.apache.jena.security.model.SecuredSeq;
+import org.apache.jena.security.model.impl.SecuredSeqImpl;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredSeqTest extends SecuredContainerTest
+{
+ private Seq seq;
+
+ public SecuredSeqTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ // TODO Auto-generated constructor stub
+ }
+
+ private SecuredSeq getSecuredSeq()
+ {
+ return (SecuredSeq) getSecuredRDFNode();
+ }
+
+ @Override
+ @Before
+ public void setup()
+ {
+ super.setup();
+ seq = baseModel.getSeq("http://example.com/testContainer");
+ setSecuredRDFNode(SecuredSeqImpl.getInstance(securedModel, seq), seq);
+ }
+
+ @Override
+ @Test
+ public void testAdd()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredSeq().add(2, 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
+ {
+ getSecuredSeq().add(2, '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
+ {
+ getSecuredSeq().add(2, 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
+ {
+ getSecuredSeq().add(2, 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
+ {
+ getSecuredSeq().add(2, 3L);
+ 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 Object o = Integer.MAX_VALUE;
+ getSecuredSeq().add(2, o);
+ 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
+ {
+ getSecuredSeq().add(2, 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
+ {
+ getSecuredSeq().add(2, "Waa hoo");
+ 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
+ {
+ getSecuredSeq().add(2, "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()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetAlt()
+ {
+ try
+ {
+ final Alt a = getSecuredSeq().getAlt(1);
+ Assert.assertTrue("Should be a secured Alt",
+ a instanceof SecuredAlt);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetBag()
+ {
+ try
+ {
+ final Bag a = getSecuredSeq().getBag(1);
+ Assert.assertTrue("Should be a secured Bag",
+ a instanceof SecuredBag);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetBoolean()
+ {
+ seq.add(2, true);
+ try
+ {
+ getSecuredSeq().getBoolean(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetByte()
+ {
+ seq.add(2, Byte.MAX_VALUE);
+ try
+ {
+ getSecuredSeq().getByte(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetChar()
+ {
+ seq.add(2, 'c');
+ try
+ {
+ getSecuredSeq().getChar(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetDouble()
+ {
+ seq.add(2, 3.14D);
+ try
+ {
+ getSecuredSeq().getDouble(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetFloat()
+ {
+ seq.add(2, 3.14F);
+ try
+ {
+ getSecuredSeq().getFloat(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetInt()
+ {
+ seq.add(2, 2);
+ try
+ {
+ getSecuredSeq().getInt(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetLanguage()
+ {
+ seq.add(2, "foo");
+ try
+ {
+ getSecuredSeq().getLanguage(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetLiteral()
+ {
+ seq.add(2, "foo");
+ try
+ {
+ getSecuredSeq().getLiteral(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetLong()
+ {
+ seq.add(2, 2L);
+ try
+ {
+ getSecuredSeq().getLong(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetObject()
+ {
+ final Object o = Integer.MAX_VALUE;
+ seq.add(2, o);
+ try
+ {
+ getSecuredSeq().getObject(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetResource()
+ {
+ seq.add(2, ResourceFactory.createResource());
+ try
+ {
+ getSecuredSeq().getResource(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ /*
+ * @Test
+ * public void testGetChar()
+ * {
+ * ResourceF f;
+ * seq.add( 2, 'c' );
+ * try
+ * {
+ * getSecuredSeq().getResource(2, f );
+ * if (!securityEvaluator.evaluate(Action.Read))
+ * {
+ * Assert.fail("Should have thrown AccessDenied Exception");
+ * }
+ * }
+ * catch (final AccessDeniedException e)
+ * {
+ * if (securityEvaluator.evaluate(Action.Read))
+ * {
+ * Assert.fail(String
+ * .format("Should not have thrown AccessDenied Exception: %s - %s",
+ * e, e.getTriple()));
+ * }
+ * }
+ *
+ * }
+ */
+ @Test
+ public void testGetSeq()
+ {
+ seq.add(2, 'c');
+ try
+ {
+ getSecuredSeq().getSeq(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetShort()
+ {
+ seq.add(2, Short.MAX_VALUE);
+ try
+ {
+ getSecuredSeq().getShort(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetString()
+ {
+ seq.add(2, "Waaa hoo");
+ try
+ {
+ getSecuredSeq().getString(2);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testIndexOf()
+ {
+ try
+ {
+ getSecuredSeq().indexOf(true);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredSeq().indexOf('c');
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredSeq().indexOf(3.14D);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredSeq().indexOf(3.14F);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredSeq().indexOf(3L);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ final Object o = Integer.MAX_VALUE;
+ getSecuredSeq().indexOf(o);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+
+ getSecuredSeq()
+ .indexOf(
+ ResourceFactory
+ .createResource("http://example.com/exampleResource"));
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredSeq().indexOf("waaa hooo");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredSeq().indexOf("dos", "es");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Override
+ @Test
+ public void testRemove()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Delete });
+ try
+ {
+ getSecuredSeq().remove(1);
+ 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 testSet()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util
+ .asSet(new Action[] { Action.Update });
+ try
+ {
+ getSecuredSeq().set(1, 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
+ {
+ getSecuredSeq().set(1, '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
+ {
+ getSecuredSeq().set(1, 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
+ {
+ getSecuredSeq().set(1, 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
+ {
+ getSecuredSeq().set(1, 3L);
+ 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 Object o = Integer.MAX_VALUE;
+ getSecuredSeq().set(1, o);
+ 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
+ {
+ getSecuredSeq().set(1, 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
+ {
+ getSecuredSeq().set(1, "Waa hoo");
+ 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
+ {
+ getSecuredSeq().set(1, "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()));
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredStatementTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredStatementTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredStatementTest.java
new file mode 100644
index 0000000..4345aa7
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/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.security.model;
+
+import java.util.Set;
+
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.Factory;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredStatement;
+import org.apache.jena.security.model.impl.SecuredStatementImpl;
+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/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/query/DataSetTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/query/DataSetTest.java b/jena-permissions/src/test/java/org/apache/jena/security/query/DataSetTest.java
new file mode 100644
index 0000000..47bcfbd
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/query/DataSetTest.java
@@ -0,0 +1,244 @@
+/*
+ * 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.query;
+
+import org.apache.jena.query.* ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.security.Factory;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
+import org.apache.jena.security.model.SecuredModel;
+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/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/query/QueryEngineTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/query/QueryEngineTest.java b/jena-permissions/src/test/java/org/apache/jena/security/query/QueryEngineTest.java
new file mode 100644
index 0000000..7bee511
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/query/QueryEngineTest.java
@@ -0,0 +1,259 @@
+/*
+ * 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.query;
+
+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.security.Factory;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
+import org.apache.jena.security.model.SecuredModel;
+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/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/query/rewriter/OpRewriterTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/query/rewriter/OpRewriterTest.java b/jena-permissions/src/test/java/org/apache/jena/security/query/rewriter/OpRewriterTest.java
new file mode 100644
index 0000000..eaec4b7
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/query/rewriter/OpRewriterTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.query.rewriter;
+
+import java.util.Arrays;
+
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.query.rewriter.OpRewriter;
+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/b712fb28/jena-permissions/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/resources/log4j.properties b/jena-permissions/src/test/resources/log4j.properties
new file mode 100644
index 0000000..f3d6f5e
--- /dev/null
+++ b/jena-permissions/src/test/resources/log4j.properties
@@ -0,0 +1,15 @@
+log4j.rootLogger=INFO, stdlog
+
+log4j.appender.stdlog=org.apache.log4j.ConsoleAppender
+## log4j.appender.stdlog.target=System.err
+log4j.appender.stdlog.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdlog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %-25c{1} :: %m%n
+
+# Execution logging
+log4j.logger.org.apache.jena.arq.info=INFO
+log4j.logger.org.apache.jena.arq.exec=INFO
+
+# Everything else in Jena
+log4j.logger.org.apache.jena=WARN
+log4j.logger.org.apache.jena=WARN
+log4j.logger.org.apache.jena.riot=INFO
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/resources/org/apache/jena/security/SecuredAssemblerTest.ttl
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/resources/org/apache/jena/security/SecuredAssemblerTest.ttl b/jena-permissions/src/test/resources/org/apache/jena/security/SecuredAssemblerTest.ttl
new file mode 100644
index 0000000..b8289f7
--- /dev/null
+++ b/jena-permissions/src/test/resources/org/apache/jena/security/SecuredAssemblerTest.ttl
@@ -0,0 +1,56 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+
+@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
+@prefix sec: <http://apache.org/jena/security/Assembler#> .
+@prefix my: <http://apache.org/jena/security/test#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#>
+
+<> ja:loadClass "org.apache.jena.security.SecuredAssembler" .
+
+sec:Model
+ rdfs:subClassOf ja:NamedModel ;
+ .
+
+my:baseModel
+ a ja:MemoryModel;
+ .
+
+my:secModel
+ a sec:Model;
+ sec:baseModel my:baseModel ;
+ ja:modelName "http://example.com/securedModel" ;
+ sec:evaluatorFactory "org.apache.jena.security.MockSecurityEvaluator" ;
+ .
+
+my:secModel2
+ a sec:Model;
+ sec:baseModel my:baseModel ;
+ ja:modelName "http://example.com/securedModel2" ;
+ sec:evaluatorImpl my:secEvaluator ;
+ .
+
+my:secEvaluator
+ a sec:Evaluator ;
+ sec:args [ rdf:_1 "bob" ;
+ ] ;
+ sec:evaluatorClass "org.apache.jena.security.StaticSecurityEvaluator" ;
+ .
+
+my:secModel3
+ a sec:Model;
+ sec:baseModel my:baseModel ;
+ ja:modelName "http://example.com/securedModel3" ;
+ sec:evaluatorImpl my:secEvaluator2 ;
+ .
+
+ my:secEvaluator2
+ a sec:Evaluator ;
+ sec:args [ rdf:_1 my:baseModel ;
+ ] ;
+ sec:evaluatorClass "org.apache.jena.security.ModelBasedSecurityEvaluator" ;
+ .
+
+
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/resources/org/apache/jena/security/model/detail.ttl
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/resources/org/apache/jena/security/model/detail.ttl b/jena-permissions/src/test/resources/org/apache/jena/security/model/detail.ttl
new file mode 100644
index 0000000..643c586
--- /dev/null
+++ b/jena-permissions/src/test/resources/org/apache/jena/security/model/detail.ttl
@@ -0,0 +1,33 @@
+@prefix ex: <http://example.com/> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+
+ex:msg1 rdf:type ex:msg;
+ ex:to "bob";
+ ex:from "alice" ;
+ ex:subj "alice to bob 1";
+ .
+
+ex:msg2 rdf:type ex:msg;
+ ex:to "alice";
+ ex:from "bob";
+ ex:subj "bob to alice 1";
+ .
+
+ex:msg3 rdf:type ex:msg;
+ ex:to "chuck" ;
+ ex:from "alice";
+ ex:subj "alice to chuck 1";
+ .
+
+ex:msg4 rdf:type ex:msg;
+ ex:to "darla" ;
+ ex:from "bob" ;
+ ex:subj "bob to darla 1"
+ .
+
+ex:msg5 rdf:type ex:msg;
+ ex:to "alice";
+ ex:from "bob";
+ ex:subj "bob to alice 2";
+ .
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/resources/org/apache/jena/security/model/test.ttl
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/resources/org/apache/jena/security/model/test.ttl b/jena-permissions/src/test/resources/org/apache/jena/security/model/test.ttl
new file mode 100644
index 0000000..2fbb4e3
--- /dev/null
+++ b/jena-permissions/src/test/resources/org/apache/jena/security/model/test.ttl
@@ -0,0 +1,2 @@
+@prefix rt: <http://example.com/readTest#> .
+rt:1 a rt:3 .
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/resources/org/apache/jena/security/model/test.xml
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/resources/org/apache/jena/security/model/test.xml b/jena-permissions/src/test/resources/org/apache/jena/security/model/test.xml
new file mode 100644
index 0000000..18ad45a
--- /dev/null
+++ b/jena-permissions/src/test/resources/org/apache/jena/security/model/test.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:rt="http://example.com/readTest#" xmlns:j.0="http://example.com/readTest#3">
+ <rdf:Description rdf:about="http://example.com/readTest#1">
+ <rdf:type rdf:resource="http://example.com/readTest#3" />
+ </rdf:Description>
+</rdf:RDF>
[12/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/LICENSE
----------------------------------------------------------------------
diff --git a/jena-security/LICENSE b/jena-security/LICENSE
deleted file mode 100644
index d645695..0000000
--- a/jena-security/LICENSE
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed 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.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/NOTICE
----------------------------------------------------------------------
diff --git a/jena-security/NOTICE b/jena-security/NOTICE
deleted file mode 100644
index d4e11ad..0000000
--- a/jena-security/NOTICE
+++ /dev/null
@@ -1,5 +0,0 @@
-Apache Jena - Security module
-Copyright 2011, 2012, 2013, 2014, 2015 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/license-header.txt
----------------------------------------------------------------------
diff --git a/jena-security/license-header.txt b/jena-security/license-header.txt
deleted file mode 100644
index 2114391..0000000
--- a/jena-security/license-header.txt
+++ /dev/null
@@ -1,15 +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.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/pom.xml
----------------------------------------------------------------------
diff --git a/jena-security/pom.xml b/jena-security/pom.xml
deleted file mode 100644
index 470c22d..0000000
--- a/jena-security/pom.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- 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.
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.jena</groupId>
- <artifactId>jena-security</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- </properties>
- <name>Apache Jena - Security</name>
- <description>Security (Permissions) wrapper around Jena RDF implementation.</description>
- <url>http://jena.apache.org/documentation/security</url>
- <inceptionYear>2012</inceptionYear>
-
- <parent>
- <groupId>org.apache.jena</groupId>
- <artifactId>jena-parent</artifactId>
- <version>14-SNAPSHOT</version>
- <relativePath>../jena-parent</relativePath>
- </parent>
- <organization>
- <name>The Apache Software Foundation</name>
- <url>http://www.apache.org/</url>
- </organization>
- <issueManagement>
- <url>http://issues.apache.org/jira/browse/JENA</url>
- <system>JIRA</system>
- </issueManagement>
- <repositories>
- <repository>
- <id>apache-snapshots-repo</id>
- <url>https://repository.apache.org/content/repositories/snapshots/</url>
- </repository>
- <repository>
- <id>apache-staging-repo</id>
- <url>https://repository.apache.org/content/repositories/staging/</url>
- </repository>
- <repository>
- <id>apache-releases-repo</id>
- <url>https://repository.apache.org/content/repositories/releases/</url>
- </repository>
- </repositories>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>1.9.1</version>
- <executions>
- <execution>
- <id>add-example-source</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>add-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>src/example/java</source>
- </sources>
- </configuration>
- </execution>
- <execution>
- <id>add-example-resource</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>add-resource</goal>
- </goals>
- <configuration>
- <resources>
- <resource>
- <directory>src/example/resources</directory>
- <targetPath>${project.build.outputDirectory}</targetPath>
- </resource>
- </resources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <!-- <version>2.9</version> -->
- <configuration>
- <excludePackageNames>org.apache.jena.security.example:org.apache.jena.security.example.*</excludePackageNames>
- <tags>
- <tag>
- <name>sec.graph</name>
- <!-- tag for all places -->
- <placement>a</placement>
- <head>Required graph permissions:</head>
- </tag>
- <tag>
- <name>sec.triple</name>
- <!-- tag for all places -->
- <placement>a</placement>
- <head>Required triple permissions:</head>
- </tag>
- </tags>
- <overview>${basedir}/src/main/overview.html</overview>
-
- </configuration>
- <executions>
- <execution>
- <id>attach-javadocs</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>org/apache/jena/security/example/**</exclude>
- </excludes>
- </configuration>
- <executions>
- <execution>
- <id>create-test-jar</id>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- <execution>
- <id>create-example-jar</id>
- <phase>package</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- <configuration>
- <classedDirectory>target</classedDirectory>
- <classifier>example</classifier>
- <includes>
- <include>../src/example/**</include>
- <include>../src/example</include>
- <include>META-INF/**</include>
- <include>org/apache/jena/security/example/**</include>
- </includes>
- <excludes>
- <exclude>META-INF/DEPENDENCIES</exclude>
- </excludes>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-collections4</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.jena</groupId>
- <artifactId>apache-jena-libs</artifactId>
- <version>${project.version}</version>
- <type>pom</type>
- </dependency>
- <dependency>
- <groupId>org.apache.jena</groupId>
- <artifactId>jena-core</artifactId>
- <version>${project.version}</version>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-core</artifactId>
- <version>1.2.2</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/readme.md
----------------------------------------------------------------------
diff --git a/jena-security/readme.md b/jena-security/readme.md
deleted file mode 100644
index 5feaa42..0000000
--- a/jena-security/readme.md
+++ /dev/null
@@ -1,32 +0,0 @@
-REQUIRES Jena 2.10.0
-
-JenaSecurity is a SecurityEvaluator interface and a set of dynamic proxies that apply that interface to Jena Graphs, Models, and associated methods and classes.
-
-The SecurityEvaluator class must be implemented. This class provides the interface to the authentication results (e.g. getPrincipal())) and the authorization system.
-
-Create a SecuredGraph by calling Factory.getInstance( SecurityEvaluator, String, Graph );
-Create a SecuredModel by calling Factory.getInstance( SecurityEvaluator, String, Model ) or ModelFactory.createModelForGraph( SecuredGraph );
-
-NOTE: when creating a model by wrapping a secured graph (e.g. ModelFactory.createModelForGraph( SecuredGraph );) the resulting Model does not
-have the same security requirements that the standard secured model does.
-
-For instance when creating a list on a secured model calling model.createList( RDFNode[] ); The standard secured model verifies that the user
-has the right to update the triples and allows or denies the entire operation accordingly. The wrapped secured graph does not have visibility
-to the createList() command and can only operate on the instructions issued by the model.createList() implementation. In the standard implementation
-the model requests the graph to delete one triple and then insert another. Thus the user must have delete and add permissions, not the update permission.
-
-There are several other cases where the difference in the layer can trip up the security system. In all known cases the result is a tighter
-security definition than was requested. For simplicity sake we recommend that the wrapped secured graph only be used in cases where access to the
-graph as a whole is granted/denied. In these cases the user either has all CRUD capabilities or none.
-
-[] a ja:Model ;
- sec:baseModel jena:model ;
- ja:modelName "modelName";
- sec:evaluatorFactory "javaclass";
- .
-
-jena:model A model defined in the assembler file.
-"modelName" The name of the model as identified in the security manager
-"javaclass" The name of a java class that implements a Evaluator Factory. The Factory must have static method getInstance() that
-returns a SecurityEvaluator.
-
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/example/java/org/apache/jena/security/example/ExampleEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/example/java/org/apache/jena/security/example/ExampleEvaluator.java b/jena-security/src/example/java/org/apache/jena/security/example/ExampleEvaluator.java
deleted file mode 100644
index 3ed244e..0000000
--- a/jena-security/src/example/java/org/apache/jena/security/example/ExampleEvaluator.java
+++ /dev/null
@@ -1,147 +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.example;
-
-import java.security.Principal;
-import java.util.Set;
-
-import org.apache.http.auth.BasicUserPrincipal;
-import org.apache.jena.security.SecurityEvaluator;
-
-import org.apache.jena.graph.NodeFactory;
-import org.apache.jena.rdf.model.AnonId;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.Property;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Resource;
-import org.apache.jena.rdf.model.ResourceFactory;
-import org.apache.jena.vocabulary.RDF;
-
-/**
- * An example evaluator that only provides access to messages in the graph that
- * are from or to the principal.
- *
- */
-public class ExampleEvaluator implements SecurityEvaluator {
-
- private Principal principal;
- private Model model;
- private RDFNode msgType = ResourceFactory.createResource( "http://example.com/msg" );
- private Property pTo = ResourceFactory.createProperty( "http://example.com/to" );
- private Property pFrom = ResourceFactory.createProperty( "http://example.com/from" );
-
- /**
- *
- * @param model The graph we are going to evaluate against.
- */
- public ExampleEvaluator( Model model )
- {
- this.model = model;
- }
-
- @Override
- public boolean evaluate(Object principal, Action action, SecNode graphIRI) {
- // we allow any action on a graph.
- return true;
- }
-
- private boolean evaluate( Object principalObj, Resource r )
- {
- Principal principal = (Principal)principalObj;
- // a message is only available to sender or recipient
- if (r.hasProperty( RDF.type, msgType ))
- {
- return r.hasProperty( pTo, principal.getName() ) ||
- r.hasProperty( pFrom, principal.getName());
- }
- return true;
- }
-
- private boolean evaluate( Object principal, SecNode node )
- {
- if (node.equals( SecNode.ANY )) {
- return false; // all wild cards are false
- }
-
- if (node.getType().equals( SecNode.Type.URI)) {
- Resource r = model.createResource( node.getValue() );
- return evaluate( principal, r );
- }
- else if (node.getType().equals( SecNode.Type.Anonymous)) {
- Resource r = model.getRDFNode( NodeFactory.createAnon( new AnonId( node.getValue()) ) ).asResource();
- return evaluate( principal, r );
- }
- else
- {
- return true;
- }
-
- }
-
- private boolean evaluate( Object principal, SecTriple triple ) {
- return evaluate( principal, triple.getSubject()) &&
- evaluate( principal, triple.getObject()) &&
- evaluate( principal, triple.getPredicate());
- }
-
- @Override
- public boolean evaluate(Object principal, Action action, SecNode graphIRI, SecTriple triple) {
- return evaluate( principal, triple );
- }
-
- @Override
- public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return evaluate( principal, triple );
- }
-
- @Override
- public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- @Override
- public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return evaluate( principal, triple );
- }
-
- @Override
- public boolean evaluateUpdate(Object principal, SecNode graphIRI, SecTriple from, SecTriple to) {
- return evaluate( principal, from ) && evaluate( principal, to );
- }
-
- public void setPrincipal( String userName )
- {
- if (userName == null)
- {
- principal = null;
- }
- principal = new BasicUserPrincipal( userName );
- }
- @Override
- public Principal getPrincipal() {
- return principal;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/example/java/org/apache/jena/security/example/SecurityExample.java
----------------------------------------------------------------------
diff --git a/jena-security/src/example/java/org/apache/jena/security/example/SecurityExample.java b/jena-security/src/example/java/org/apache/jena/security/example/SecurityExample.java
deleted file mode 100644
index 0b7e0d9..0000000
--- a/jena-security/src/example/java/org/apache/jena/security/example/SecurityExample.java
+++ /dev/null
@@ -1,93 +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.example;
-
-import java.net.URL;
-
-import org.apache.jena.security.Factory;
-
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.ModelFactory;
-import org.apache.jena.rdf.model.Property;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.ResIterator;
-import org.apache.jena.rdf.model.Resource;
-import org.apache.jena.rdf.model.ResourceFactory;
-import org.apache.jena.rdf.model.Statement;
-import org.apache.jena.vocabulary.RDF;
-
-public class SecurityExample {
-
- /**
- * @param args
- */
-
- public static void main(String[] args) {
- String[] names = { "alice", "bob", "chuck", "darla" };
-
- RDFNode msgType = ResourceFactory
- .createResource("http://example.com/msg");
- Property pTo = ResourceFactory.createProperty("http://example.com/to");
- Property pFrom = ResourceFactory
- .createProperty("http://example.com/from");
- Property pSubj = ResourceFactory
- .createProperty("http://example.com/subj");
-
- Model model = ModelFactory.createDefaultModel();
- URL url = SecurityExample.class.getClassLoader().getResource(
- "org/apache/jena/security/example/example.ttl");
- model.read(url.toExternalForm());
- ResIterator ri = model.listSubjectsWithProperty(RDF.type, msgType);
- System.out.println("All the messages");
- while (ri.hasNext()) {
- Resource msg = ri.next();
- Statement to = msg.getProperty(pTo);
- Statement from = msg.getProperty(pFrom);
- Statement subj = msg.getProperty(pSubj);
- System.out.println(String.format("%s to: %s from: %s subj: %s",
- msg, to.getObject(), from.getObject(), subj.getObject()));
- }
- System.out.println();
-
- ExampleEvaluator evaluator = new ExampleEvaluator(model);
- model = Factory.getInstance(evaluator,
- "http://example.com/SecuredModel", model);
- for (String userName : names) {
- evaluator.setPrincipal(userName);
-
- System.out.println("Messages " + userName + " can manipulate");
- ri = model.listSubjectsWithProperty(RDF.type, msgType);
- while (ri.hasNext()) {
- Resource msg = ri.next();
- Statement to = msg.getProperty(pTo);
- Statement from = msg.getProperty(pFrom);
- Statement subj = msg.getProperty(pSubj);
- System.out.println(String.format(
- "%s to: %s from: %s subj: %s", msg, to.getObject(),
- from.getObject(), subj.getObject()));
- }
- ri.close();
- for (String name : names)
- {
- System.out.println( String.format( "%s messages to %s", model.listSubjectsWithProperty( pTo, name ).toList().size(), name ) );
- }
- System.out.println();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/example/java/org/apache/jena/security/example/ShiroExampleEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/example/java/org/apache/jena/security/example/ShiroExampleEvaluator.java b/jena-security/src/example/java/org/apache/jena/security/example/ShiroExampleEvaluator.java
deleted file mode 100644
index a1eedef..0000000
--- a/jena-security/src/example/java/org/apache/jena/security/example/ShiroExampleEvaluator.java
+++ /dev/null
@@ -1,235 +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.example;
-
-import java.util.Set;
-
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.subject.Subject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.jena.graph.NodeFactory;
-import org.apache.jena.rdf.model.AnonId;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.Property;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Resource;
-import org.apache.jena.rdf.model.ResourceFactory;
-import org.apache.jena.vocabulary.RDF;
-
-/**
- * Class to use Shiro to provide credentials.
- *
- * An example evaluator that only provides access to messages in the graph that
- * are from or to the principal.
- *
- */
-public class ShiroExampleEvaluator implements SecurityEvaluator {
-
- private static final Logger LOG = LoggerFactory.getLogger(ShiroExampleEvaluator.class);
- // the model that contains the messages.
- private Model model;
- private RDFNode msgType = ResourceFactory.createResource( "http://example.com/msg" );
- private Property pTo = ResourceFactory.createProperty( "http://example.com/to" );
- private Property pFrom = ResourceFactory.createProperty( "http://example.com/from" );
-
- /**
- *
- * @param model The graph we are going to evaluate against.
- */
- public ShiroExampleEvaluator( Model model )
- {
- this.model = model;
- }
-
- /**
- * We allow any action on the graph itself, so this is always true.
- */
- @Override
- public boolean evaluate(Object principal, Action action, SecNode graphIRI) {
- // we allow any action on a graph.
- return true;
- }
-
- /**
- * This is our internal check to see if the user may access the resource.
- * This method is called from the evauate(Object,SecNode) method.
- * A user may only access the resource if they are authenticated, and are either the
- * sender or the recipient.
- * Additionally the admin can always see the messages.
- * @param principalObj
- * @param r
- * @return
- */
- private boolean evaluate( Object principalObj, Resource r )
- {
- // cast to the Subject because we know that it comes from Shiro and that
- // our getPrincipal() method returns a Subject.
- Subject subject = (Subject)principalObj;
- if (! subject.isAuthenticated())
- {
- LOG.info( "User not authenticated");
- return false;
- }
- // a message is only available to sender or recipient
- LOG.debug( "checking {}", subject.getPrincipal());
- Object principal = subject.getPrincipal();
-
- // We put the admin check here but it could have been done much earlier.
- if ("admin".equals(principal.toString()))
- {
- return true;
- }
- // if we are looking at a message object then check the restrictions.
- if (r.hasProperty( RDF.type, msgType ))
- {
- return r.hasProperty( pTo, subject.getPrincipal().toString() ) ||
- r.hasProperty( pFrom, subject.getPrincipal().toString());
- }
- // otherwise user can see the object.
- return true;
- }
-
- /**
- * Check that the user can see a specific node.
- * @param principal
- * @param node
- * @return
- */
- private boolean evaluate( Object principal, SecNode node )
- {
- // Access to wild card is false -- this forces checks to the acutal nodes
- // to be returned.
- // we could have checked for admin access here and returned true since the admin
- // can see any node.
- if (node.equals( SecNode.ANY )) {
- return false;
- }
-
- // URI nodes are retrieved from the model and evaluated
- if (node.getType().equals( SecNode.Type.URI)) {
- Resource r = model.createResource( node.getValue() );
- return evaluate( principal, r );
- }
- // anonymous nodes have to be retrieved from the model as anonymous nodes.
- else if (node.getType().equals( SecNode.Type.Anonymous)) {
- Resource r = model.getRDFNode( NodeFactory.createAnon( new AnonId( node.getValue()) ) ).asResource();
- return evaluate( principal, r );
- }
- // anything else (literals) can be seen.
- else
- {
- return true;
- }
-
- }
-
- /**
- * Evaluate if the user can see the triple.
- * @param principal
- * @param triple
- * @return
- */
- private boolean evaluate( Object principal, SecTriple triple ) {
- // we could have checked here to see if the principal was the admin and
- // just returned true since the admin can perform any operation on any triple.
- return evaluate( principal, triple.getSubject()) &&
- evaluate( principal, triple.getObject()) &&
- evaluate( principal, triple.getPredicate());
- }
-
- /**
- * As per our design, users can do anything with triples they have access to, so we just
- * ignore the action parameter. If we were to implement rules restricted access based
- * upon action this method would sort those out appropriately.
- */
- @Override
- public boolean evaluate(Object principal, Action action, SecNode graphIRI, SecTriple triple) {
- // we could have checked here to see if the principal was the admin and
- // just returned true since the admin can perform any operation on any triple.
- return evaluate( principal, triple );
- }
-
- /**
- * As per our design, users can access any graph. If we were to implement rules that
- * restricted user access to specific graphs, those checks would be here and we would
- * return <code>false</code> if they were not allowed to access the graph. Note that this
- * method is checking to see that the user may perform ALL the actions in the set on the
- * graph.
- */
- @Override
- public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- /**
- * As per our design, users can access any triple from a message that is from or to them.
- * Since we don't have restrictions on actions this is no different then checking access
- * for a single action.
- */
- @Override
- public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return evaluate( principal, triple );
- }
-
- /**
- * As per our design, users can access any graph. If we were to implement rules that
- * restricted user access to specific graphs, those checks would be here and we would
- * return <code>false</code> if they were not allowed to access the graph. Note that this
- * method is checking to see that the user may perform ANY of the actions in the set on the
- * graph.
- */
- @Override
- public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI) {
- return true;
- }
-
- /**
- * As per our design, users can access any triple from a message that is from or to them.
- * Since we don't have restrictions on actions this is no different then checking access
- * for a single action.
- */
- @Override
- public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return evaluate( principal, triple );
- }
-
- /**
- * As per our design, users can access any triple from a message that is from or to them.
- * So for an update they can only change triples they have access to into other triples
- * they have access to. (e.g. they can not remvoe themself from the messsage).
- */
- @Override
- public boolean evaluateUpdate(Object principal, SecNode graphIRI, SecTriple from, SecTriple to) {
- return evaluate( principal, from ) && evaluate( principal, to );
- }
-
- /**
- * Return the Shiro subject. This is the subject that Shiro currently has logged in.
- */
- @Override
- public Object getPrincipal() {
- return SecurityUtils.getSubject();
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/example/resources/org/apache/jena/security/example/example.ttl
----------------------------------------------------------------------
diff --git a/jena-security/src/example/resources/org/apache/jena/security/example/example.ttl b/jena-security/src/example/resources/org/apache/jena/security/example/example.ttl
deleted file mode 100644
index 7047629..0000000
--- a/jena-security/src/example/resources/org/apache/jena/security/example/example.ttl
+++ /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.
-
-@prefix ex: <http://example.com/> .
-@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-
-ex:msg1 rdf:type ex:msg;
- ex:to "bob";
- ex:from "alice" ;
- ex:subj "alice to bob 1";
- .
-
-ex:msg2 rdf:type ex:msg;
- ex:to "alice";
- ex:from "bob";
- ex:subj "bob to alice 1";
- .
-
-ex:msg3 rdf:type ex:msg;
- ex:to "chuck" ;
- ex:from "alice";
- ex:subj "alice to chuck 1";
- .
-
-ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
- .
-
-ex:msg5 rdf:type ex:msg;
- ex:to "alice";
- ex:from "bob";
- ex:subj "bob to alice 2";
- .
-
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/example/resources/org/apache/jena/security/example/fuseki/config.ttl
----------------------------------------------------------------------
diff --git a/jena-security/src/example/resources/org/apache/jena/security/example/fuseki/config.ttl b/jena-security/src/example/resources/org/apache/jena/security/example/fuseki/config.ttl
deleted file mode 100644
index a748f01..0000000
--- a/jena-security/src/example/resources/org/apache/jena/security/example/fuseki/config.ttl
+++ /dev/null
@@ -1,98 +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.
-
-##
-## Define all the prefixes
-##
-
-@prefix fuseki: <http://jena.apache.org/fuseki#> .
-@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
-@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
-@prefix sec: <http://apache.org/jena/security/Assembler#> .
-@prefix my: <http://example.org/#> .
-
-##
-## Load the SecuredAssembler class from the security library and define
-## the sec:Model as a subclass of ja:NamedModel.
-##
-[] ja:loadClass "org.apache.jena.security.SecuredAssembler" .
-sec:Model rdfs:subClassOf ja:NamedModel .
-
-##
-## Define the base model that contains the unsecured data.
-##
-my:baseModel rdf:type ja:MemoryModel;
- ja:content [ja:externalContent <file:./example.ttl>]
- .
-
-##
-## Define the secured model. This is where permissions is applied to the
-## my:baseModel to create a model that has permission restrictions. Note
-## that it is using the security evaluator implementation (sec:evaluatorImpl)
-## called my:secEvaluator which we will define next.
-##
-my:securedModel rdf:type sec:Model ;
- sec:baseModel my:baseModel ;
- ja:modelName "https://example.org/securedModel" ;
- sec:evaluatorImpl my:secEvaluator .
-
-##
-## Define the security evaluator. This is where we use the example
-## ShiroExampleEvaluator. For your production environment you will replace
-## "org.apache.jena.security.example.ShiroExampleEvaluator" with your
-## SecurityEvaluator implementation. Note that ShiroExampleEvaluator constructor
-## takes a Model argument. We pass in the unsecured baseModel so that the evaluator
-## can read it unencumbered. Your implementation of SecurityEvaluator may have different
-## parameters to meet your specific needs.
-##
-my:secEvaluator rdf:type sec:Evaluator ;
- sec:args [
- rdf:_1 my:baseModel ;
- ] ;
- sec:evaluatorClass "org.apache.jena.security.example.ShiroExampleEvaluator" .
-
-##
-## Define the dataset that we will use for in the server.
-##
-my:securedDataset rdf:type ja:RDFDataset ;
- ja:defaultGraph my:securedModel .
-
-##
-## Define the fuseki:Server.
-##
-my:fuskei rdf:type fuseki:Server ;
- fuseki:services (
- my:service1
- ) .
-
-##
-## Define the service for the fuseki:Service. Note that the fuseki:dataset served by
-## this server is the secured dataset defined above.
-##
-my:service1 rdf:type fuseki:Service ;
- rdfs:label "My Secured Data Service" ;
- fuseki:name "myAppFuseki" ; # http://host:port/myAppFuseki
- fuseki:serviceQuery "query" ; # SPARQL query service
- fuseki:serviceQuery "sparql" ; # SPARQL query service
- fuseki:serviceUpdate "update" ; # SPARQL query service
- fuseki:serviceUpload "upload" ; # Non-SPARQL upload service
- fuseki:serviceReadWriteGraphStore "data" ; # SPARQL Graph store protocol (read and write)
- # A separate ead-only graph store endpoint:
- fuseki:serviceReadGraphStore "get" ; # SPARQL Graph store protocol (read only)
- fuseki:dataset my:securedDataset ;
- .
-
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/example/resources/org/apache/jena/security/example/fuseki/shiro.ini
----------------------------------------------------------------------
diff --git a/jena-security/src/example/resources/org/apache/jena/security/example/fuseki/shiro.ini b/jena-security/src/example/resources/org/apache/jena/security/example/fuseki/shiro.ini
deleted file mode 100644
index a9fbf71..0000000
--- a/jena-security/src/example/resources/org/apache/jena/security/example/fuseki/shiro.ini
+++ /dev/null
@@ -1,47 +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.
-
-[main]
-# Development
-ssl.enabled = false
-
-plainMatcher=org.apache.shiro.authc.credential.SimpleCredentialsMatcher
-#iniRealm=org.apache.shiro.realm.text.IniRealm
-iniRealm.credentialsMatcher = $plainMatcher
-
-localhost=org.apache.jena.fuseki.authz.LocalhostFilter
-
-[users]
-# Implicitly adds "iniRealm = org.apache.shiro.realm.text.IniRealm"
-admin=admin
-alice=alice
-bob=bob
-chuck=chuck
-darla=darla
-
-[roles]
-
-[urls]
-## Control functions open to anyone
-/$/status = anon
-/$/ping = anon
-
-## restrict access. Must log in with above.
-/$/** = authcBasic,user
-
-
-# Everything else
-/**=anon
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/AccessDeniedException.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/AccessDeniedException.java b/jena-security/src/main/java/org/apache/jena/security/AccessDeniedException.java
deleted file mode 100644
index 3c0654d..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/AccessDeniedException.java
+++ /dev/null
@@ -1,66 +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.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-
-/**
- * Exception thrown by the security system when an action is not allowed.
- *
- * Contains the graphIRI and the action that was not allowed.
- */
-public class AccessDeniedException extends RuntimeException
-{
- private static final long serialVersionUID = 2789332975364811725L;
-
- private String triple;
-
- /**
- * Constructor.
- * @param uri The SecNode that identifies graph with the security.
- * @param action The action that was prohibited.
- */
- public AccessDeniedException( final SecNode uri, final Action action )
- {
- super(String.format("securedModel sec. %s: %s", uri, action));
- }
-
- /**
- * Constructor.
- * @param uri The SecNode that identifies graph with the security.
- * @param triple The triple The triple on which the action was prohibited.
- * @param action The action that was prohibited.
- */
- public AccessDeniedException( final SecNode uri, final String triple,
- final Action action )
- {
- super(String.format("triple sec. %s: %s", uri, action));
- this.triple = triple;
- }
-
- /**
- * @return The triple on which the action was prohibited. May be null.
- */
- public String getTriple()
- {
- return triple;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/AssemblerConstants.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/AssemblerConstants.java b/jena-security/src/main/java/org/apache/jena/security/AssemblerConstants.java
deleted file mode 100644
index 700883e..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/AssemblerConstants.java
+++ /dev/null
@@ -1,62 +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.apache.jena.rdf.model.Property ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-
-public interface AssemblerConstants {
- public static final String URI = "http://apache.org/jena/security/Assembler#";
- /**
- * Property named URI+"evaluatorFactory"
- */
- public static final Property EVALUATOR_FACTORY =
- ResourceFactory.createProperty( URI + "evaluatorFactory" );
- /**
- * Property named URI+"Model"
- */
- public static final Property SECURED_MODEL = ResourceFactory.createProperty( URI + "Model" );
- /**
- * Property named URI+"baseModel"
- */
- public static final Property BASE_MODEL = ResourceFactory.createProperty( URI + "baseModel" );
- /**
- * Property named URI+"Evaluator"
- */
- public static final Property EVALUATOR_ASSEMBLER = ResourceFactory.createProperty( URI+"Evaluator" );
- /**
- * Property named URI+"evaluatorImpl"
- */
- public static final Property EVALUATOR_IMPL =
- ResourceFactory.createProperty( URI + "evaluatorImpl" );
-
- /**
- * Property named URI+"evaluatorClass"
- */
- public static final Property EVALUATOR_CLASS =
- ResourceFactory.createProperty( URI + "evaluatorClass" );
- /**
- * Property named URI+"evaluatorImpl"
- */
- public static final Property ARGUMENT_LIST =
- ResourceFactory.createProperty( URI + "args" );
-
- // message formats
- public static final String NO_X_PROVIDED = "No %s provided for %s";
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/Factory.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/Factory.java b/jena-security/src/main/java/org/apache/jena/security/Factory.java
deleted file mode 100644
index 1ae3579..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/Factory.java
+++ /dev/null
@@ -1,69 +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.apache.jena.graph.Graph ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.security.graph.SecuredGraph;
-import org.apache.jena.security.model.SecuredModel;
-
-/**
- * The factory that can be used to create an instance of a SecuredGraph or a SecuredModel.
- */
-public class Factory
-{
-
- /**
- * 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 graph secured under the name graphIRI
- */
- public static SecuredGraph getInstance(
- final SecurityEvaluator securityEvaluator, final String graphIRI,
- final Graph graph )
- {
-
- return org.apache.jena.security.graph.impl.Factory.getInstance(
- securityEvaluator, graphIRI, graph);
- }
-
- /**
- * Get an instance of SecuredModel
- *
- * @param securityEvaluator
- * The security evaluator to use
- * @param modelIRI
- * The securedModel IRI (graph IRI) to evaluate against.
- * @param model
- * The model to secure.
- * @return the model secured under the name modelIRI
- */
- public static SecuredModel getInstance(
- final SecurityEvaluator securityEvaluator, final String modelIRI,
- final Model model )
- {
- return org.apache.jena.security.model.impl.SecuredModelImpl.getInstance(
- securityEvaluator, modelIRI, model);
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/SecuredAssembler.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/SecuredAssembler.java b/jena-security/src/main/java/org/apache/jena/security/SecuredAssembler.java
deleted file mode 100644
index 02b255d..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/SecuredAssembler.java
+++ /dev/null
@@ -1,264 +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.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-
-import org.apache.jena.assembler.Assembler ;
-import org.apache.jena.assembler.JA ;
-import org.apache.jena.assembler.Mode ;
-import org.apache.jena.assembler.assemblers.AssemblerGroup ;
-import org.apache.jena.assembler.assemblers.ModelAssembler ;
-import org.apache.jena.assembler.exceptions.AssemblerException ;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.sparql.util.MappingRegistry ;
-
-/**
- * Assembler for a secured model.
- *
- * <p>
- * The assembler file should include the following
- * <code><pre>
- * <>; ja:loadClass "org.apache.jena.security.SecuredAssembler" .
- *
- * sec:Model rdfs:subClassOf ja:NamedModel .
- *
- * sec:evaluator rdfs:domain sec:Model ;
- * rdfs:range sec:Evaluator .
- * </pre></code>
- *
- * The model definition should include something like.
- *
- * <code><pre>
- * my:secModel a sec:Model ;
- * sec:baseModel my:baseModel ;
- * ja:modelName "http://example.com/securedModel" ;
- * sec:evaluatorFactory "org.apache.jena.security.MockSecurityEvaluator" ;
- * .
- * </pre></code>
- *
- * Terms used in above example:
- *
- * <dl>
- * <dt>my:secModel</dt>
- * <dd>The secured model as referenced in the assembler file.</dd>
- *
- * <dt>sec:Model</dt>
- * <dd>Identifes my:secModel as a secured model</dd>
- *
- * <dt>sec:baseModel</dt>
- * <dd>Identifies my:baseModel as the base model we are applying security to</dd>
- *
- * <dt>my:baseModel</dt>
- * <dd>a ja:Model (or subclass) defined elsewhere in the assembler file</dd>
- *
- * <dt>ja:modelName</dt>
- * <dd>The name of the graph as it will be addressed in the security environment
- * (see ja:NamedModel examples from Jena)</dd>
- *
- * <dt>sec:evaluatorFactory</dt>
- * <dd>Identifies "org.apache.jena.security.MockSecurityEvaluator" as the java class
- * that implements an Evaluator Factory. The Factory must have
- * static method <code>getInstance()</code> that returns a SecurityEvaluator.</dd>
- * </dl>
- *
- * or if using an evaluator assembler
- *
- * <code><pre>
- * my:secModel a sec:Model ;
- * sec:baseModel my:baseModel ;
- * ja:modelName "http://example.com/securedModel" ;
- * sec:evaluatorImpl ex:myEvaluator;
- * .
- *
- * ex:myEvaluator a sec:Evaluator ;
- * ex:arg1 "argument 1 for my evaluator constructor" ;
- * ex:arg2 "argument 2 for my evaluator constructor" ;
- * .
- *
- * </pre></code>
- *
- * Terms used in above example:
- *
- * <dl>
- * <dt>my:secModel</dt>
- * <dd>The secured model as referenced in the assembler file.</dd>
- *
- * <dt>sec:Model</dt>
- * <dd>Identifes my:secModel as a secured model</dd>
- *
- * <dt>sec:baseModel</dt>
- * <dd>Identifies my:baseModel as the base model we are applying security to</dd>
- *
- * <dt>my:baseModel</dt>
- * <dd>a ja:Model (or subclass) defined elsewhere in the assembler file</dd>
- *
- * <dt>ja:modelName</dt>
- * <dd>The name of the graph as it will be addressed in the security environment
- * (see ja:NamedModel examples from Jena)</dd>
- *
- * <dt>sec:evaluatorImpl</dt>
- * <dd>Identifies ex:myEvaluator as a SecurityEvaluator defined elsewhere in the assembler file.
- * It must subclass as a sec:Evaluator.</dd>
- * </dd>
- *
- * <dt>ex:arg1 and ex:arg2</dt>
- * <dd>Arguments as defined by the user defined security evaluator assembler.</dd>
- * </dl>
-
- * </p>
- *
- */
-public class SecuredAssembler extends ModelAssembler implements AssemblerConstants {
- private static boolean initialized;
-
- // message formats
- private static final String ERROR_FINDING_FACTORY = "Error finding factory class %s: %s";
-
- static { init() ; }
-
- /**
- * Initialize the assembler.
- * Registers the prefix "sec" with the uri http://apache.org/jena/security/Assembler#
- * and registers this assembler with the uri http://apache.org/jena/security/Assembler#Model
- */
- static synchronized public void init()
- {
- if ( initialized )
- return ;
- MappingRegistry.addPrefixMapping("sec", URI) ;
- registerWith(Assembler.general) ;
- initialized = true ;
- }
-
- /**
- * Register this assembler in the assembler group.
- * @param group The assembler group to register with.
- */
- static void registerWith(AssemblerGroup group)
- {
- if ( group == null )
- group = Assembler.general ;
- group.implementWith( SECURED_MODEL, new SecuredAssembler()) ;
- group.implementWith( EVALUATOR_ASSEMBLER, new SecurityEvaluatorAssembler());
- }
-
- @Override
- public Model open(Assembler a, Resource root, Mode mode) {
-
- Resource rootModel = getUniqueResource( root, BASE_MODEL );
- if (rootModel == null)
- {
- throw new AssemblerException( root, String.format( NO_X_PROVIDED, BASE_MODEL, root ));
- }
- Model baseModel = a.openModel(rootModel, Mode.ANY);
-
- Literal modelName = getUniqueLiteral( root, JA.modelName );
- if (modelName == null)
- {
- throw new AssemblerException( root, String.format( NO_X_PROVIDED, JA.modelName, root ));
- }
-
- Literal factoryName = getUniqueLiteral( root, EVALUATOR_FACTORY );
- Resource evaluatorImpl = getUniqueResource( root, EVALUATOR_IMPL );
- if (factoryName == null && evaluatorImpl == null)
- {
- throw new AssemblerException( root,
- String.format( "Either a %s or a %s must be provided for %s" ,
- EVALUATOR_FACTORY, EVALUATOR_IMPL, root ));
- }
- if (factoryName != null && evaluatorImpl != null)
- {
- throw new AssemblerException( root,
- String.format( "May not specify both a %s and a %s for %s" ,
- EVALUATOR_FACTORY, EVALUATOR_IMPL, root ));
- }
- SecurityEvaluator securityEvaluator = null;
- if (factoryName != null)
- {
- securityEvaluator = executeEvaluatorFactory( root, factoryName );
- }
- if (evaluatorImpl != null)
- {
- securityEvaluator = getEvaluatorImpl( a, evaluatorImpl );
- }
- return Factory.getInstance(securityEvaluator, modelName.asLiteral().getString(), baseModel);
-
- }
-
- @Override
- protected Model openEmptyModel(Assembler a, Resource root, Mode mode) {
- return open(a, root, mode);
- }
-
- private SecurityEvaluator executeEvaluatorFactory(Resource root, Literal factoryName ) {
- try
- {
- Class<?> factoryClass = Class.forName( factoryName.getString() );
- Method method = factoryClass.getMethod("getInstance" );
- if ( ! SecurityEvaluator.class.isAssignableFrom(method.getReturnType()))
- {
- throw new AssemblerException( root, String.format( "%s (found at %s for %s) getInstance() must return an instance of SecurityEvaluator", factoryName, EVALUATOR_FACTORY, root ));
- }
- if ( ! Modifier.isStatic( method.getModifiers()))
- {
- throw new AssemblerException( root, String.format( "%s (found at %s for %s) getInstance() must be a static method", factoryName, EVALUATOR_FACTORY, root ));
- }
- return (SecurityEvaluator) method.invoke( null );
- }
- catch (SecurityException e)
- {
- throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e);
- }
- catch (IllegalArgumentException e)
- {
- throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e);
- }
- catch (ClassNotFoundException e)
- {
- throw new AssemblerException( root, String.format( "Class %s (found at %s for %s) could not be loaded", factoryName, EVALUATOR_FACTORY, root ));
- }
- catch (NoSuchMethodException e)
- {
- throw new AssemblerException( root, String.format( "%s (found at %s for %s) must implement a static getInstance() that returns an instance of SecurityEvaluator", factoryName, EVALUATOR_FACTORY, root ));
- }
- catch (IllegalAccessException e)
- {
- throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e);
- }
- catch (InvocationTargetException e)
- {
- throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e);
- }
- }
-
- private SecurityEvaluator getEvaluatorImpl(Assembler a, Resource evaluatorImpl ) {
- Object obj = a.open(a, evaluatorImpl, Mode.ANY);
- if (obj instanceof SecurityEvaluator)
- {
- return (SecurityEvaluator) obj;
- }
- throw new AssemblerException( evaluatorImpl, String.format(
- "%s does not specify a SecurityEvaluator instance", evaluatorImpl));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/SecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/SecurityEvaluator.java b/jena-security/src/main/java/org/apache/jena/security/SecurityEvaluator.java
deleted file mode 100644
index c700090..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/SecurityEvaluator.java
+++ /dev/null
@@ -1,616 +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.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
-/**
- * SecurityEvaluator.
- * <p>
- * The security evaluator is the link between the graph security system and an
- * external security system. This interface specifies the methods that are
- * required by the graph security system. It is assumed that the implementation
- * will handle tracking the current user and will query some underlying data
- * source to determine what actions the user can and can not take.
- * </p>
- * <p>
- * All questions of white listing or black listing will be handled in the
- * concrete implementation.
- * </p>
- * <p>
- * Implementations of this class should probably cache any evaluate calculations
- * as the evaluate methods are called frequently. However, the underlying
- * classes do cache results within a single method check.
- * </p>
- * <p>
- * <dl>
- * <dt>Secured operations</dt>
- * <dd>The security system recognizes and secures each of the CRUD (Create,
- * Read, Update and Delete) operations as represented by the Action enumeration.
- * </dd>
- * </dl>
- * <dl>
- * <dt>Levels of security</dt>
- * <dd>The security interfaces operates at two (2) levels: graph (or Model) and
- * triple.
- * <p>
- * At the the graph level the security evaluator may restrict CRUD access to the
- * graph or model as a whole. When evaluating the restriction, if the user it
- * not permitted to perform the operation on the graph or model access is
- * denied. If the user is permitted any triple restrictions are evaluated.
- * </p>
- * <p>
- * At the triple level the security evaluator may restrict CRUD access to
- * specific triples. In order to skip potentially expensive triple security
- * checks the system will generally ask if the user is permitted the CRUD action
- * on any triple. This is represented by the SecTriple
- * <code>(ANY, ANY, ANY)</code>.
- * <ul>
- * <li>
- * If the system does not support triple level security the system should always
- * return <code>true</code>.</li>
- * If the system does support triple level security and is unable to verify that
- * the user can execute the CRUD action against any arbitrary triple the system
- * should return <code>false</code>. </li>
- * <li>See <code>SecNode.ANY</code>, <code>SecNode.FUTURE</code>, and
- * <code>SecNode.VARIABLE</code> for discussion of specifics of their respective
- * usages.</li>
- * </ul>
- * </p>
- * </dd>
- * </dl>
- * <dl>
- * <dt>
- *
- * </p>
- */
-public interface SecurityEvaluator {
- /**
- * Identifies a sepcific CRUD actions.
- */
- static enum Action {
- /**
- * Allow creation of the object in question.
- */
- Create,
- /**
- * Allow the user to read the object in question.
- */
- Read,
- /**
- * Allow the user to update the object in question
- */
- Update,
- /**
- * Allow the user to delete the object in question.
- */
- Delete
-
- }
-
- /**
- * A node in the evaluation.
- * <p>
- * A node with no value represents a node of that type but unknown
- * exactitude. (e.g. <code>SecNode(URI,"")</code> is a URI but of unknown
- * value. Useful for systems that restrict type creation.
- * </p>
- * <p>
- * <code>SecNode(Anonymous,"")</code> represents an anonymous node that will
- * be created. Otherwise anonymous node values are the values within the
- * secured graph.
- * </p>
- * <p>
- * An "Any" node type matches any node.
- * </p>
- */
- public static class SecNode implements Comparable<SecNode> {
-
- /**
- * The types of nodes.
- */
- public static enum Type {
- /**
- * A URI type node
- */
- URI,
- /**
- * A Literal node.
- */
- Literal,
- /**
- * An anonymous node. Also called a "blank" node.
- */
- Anonymous,
- /**
- * Any node.
- */
- Any
- }
-
- /**
- * Matches any node in the security system.
- * <p>
- * Used in triple checks as follows:
- * <dl>
- * <dt><code>(ANY, ANY, ANY)</code></dt>
- * <dd>Asks if the user may perform the action on any triple.</dd>
- * <dt><code>(X, ANY, ANY)</code></dt>
- * <dd>Asks if the user may perform the action against any triple where
- * X is the subject.</dd>
- * <dt><code>(ANY, X, ANY)</code></dt>
- * <dd>Asks if the user may perform the action against any triple where
- * X is the predicate.</dd>
- * <dt><code>(SecNode.ANY, SecNode.ANY, SecNode.X)</code></dt>
- * <dd>Asks if if the user may perform the action against any triple
- * where X is the object.</dd>
- * </dl>
- * The <code>ANY</code> may occur multiple times and may occur with the
- * <code>VARIABLE</code> and/or <code>FUTURE</code> nodes.
- * </p>
- */
- public static final SecNode ANY = new SecNode(Type.Any, "any");
-
- /**
- * Indicates a variable in the triple.
- * <p>
- * </p>
- * This differs from <code>ANY</code> in that the system is asking if
- * there are any prohibitions not if the user may perform. Thus queries
- * with the VARIABLE type node should return <code>true</code> where
- * <code>ANY</code> returns <code>false</code>. In general this type is
- * used in the query to determine if triple level filtering of results
- * must be performed.
- * <p>
- * </p>
- * <p>
- * <dl>
- * <dt><code>(VARIABLE, X, Y )</code></dt>
- * <dd>
- * Asks if there are any prohibitions against the user seeing all
- * subjects that have property X and object Y.</dd>
- * <dt>
- * <code>(X, VARIABLE, Y )</code></dt>
- * <dd>
- * Asks if there are any prohibitions against the user seeing all
- * predicates that have subject X and object Y.</dd>
- * <dt>
- * <code>(X, Y, VARIABLE)</code></dt>
- * <dd>
- * Asks if there are any prohibitions against the user seeing all
- * objects that have subject X and predicate Y.</dd>
- * </dl>
- * The <code>VARIABLE</code> may occur multiple times and may occur with
- * the <code>ANY</code> node.
- * </p>
- *
- */
- public static final SecNode VARIABLE = new SecNode(Type.Any, "variable");
-
- /**
- * This is an anonymous node that will be created in the future.
- * <p>
- * FUTURE is used to check that an anonymous node may be created in as
- * specific position in a triple.
- * </p>
- * <p>
- * <dl>
- * <dt><code>(FUTURE, X, Y )</code></dt>
- * <dd>
- * Asks if there the user may create an anonymous node that has property
- * X and object Y.</dd>
- * <dt>
- * <code>(X, Y, FUTURE)</code></dt>
- * <dd>
- * Asks if there the user may create an anonymous node that has subject
- * X and property Y.</dd>
- * </dl>
- * The <code>FUTURE</code> may occur multiple times and may occur with
- * the <code>ANY</code> node.
- * </p>
- */
- public static final SecNode FUTURE = new SecNode(Type.Anonymous, "");
-
- private final Type type;
- private final String value;
- private Integer hashCode;
-
- /**
- * Create a SecNode of the type and value.
- *
- * @param type
- * The type of the node
- * @param value
- * The value of the node. A null is interpreted as an empty
- * string.
- */
- public SecNode(final Type type, final String value) {
- this.type = type;
- this.value = value == null ? "" : value;
- }
-
- @Override
- public int compareTo(final SecNode node) {
- final int retval = type.compareTo(node.type);
- return retval == 0 ? value.compareTo(node.value) : retval;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (o instanceof SecNode) {
- return this.compareTo((SecNode) o) == 0;
- }
- return false;
- }
-
- /**
- * Get the type of the node.
- *
- * @return The type of the node.
- */
- public Type getType() {
- return type;
- }
-
- /**
- * Get the value of the node.
- *
- * @return the value of the node
- */
- public String getValue() {
- return value;
- }
-
- @Override
- public int hashCode() {
- if (hashCode == null) {
- hashCode = new HashCodeBuilder().append(type).append(value)
- .toHashCode();
- }
- return hashCode;
- }
-
- @Override
- public String toString() {
- return String.format("[%s:%s]", getType(), getValue());
- }
- }
-
- /**
- * An immutable triple of SecNodes.
- */
- public static class SecTriple implements Comparable<SecTriple> {
- private final SecNode subject;
- private final SecNode predicate;
- private final SecNode object;
- private transient Integer hashCode;
-
- /**
- * The triple of <code>(ANY, ANY, ANY)</code>.
- */
- public static final SecTriple ANY = new SecTriple(SecNode.ANY,
- SecNode.ANY, SecNode.ANY);
-
- /**
- * Create the sec triple
- *
- * @param subject
- * The subject node.
- * @param predicate
- * The predicate node.
- * @param object
- * The object node.
- * @throws IllegalArgumentException
- * is any value is null.
- */
- public SecTriple(final SecNode subject, final SecNode predicate,
- final SecNode object) {
- if (subject == null) {
- throw new IllegalArgumentException("Subject may not be null");
- }
- if (predicate == null) {
- throw new IllegalArgumentException("Predicate may not be null");
- }
- if (object == null) {
- throw new IllegalArgumentException("Object may not be null");
- }
- this.subject = subject;
- this.predicate = predicate;
- this.object = object;
- }
-
- @Override
- public int compareTo(final SecTriple o) {
- if (o == null) {
- return 1;
- }
- int retval = subject.compareTo(o.subject);
- if (retval == 0) {
- retval = predicate.compareTo(o.predicate);
- }
- return retval == 0 ? object.compareTo(o.object) : retval;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (o instanceof SecTriple) {
- return this.compareTo((SecTriple) o) == 0;
- }
- return false;
- }
-
- /**
- * @return the object node.
- */
- public SecNode getObject() {
- return object;
- }
-
- /**
- * @return the predicate node.
- */
- public SecNode getPredicate() {
- return predicate;
- }
-
- /**
- * @return the subject node.
- */
- public SecNode getSubject() {
- return subject;
- }
-
- @Override
- public int hashCode() {
- if (hashCode == null) {
- hashCode = new HashCodeBuilder().append(object)
- .append(predicate).append(subject).toHashCode();
- }
- return hashCode;
- }
-
- @Override
- public String toString() {
- return String.format("( %s, %s, %s )", getSubject(),
- getPredicate(), getObject());
- }
- }
-
- /**
- * A collection of utility functions for the SecurityEvaluator
- * implementations.
- */
- public static class Util {
- /**
- * Return an array of actions as a set.
- * <p>
- * The order of the collection is preserved
- * </p>
- *
- * @param actions
- * The actions.
- * @return The set of actions.
- */
- public static Set<Action> asSet(final Action[] actions) {
- return Util.asSet(Arrays.asList(actions));
- }
-
- /**
- * Return a collection of actions as a set.
- * <p>
- * The order of the collection is preserved
- * </p>
- *
- * @param actions
- * The collection of actions.
- * @return The set of actions.
- */
- public static Set<Action> asSet(final Collection<Action> actions) {
- if (actions instanceof Set) {
- return (Set<Action>) actions;
- }
- else {
- return new LinkedHashSet<Action>(actions);
- }
- }
- }
-
- /**
- * Determine if the action is allowed on the graph.
- *
- * @param principal
- * The principal that is attempting the action.
- *
- * @param action
- * The action to perform
- * @param graphIRI
- * The IRI of the graph to check
- * @return true if the action is allowed, false otherwise.
- */
- public boolean evaluate(Object principal, Action action, SecNode graphIRI);
-
- /**
- * Determine if the action is allowed on the triple within the graph.
- * <p>
- * The evaluation should be performed in the following order:
- * <ol>
- * <li>
- * If the triple contains a <code>VARIABLE</code> then this method must
- * return <code>true</code> if there are any restrictions where the
- * remaining nodes are either constants or <code>ANY</code> nodes. This will
- * force the system to use subsequent checks to verify access by
- * substituting the value of the <code>VARIABLE</code>s.
- * <em>If the system can not quickly verify the solution
- * it is always acceptable to return <code>true</code>.</em>
- * <li>
- * Except as specified in the above check, if the triple contains an
- * <code>ANY</code> then this method must return <code>false</code> if there
- * are any restrictions where the remaining nodes are held constant and the
- * ANY node is allowed to vary. This checks is used to avoid subsequent
- * explicit triple checks.
- * <em>If the system can not quickly verify the solution it is always
- * acceptable to return <code>false</code>.</em></li>
- * <li>All other triples are explict triples and the system must determine
- * if the user is permitted to perform the action on the triple. If the
- * triple contains a <code>FUTURE</code> node that node should be considered
- * as an anonymous or blank node that is not yet created. It should only be
- * used with <code>Create</code> actions and is asking if the user may
- * create a blank node in that position in the triple.</li>
- * </ol>
- * </p>
- *
- * @param principal
- * The principal that is attempting the action.
- *
- * @param action
- * The action to perform
- * @param graphIRI
- * The IRI of the graph to the action is being taken upon. May be
- * <code>ANY</code>.
- * @param triple
- * The triple to check
- * @return true if the action is allowed, false otherwise.
- * @throws IllegalArgumentException
- * if any argument is null.
- */
- public boolean evaluate(Object principal, Action action, SecNode graphIRI,
- SecTriple triple);
-
- /**
- * Determine if all actions are allowed on the graph.
- *
- * @param principal
- * The principal that is attempting the action.
- *
- * @param actions
- * The set of actions to perform
- * @param graphIRI
- * The IRI of the graph to the action is being taken upon. May be
- * <code>ANY</code>.
- * @return true if all the actions are allowed, false otherwise.
- * @throws IllegalArgumentException
- * if any argument is null.
- */
- public boolean evaluate(Object principal, Set<Action> actions,
- SecNode graphIRI);
-
- /**
- * Determine if all the actions are allowed on the triple within the graph.
- * <p>
- * See evaluate( Action, SecNode, SecTriple ) for discussion of evaluation
- * strategy.
- * </p>
- *
- * @param actions
- * The actions to perform.
- * @param graphIRI
- * The IRI of the graph to the action is being taken upon. May be
- * <code>ANY</code>.
- * @param triple
- * The triple to check
- * @return true if all the actions are allowed, false otherwise.
- * @throws IllegalArgumentException
- * if any argument is null.
- */
- public boolean evaluate(Object principal, Set<Action> actions,
- SecNode graphIRI, SecTriple triple);
-
- /**
- * Determine if any of the actions are allowed on the graph.
- *
- * @param principal
- * The principal that is attempting the action.
- *
- * @param actions
- * The actions to perform
- * @param graphIRI
- * The IRI of the graph to the action is being taken upon. May be
- * <code>ANY</code>.
- * @return true true if any the actions are allowed, false otherwise.
- * @throws IllegalArgumentException
- * if any argument is null.
- */
- public boolean evaluateAny(Object principal, Set<Action> actions,
- SecNode graphIRI);
-
- /**
- * Determine if any of the actions are allowed on the triple within the
- * graph.
- * <p>
- * See evaluate( Action, SecNode, SecTriple ) for discussion of evaluation
- * strategy.
- * </p>
- *
- * @param principal
- * The principal that is attempting the action.
- *
- * @param actions
- * The actions to check.
- * @param graphIRI
- * The IRI of the graph to the action is being taken upon. May be
- * <code>ANY</code>.
- * @param triple
- * The triple to check
- * @return true if any the actions are allowed, false otherwise.
- * @throws IllegalArgumentException
- * if any argument is null.
- */
- public boolean evaluateAny(Object principal, Set<Action> actions,
- SecNode graphIRI, SecTriple triple);
-
- /**
- * Determine if the user is allowed to update the "from" triple to the "to"
- * triple.
- * <p>
- * Update is a special case since it modifies one triple to be another. So
- * the user must have permissions to change the "from" triple into the "to"
- * triple.
- *
- * @param principal
- * The principal that is attempting the action.
- * @param graphIRI
- * The IRI of the graph to the action is being taken upon. May be
- * <code>ANY</code>.
- * @param from
- * The triple to be changed
- * @param to
- * The value to change it to.
- * @return true if the user may make the change, false otherwise.
- * @throws IllegalArgumentException
- * if any argument is null.
- */
- public boolean evaluateUpdate(Object principal, SecNode graphIRI,
- SecTriple from, SecTriple to);
-
- /**
- * returns the current principal or null if there is no current principal.
- *
- * All security evaluation methods use this method to determine who the call
- * is being executed as. This allows subsystems (like the listener system)
- * to capture the current user and evaluate later calls in terms of that
- * user.
- *
- * @return The current principal
- */
- public Object getPrincipal();
-}
[10/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItemImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItemImpl.java b/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItemImpl.java
deleted file mode 100644
index e24cfb8..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItemImpl.java
+++ /dev/null
@@ -1,842 +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.impl;
-
-import java.lang.reflect.Proxy;
-
-import org.apache.commons.collections4.map.LRUMap;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.jena.rdf.model.Statement ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.SecurityEvaluator.SecTriple;
-import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.vocabulary.RDF ;
-
-/**
- * An abstract implementation of SecuredItem that caches security checks.
- * <p>
- * Security checks are performed at multiple locations. This implementation ensures that
- * during a single operation the specific check is only evaluated once by caching the result.
- * </p>
- *
- */
-public abstract class SecuredItemImpl implements SecuredItem
-{
- // a key for the secured item.
- private class CacheKey implements Comparable<CacheKey>
- {
- private final Action action;
- private final SecNode modelNode;
- private final SecTriple from;
- private final SecTriple to;
- private Integer hashCode;
-
- public CacheKey( final Action action, final SecNode modelNode )
- {
- this(action, modelNode, null, null);
- }
-
- public CacheKey( final Action action, final SecNode modelNode,
- final SecTriple to )
- {
- this(action, modelNode, to, null);
- }
-
- public CacheKey( final Action action, final SecNode modelNode,
- final SecTriple to, final SecTriple from )
- {
- this.action = action;
- this.modelNode = modelNode;
- this.to = to;
- this.from = from;
- }
-
- @Override
- public int compareTo( final CacheKey other )
- {
- int retval = this.action.compareTo(other.action);
- if (retval == 0)
- {
- retval = this.modelNode.compareTo(other.modelNode);
- }
- if (retval == 0)
- {
- if (this.to == null)
- {
- if (other.to == null)
- {
- return 0;
- }
- return -1;
- }
- retval = this.to.compareTo(other.to);
- }
- if (retval == 0)
- {
- if (this.from == null)
- {
- if (other.from == null)
- {
- return 0;
- }
- return -1;
- }
- retval = this.from.compareTo(other.from);
- }
- return retval;
- }
-
- @Override
- public boolean equals( final Object o )
- {
- if (o instanceof CacheKey)
- {
- return this.compareTo((CacheKey) o) == 0;
- }
- return false;
- }
-
- @Override
- public int hashCode()
- {
- if (hashCode == null)
- {
- hashCode = new HashCodeBuilder().append(action)
- .append(modelNode).append(from).append(to).toHashCode();
- }
- return hashCode;
- }
- }
-
- // the maximum size of the cache
- public static int MAX_CACHE = 100;
- // the cache for this thread.
- public static final ThreadLocal<LRUMap> CACHE = new ThreadLocal<LRUMap>();
- // the number of times this thread has recursively called the constructor.
- public static final ThreadLocal<Integer> COUNT = new ThreadLocal<Integer>();
-
- /**
- * Convert a Jena Node object into a SecNode object.
- * @param jenaNode The Jena node to convert.
- * @return The SecNode that represents the jenaNode.
- */
- public static SecNode convert( final org.apache.jena.graph.Node jenaNode )
- {
- if (org.apache.jena.graph.Node.ANY.equals(jenaNode))
- {
- return SecNode.ANY;
- }
- if (jenaNode.isLiteral())
- {
- return new SecNode(Type.Literal, jenaNode.getLiteral().toString());
- }
- if (jenaNode.isBlank())
- {
- return new SecNode(Type.Anonymous, jenaNode.getBlankNodeLabel());
- }
- if (jenaNode.isVariable())
- {
- return SecNode.VARIABLE;
- }
- return new SecNode(Type.URI, jenaNode.getURI());
- }
-
- /**
- * Convert a Jena Triple into a SecTriple.
- * @param jenaTriple The Jena Triple to convert.
- * @return The SecTriple that represents the jenaTriple.
- */
- public static SecTriple convert(
- final org.apache.jena.graph.Triple jenaTriple )
- {
- return new SecTriple(SecuredItemImpl.convert(jenaTriple.getSubject()),
- SecuredItemImpl.convert(jenaTriple.getPredicate()),
- SecuredItemImpl.convert(jenaTriple.getObject()));
- }
-
- /**
- * Decrement the number of instances of SecuredItem.
- */
- public static void decrementUse()
- {
- final Integer i = SecuredItemImpl.COUNT.get();
- if (i == null)
- {
- throw new IllegalStateException("No count on exit");
- }
- if (i < 1)
- {
- throw new IllegalStateException("No count less than 1");
- }
- if (i == 1)
- {
- SecuredItemImpl.CACHE.remove();
- SecuredItemImpl.COUNT.remove();
- }
- else
- {
- SecuredItemImpl.COUNT.set( i - 1 );
- }
- }
-
- /**
- * Increment the number of instances of SecuredItem.
- */
- public static void incrementUse()
- {
- final Integer i = SecuredItemImpl.COUNT.get();
- if (i == null)
- {
- SecuredItemImpl.CACHE.set(new LRUMap(Math.max(
- SecuredItemImpl.MAX_CACHE, 100)));
- SecuredItemImpl.COUNT.set( 1 );
- }
- else
- {
- SecuredItemImpl.COUNT.set( i + 1 );
- }
- }
-
- // the evaluator we are using
- private final SecurityEvaluator securityEvaluator;
-
- // the secured node for that names the graph.
- private final SecNode modelNode;
-
- // the item holder that we are evaluating.
- private final ItemHolder<?, ?> itemHolder;
-
- /**
- * Create the SecuredItemImpl.
- * @param securedItem The securedItem.
- * @param holder The Item holder for the securedItem.
- * @throws IllegalArgumentException if securedItem is null or securedItem.getSecurityEvaluator()
- * returns null, or the holder is null.
- */
- protected SecuredItemImpl( final SecuredItem securedItem,
- final ItemHolder<?, ?> holder )
- {
- if (securedItem == null)
- {
- throw new IllegalArgumentException("Secured item may not be null");
- }
- if (securedItem.getSecurityEvaluator() == null)
- {
- throw new IllegalArgumentException(
- "Security evaluator in secured item may not be null");
- }
- if (holder == null)
- {
- throw new IllegalArgumentException("ItemHolder may not be null");
- }
- this.securityEvaluator = securedItem.getSecurityEvaluator();
- this.modelNode = new SecurityEvaluator.SecNode(
- SecurityEvaluator.SecNode.Type.URI, securedItem.getModelIRI());
- this.itemHolder = holder;
- }
-
- /**
- * Create the SecuredItemImpl.
- * @param securityEvaluator the secured evaluator to use.
- * @param modelURI the URI for the model.
- * @param holder The holder to use.
- * @throws IllegalArgumentException if security evaluator is null, modelURI is null or empty,
- * or holder is null.
- */
- protected SecuredItemImpl( final SecurityEvaluator securityEvaluator,
- final String modelURI, final ItemHolder<?, ?> holder )
- {
- if (securityEvaluator == null)
- {
- throw new IllegalArgumentException(
- "Security evaluator may not be null");
- }
- if (StringUtils.isEmpty(modelURI))
- {
- throw new IllegalArgumentException(
- "ModelURI may not be empty or null");
- }
- if (holder == null)
- {
- throw new IllegalArgumentException("ItemHolder may not be null");
- }
- this.securityEvaluator = securityEvaluator;
- this.modelNode = new SecurityEvaluator.SecNode(
- SecurityEvaluator.SecNode.Type.URI, modelURI);
- this.itemHolder = holder;
- }
-
- @Override
- public String toString() {
- if (canRead())
- {
- return itemHolder.getBaseItem().toString();
- }
- return super.toString();
- }
-
- /**
- * get the cached value.
- * @param key The key to look for.
- * @return the value of the security check or <code>null</code> if the value has not been cached.
- */
- private Boolean cacheGet( final CacheKey key )
- {
- final LRUMap cache = SecuredItemImpl.CACHE.get();
- return (cache == null) ? null : (Boolean) cache.get(key);
- }
-
- /**
- * set teh cache value.
- * @param key The key to set the value for.
- * @param value The value to set.
- */
- void cachePut( final CacheKey key, final boolean value )
- {
- final LRUMap cache = SecuredItemImpl.CACHE.get();
- if (cache != null)
- {
- cache.put(key, value);
- SecuredItemImpl.CACHE.set(cache);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jena.security.SecuredItem#canCreate()
- */
- @Override
- public boolean canCreate()
- {
- final CacheKey key = new CacheKey(Action.Create, modelNode);
- Boolean retval = cacheGet(key);
- if (retval == null)
- {
- retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Create, modelNode);
- cachePut(key, retval);
- }
- return retval;
- }
-
- public boolean canCreate( final org.apache.jena.graph.Triple t )
- {
- return canCreate(SecuredItemImpl.convert(t));
- }
-
- @Override
- public boolean canCreate( final SecTriple t )
- {
- final CacheKey key = new CacheKey(Action.Create, modelNode, t);
- Boolean retval = cacheGet(key);
- if (retval == null)
- {
- retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Create, modelNode, t);
- cachePut(key, retval);
- }
- return retval;
- }
-
- public boolean canCreate( final Statement s )
- {
- return canCreate(s.asTriple());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jena.security.SecuredItem#canDelete()
- */
- @Override
- public boolean canDelete()
- {
- final CacheKey key = new CacheKey(Action.Delete, modelNode);
- Boolean retval = cacheGet(key);
- if (retval == null)
- {
- retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Delete, modelNode);
- cachePut(key, retval);
- }
- return retval;
- }
-
- public boolean canDelete( final org.apache.jena.graph.Triple t )
- {
- return canDelete(SecuredItemImpl.convert(t));
- }
-
- @Override
- public boolean canDelete( final SecTriple t )
- {
- final CacheKey key = new CacheKey(Action.Delete, modelNode, t);
- Boolean retval = cacheGet(key);
- if (retval == null)
- {
- retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Delete, modelNode, t);
- cachePut(key, retval);
- }
- return retval;
- }
-
- public boolean canDelete( final Statement s )
- {
- return canDelete(s.asTriple());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jena.security.SecuredItem#canRead()
- */
- @Override
- public boolean canRead()
- {
- final CacheKey key = new CacheKey(Action.Read, modelNode);
- Boolean retval = cacheGet(key);
- if (retval == null)
- {
- retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Read, modelNode);
- cachePut(key, retval);
- }
- return retval;
- }
-
- public boolean canRead( final org.apache.jena.graph.Triple t )
- {
- return canRead(SecuredItemImpl.convert(t));
- }
-
- @Override
- public boolean canRead( final SecTriple t )
- {
- final CacheKey key = new CacheKey(Action.Read, modelNode, t);
- Boolean retval = cacheGet(key);
- if (retval == null)
- {
- retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Read, modelNode, t);
- cachePut(key, retval);
- }
- return retval;
- }
-
- public boolean canRead( final Statement s )
- {
- return canRead(s.asTriple());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jena.security.SecuredItem#canUpdate()
- */
- @Override
- public boolean canUpdate()
- {
- final CacheKey key = new CacheKey(Action.Update, modelNode);
- Boolean retval = cacheGet(key);
- if (retval == null)
- {
- retval = securityEvaluator.evaluate(securityEvaluator.getPrincipal(),Action.Update, modelNode);
- cachePut(key, retval);
- }
- return retval;
- }
-
- public boolean canUpdate( final org.apache.jena.graph.Triple from,
- final org.apache.jena.graph.Triple to )
- {
- return canUpdate(SecuredItemImpl.convert(from),
- SecuredItemImpl.convert(to));
- }
-
- @Override
- public boolean canUpdate( final SecTriple from, final SecTriple to )
- {
- final CacheKey key = new CacheKey(Action.Update, modelNode, from, to);
- Boolean retval = cacheGet(key);
- if (retval == null)
- {
- retval = securityEvaluator.evaluateUpdate(securityEvaluator.getPrincipal(),modelNode, from, to);
- cachePut(key, retval);
- }
- return retval;
- }
-
- public boolean canUpdate( final Statement from, final Statement to )
- {
- return canUpdate(from.asTriple(), to.asTriple());
- }
-
- /**
- * check that create on the securedModel is allowed,
- *
- * @throws AccessDeniedException
- * on failure
- */
- protected void checkCreate()
- {
- if (!canCreate())
- {
- throw new AccessDeniedException(modelNode, Action.Create);
- }
- }
-
- protected void checkCreate( final org.apache.jena.graph.Triple t )
- {
- checkCreate(SecuredItemImpl.convert(t));
- }
-
- /**
- * check that the triple can be created in the securedModel.,
- *
- * @throws AccessDeniedException
- * on failure
- */
- protected void checkCreate( final SecTriple t )
- {
- if (!canCreate(t))
- {
- throw new AccessDeniedException(modelNode, t.toString(),
- Action.Create);
- }
- }
-
- protected void checkCreate( final Statement s )
- {
- checkCreate(s.asTriple());
- }
-
- protected void checkCreateReified( final String uri, final SecTriple t )
- {
- checkUpdate();
- final SecNode n = uri == null ? SecNode.FUTURE : new SecNode(Type.URI,
- uri);
- checkCreate(new SecTriple(n, SecuredItemImpl.convert(RDF.subject
- .asNode()), t.getSubject()));
- checkCreate(new SecTriple(n, SecuredItemImpl.convert(RDF.predicate
- .asNode()), t.getPredicate()));
- checkCreate(new SecTriple(n, SecuredItemImpl.convert(RDF.object
- .asNode()), t.getObject()));
- }
-
- protected void checkCreateStatement( final ExtendedIterator<Statement> stmts )
- {
- if (!canCreate(SecTriple.ANY))
- {
- try
- {
- while (stmts.hasNext())
- {
- checkCreate(stmts.next());
- }
- }
- finally
- {
- stmts.close();
- }
- }
- }
-
- protected void checkCreateTriples(
- final ExtendedIterator<org.apache.jena.graph.Triple> triples )
- {
- if (!canCreate(SecTriple.ANY))
- {
- try
- {
- while (triples.hasNext())
- {
- checkCreate(triples.next());
- }
- }
- finally
- {
- triples.close();
- }
- }
- }
-
- /**
- * check that delete on the securedModel is allowed,
- *
- * @throws AccessDeniedException
- * on failure
- */
- protected void checkDelete()
- {
- if (!canDelete())
- {
- throw new AccessDeniedException(modelNode, Action.Delete);
- }
- }
-
- protected void checkDelete( final org.apache.jena.graph.Triple t )
- {
- checkDelete(SecuredItemImpl.convert(t));
- }
-
- /**
- * check that the triple can be deleted in the securedModel.,
- *
- * @throws AccessDeniedException
- * on failure
- */
- protected void checkDelete( final SecTriple t )
- {
- if (!canDelete(t))
- {
- throw new AccessDeniedException(modelNode, t.toString(),
- Action.Delete);
- }
- }
-
- protected void checkDelete( final Statement s )
- {
- checkDelete(s.asTriple());
- }
-
- protected void checkDeleteStatements(
- final ExtendedIterator<Statement> stmts )
- {
- if (!canDelete(SecTriple.ANY))
- {
- try
- {
- while (stmts.hasNext())
- {
- checkDelete(stmts.next());
- }
- }
- finally
- {
- stmts.close();
- }
- }
- }
-
- protected void checkDeleteTriples(
- final ExtendedIterator<org.apache.jena.graph.Triple> triples )
- {
- if (!canDelete(SecTriple.ANY))
- {
- try
- {
- while (triples.hasNext())
- {
- checkDelete(triples.next());
- }
- }
- finally
- {
- triples.close();
- }
- }
- }
-
- /**
- * check that read on the securedModel is allowed,
- *
- * @throws AccessDeniedException
- * on failure
- */
- protected void checkRead()
- {
- if (!canRead())
- {
- throw new AccessDeniedException(modelNode, Action.Read);
- }
- }
-
- protected void checkRead( final org.apache.jena.graph.Triple t )
- {
- checkRead(SecuredItemImpl.convert(t));
- }
-
- /**
- * check that the triple can be read in the securedModel.,
- *
- * @throws AccessDeniedException
- * on failure
- */
- protected void checkRead( final SecTriple t )
- {
- if (!canRead(t))
- {
- throw new AccessDeniedException(modelNode, t.toString(),
- Action.Read);
- }
- }
-
- protected void checkRead( final Statement s )
- {
- checkRead(s.asTriple());
- }
-
- protected void checkReadStatement( final ExtendedIterator<Statement> stmts )
- {
- try
- {
- while (stmts.hasNext())
- {
- checkRead(stmts.next());
- }
- }
- finally
- {
- stmts.close();
- }
- }
-
- protected void checkReadTriples(
- final ExtendedIterator<org.apache.jena.graph.Triple> triples )
- {
- try
- {
- while (triples.hasNext())
- {
- checkRead(triples.next());
- }
- }
- finally
- {
- triples.close();
- }
- }
-
- /**
- * check that update on the securedModel is allowed,
- *
- * @throws AccessDeniedException
- * on failure
- */
- protected void checkUpdate()
- {
- if (!canUpdate())
- {
- throw new AccessDeniedException(modelNode, Action.Update);
- }
- }
-
- protected void checkUpdate( final org.apache.jena.graph.Triple from,
- final org.apache.jena.graph.Triple to )
- {
- checkUpdate(SecuredItemImpl.convert(from), SecuredItemImpl.convert(to));
- }
-
- /**
- * check that the triple can be updated in the securedModel.,
- *
- * @param from the starting triple
- * @param to the final triple.
- * @throws AccessDeniedException
- * on failure
- */
- protected void checkUpdate( final SecTriple from, final SecTriple to )
- {
- if (!canUpdate(from, to))
- {
- throw new AccessDeniedException(modelNode, String.format(
- "%s to %s", from, to), Action.Update);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jena.security.SecuredItem#equals(java.lang.Object)
- */
- @Override
- public boolean equals( final Object o )
- {
- if (Proxy.isProxyClass(o.getClass()))
- {
- return o.equals(itemHolder.getSecuredItem());
- }
- else
- {
- if (o instanceof SecuredItemImpl)
- {
- return itemHolder.getBaseItem().equals( ((SecuredItemImpl)o).getBaseItem());
- }
- return false;
- }
- }
-
- @Override
- public int hashCode()
- {
- return itemHolder.getBaseItem().hashCode();
- }
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jena.security.SecuredItem#getBaseItem()
- */
- @Override
- public Object getBaseItem()
- {
- return itemHolder.getBaseItem();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jena.security.SecuredItem#getModelIRI()
- */
- @Override
- public String getModelIRI()
- {
- return modelNode.getValue();
- }
-
- /**
- * get the name of the model.
- */
- @Override
- public SecNode getModelNode()
- {
- return modelNode;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jena.security.SecuredItem#getSecurityEvaluator()
- */
- @Override
- public SecurityEvaluator getSecurityEvaluator()
- {
- return securityEvaluator;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jena.security.isEquivalent()
- */
- @Override
- public boolean isEquivalent( final SecuredItem securedItem )
- {
- return SecuredItem.Util.isEquivalent(this, securedItem);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItemInvoker.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItemInvoker.java b/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItemInvoker.java
deleted file mode 100644
index 9e9149d..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/impl/SecuredItemInvoker.java
+++ /dev/null
@@ -1,146 +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.impl;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Proxy;
-
-
-/**
- * A generic InvocationHandler that handles the general invocation of the
- * security methods.
- */
-public class SecuredItemInvoker implements InvocationHandler
-{
- // the equals() method
- private static Method EQUALS;
- // the toString() method
- private static Method TO_STRING;
- // the hashCode() method.
- private static Method HASH_CODE;
- // the instance of SecuredItem that this proxy is using. Must be
- // package-private for ItemHolder use.
- /* package-private */final SecuredItem securedItem;
-
- final Class<?> securedClass;
-
- // populate the static fields.
- static
- {
- try
- {
- SecuredItemInvoker.EQUALS = Object.class.getMethod("equals",
- Object.class);
- SecuredItemInvoker.TO_STRING = Object.class.getMethod("toString");
- SecuredItemInvoker.HASH_CODE = Object.class.getMethod("hashCode");
- }
- catch (final SecurityException e)
- {
- throw new RuntimeException(e);
- }
- catch (final NoSuchMethodException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Constructor.
- *
- * @param securedClass
- * The class of the object that is being protected.
- * @param securedItem
- * The implementation of the SecuredItem version of the object.
- */
- public SecuredItemInvoker( final Class<?> securedClass,
- final SecuredItem securedItem )
- {
- this.securedItem = securedItem;
- this.securedClass = securedClass;
- }
-
- @Override
- public Object invoke( final Object proxy, final Method method,
- final Object[] args ) throws Throwable
- {
-
- // check for the special case methods
- if (SecuredItemInvoker.EQUALS.equals(method))
- {
- if (Proxy.isProxyClass(args[0].getClass()))
- {
- return args[0].equals(securedItem);
- }
- else
- {
- return securedItem.equals(args[0]);
- }
- }
-
- if (SecuredItemInvoker.HASH_CODE.equals(method))
- {
- return securedItem.hashCode();
- }
-
- if (SecuredItemInvoker.TO_STRING.equals(method))
- {
- return securedItem.toString();
- }
-
- try
- {
- final Method m = securedItem.getClass().getMethod(method.getName(),
- method.getParameterTypes());
- if (!Modifier.isAbstract(m.getModifiers()))
- {
- try
- {
- SecuredItemImpl.incrementUse();
- try
- {
- return m.invoke(securedItem, args);
- }
- finally
- {
- SecuredItemImpl.decrementUse();
- }
-
- }
- catch (final java.lang.reflect.InvocationTargetException e2)
- {
- if (e2.getTargetException() instanceof RuntimeException)
- {
- throw e2.getTargetException();
- }
- throw e2;
- }
- }
- }
- catch (final NoSuchMethodException e2)
- {
- // acceptable
- }
-
- // if we get here then the method is not being proxied so call the
- // original method on the base item.
- return method.invoke(securedItem.getBaseItem(), args);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredAlt.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredAlt.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredAlt.java
deleted file mode 100644
index 6b4dea4..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredAlt.java
+++ /dev/null
@@ -1,264 +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.model;
-
-import org.apache.jena.rdf.model.Alt ;
-import org.apache.jena.rdf.model.RDFNode ;
-import org.apache.jena.rdf.model.ResourceF ;
-import org.apache.jena.security.AccessDeniedException;
-
-/**
- * The interface for secured Alt instances.
- *
- * Use the SecuredAlt.Factory to create instances
- */
-@SuppressWarnings("deprecation")
-public interface SecuredAlt extends Alt, SecuredContainer
-{
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredRDFNode getDefault() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt getDefaultAlt() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredBag getDefaultBag() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public boolean getDefaultBoolean() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public byte getDefaultByte() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public char getDefaultChar() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public double getDefaultDouble() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public float getDefaultFloat() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public int getDefaultInt() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public String getDefaultLanguage() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredLiteral getDefaultLiteral() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public long getDefaultLong() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource getDefaultResource() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public SecuredResource getDefaultResource( final ResourceF f )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredSeq getDefaultSeq() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public short getDefaultShort() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
- */
- @Override
- public String getDefaultString() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
- * RDF.li(1), o )
- * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt setDefault( final boolean o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
- * RDF.li(1), o )
- * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt setDefault( final char o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
- * RDF.li(1), o )
- * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt setDefault( final double o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
- * RDF.li(1), o )
- * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt setDefault( final float o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
- * RDF.li(1), o )
- * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt setDefault( final long o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
- * RDF.li(1), o )
- * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt setDefault( final Object o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
- * RDF.li(1), o )
- * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt setDefault( final RDFNode o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
- * RDF.li(1), o )
- * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt setDefault( final String o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Update SecTriple(this, RDF.li(1), existing ), SecTriple(this,
- * RDF.li(1), o )
- * @sec.triple Create SecTriple(this, RDF.li(1), o ) if no current default
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt setDefault( final String o, final String l )
- throws AccessDeniedException;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredBag.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredBag.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredBag.java
deleted file mode 100644
index 62d63fa..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredBag.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.model;
-
-import org.apache.jena.rdf.model.Bag ;
-
-/**
- * The interface for secured Bag instances.
- *
- * Use the SecuredBag.Factory to create instances
- */
-public interface SecuredBag extends Bag, SecuredContainer
-{
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredContainer.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredContainer.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredContainer.java
deleted file mode 100644
index eff2858..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredContainer.java
+++ /dev/null
@@ -1,218 +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.model;
-
-import java.util.Set;
-
-import org.apache.jena.rdf.model.Container ;
-import org.apache.jena.rdf.model.RDFNode ;
-import org.apache.jena.rdf.model.Statement ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.impl.SecuredNodeIterator;
-
-/**
- * The interface for secured Container instances.
- *
- * Use one of the SecuredContainer derived class Factory methods to create
- * instances
- */
-public interface SecuredContainer extends Container, SecuredResource
-{
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer add( final boolean o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer add( final char o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer add( final double o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer add( final float o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer add( final long o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer add( final Object o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer add( final RDFNode o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer add( final String o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer add( final String o, final String l )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final boolean o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final char o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final double o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final float o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final long o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final Object o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final RDFNode o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final String o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final String o, final String l )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read on each triple ( this, rdf:li_? node ) returned by
- * iterator;
- * @throws AccessDeniedException
- */
- @Override
- public SecuredNodeIterator<RDFNode> iterator() throws AccessDeniedException;
-
- /**
- * @param perms the Permissions required on each node returned
- * @sec.graph Read
- * @sec.triple Read + perms on each triple ( this, rdf:li_? node ) returned
- * by iterator;
- * @throws AccessDeniedException
- */
- public SecuredNodeIterator<RDFNode> iterator( Set<Action> perms )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Delete s as triple;
- * @throws AccessDeniedException
- */
- @Override
- public SecuredContainer remove( final Statement s )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public int size() throws AccessDeniedException;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredLiteral.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredLiteral.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredLiteral.java
deleted file mode 100644
index bb34453..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredLiteral.java
+++ /dev/null
@@ -1,165 +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.model;
-
-import org.apache.jena.datatypes.DatatypeFormatException ;
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.security.AccessDeniedException;
-
-/**
- * The interface for secured Literal instances.
- *
- * Use the SecuredLiteral.Factory to create instances
- */
-public interface SecuredLiteral extends Literal, SecuredRDFNode
-{
-
- @Override
- public SecuredLiteral asLiteral();
-
- // @Override
- // public SecuredResource asResource();
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean getBoolean() throws AccessDeniedException,
- DatatypeFormatException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public byte getByte() throws AccessDeniedException, DatatypeFormatException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public char getChar() throws AccessDeniedException, DatatypeFormatException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public RDFDatatype getDatatype() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getDatatypeURI() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public double getDouble() throws AccessDeniedException,
- DatatypeFormatException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public float getFloat() throws AccessDeniedException,
- DatatypeFormatException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public int getInt() throws AccessDeniedException, DatatypeFormatException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getLanguage() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getLexicalForm() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public long getLong() throws AccessDeniedException, DatatypeFormatException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public short getShort() throws AccessDeniedException,
- DatatypeFormatException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String getString() throws AccessDeniedException,
- DatatypeFormatException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public Object getValue() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public Literal inModel( final Model m ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean isWellFormedXML() throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean sameValueAs( final Literal other )
- throws AccessDeniedException;
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/SecuredModel.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/SecuredModel.java b/jena-security/src/main/java/org/apache/jena/security/model/SecuredModel.java
deleted file mode 100644
index 4b59115..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/SecuredModel.java
+++ /dev/null
@@ -1,1566 +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.model;
-
-import java.io.InputStream ;
-import java.io.OutputStream ;
-import java.io.Reader ;
-import java.io.Writer ;
-import java.util.Calendar ;
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.AccessDeniedException ;
-import org.apache.jena.security.graph.SecuredGraph ;
-import org.apache.jena.security.graph.SecuredPrefixMapping ;
-import org.apache.jena.security.model.impl.SecuredNodeIterator ;
-import org.apache.jena.security.model.impl.SecuredRSIterator ;
-import org.apache.jena.security.model.impl.SecuredResIterator ;
-import org.apache.jena.security.model.impl.SecuredStatementIterator ;
-import org.apache.jena.shared.PropertyNotFoundException ;
-
-/**
- * The interface for secured Model instances.
- *
- * Use the SecuredModel.Factory to create instances
- */
-public interface SecuredModel extends Model, SecuredPrefixMapping
-{
-
- @Override
- public SecuredModel abort();
-
- /**
- * @sec.graph Update
- * @sec.triple Create for each statement as a triple.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final List<Statement> statements )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create for each statement in the securedModel as a triple.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final Model m ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create the triple SecTriple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final Resource s, final Property p, final RDFNode o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create the triple SecTriple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final Resource s, final Property p, final String o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create the triple SecTriple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final Resource s, final Property p,
- final String o, final boolean wellFormed )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create the triple SecTriple(s,p,literal(lex,datatype))
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final Resource s, final Property p,
- final String lex, final RDFDatatype datatype )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create the triple SecTriple(s,p,literal(o,l,false))
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final Resource s, final Property p,
- final String o, final String l ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create the statement as a triple
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final Statement s ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create all the statements as triples.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final Statement[] statements )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create all the statements as triples.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel add( final StmtIterator iter )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create triple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final boolean o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create triple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final char o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create triple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final double o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create triple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final float o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create triple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final int o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create triple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final Literal o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create triple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final long o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create triple(s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- @Deprecated
- public SecuredModel addLiteral( final Resource s, final Property p,
- final Object o ) throws AccessDeniedException;
-
- @Override
- public SecuredRDFNode asRDFNode( final Node n );
-
- @Override
- /**
- * @sec.graph Read if t does exist
- * @sec.graph Update it t does not exist
- * @sec.triple Read if t does exist
- * @sec.triple Create if t does exist
- * @throws AccessDeniedException
- */
- public SecuredStatement asStatement( final Triple t )
- throws AccessDeniedException;
-
- @Override
- public SecuredModel begin();
-
- @Override
- public SecuredModel commit();
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, SecNode.ANY )
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final Resource s, final Property p )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final Resource s, final Property p, final RDFNode o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final Resource s, final Property p, final String o )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, literal(o,l,null) )
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final Resource s, final Property p,
- final String o, final String l ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read s as a triple with null replaced by SecNode.ANY
- * @throws AccessDeniedException
- */
- @Override
- public boolean contains( final Statement s ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read every statement in securedModel.
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsAll( final Model model )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read every statement
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsAll( final StmtIterator iter )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read any statement in securedModel to be included in check, if
- * no
- * statement in securedModel can be read will return false;
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsAny( final Model model )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read any statement in iter to be included in check, if no
- * statement in iter can be read will return false;
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsAny( final StmtIterator iter )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, literal(o) )
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final boolean o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, literal(o) )
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final char o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, literal(o) )
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final double o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, literal(o) )
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final float o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, literal(o) )
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final int o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, literal(o) )
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final long o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, typedLiteral(o) )
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final Object o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( s, p, resource) where SecTriple(s,p,resource) is in the
- * securedModel.
- * @throws AccessDeniedException
- */
- @Override
- public boolean containsResource( final RDFNode r )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( SecNode.ANY, RDF.type, Rdf.Alt)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt createAlt() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( uri, RDF.type, Rdf.Alt)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt createAlt( final String uri )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( SecNode.ANY, RDF.type, Rdf.Bag)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredBag createBag() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( uri, RDF.type, Rdf.Bag)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredBag createBag( final String uri )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredRDFList createList() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( RDF.nil, SecNode.IGNORE, SecNode.IGNORE)
- * @sec.triple Create for each member SecTriple(SecNode.ANY,
- * RDF.first.asNode(),
- * member.asNode())
- * @sec.triple Create SecTriple(SecNode.ANY, RDF.rest.asNode(), SecNode.ANY)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredRDFList createList( final Iterator<? extends RDFNode> members )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( RDF.nil, SecNode.IGNORE, SecNode.IGNORE)
- * @sec.triple Create for each member SecTriple(SecNode.ANY,
- * RDF.first.asNode(),
- * member.asNode())
- * @sec.triple Create SecTriple(SecNode.ANY, RDF.rest.asNode(), SecNode.ANY)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredRDFList createList( final RDFNode[] members )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s,p,o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final boolean o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s,p,o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final char o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s,p,o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final double o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s,p,o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final float o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s,p,o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final int o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s,p,o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final long o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s,p,o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final Object o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s,p,o )
- * @throws AccessDeniedException
- */
- @Override
- public Property createProperty( final String uri )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s,p,o )
- * @throws AccessDeniedException
- */
- @Override
- public Property createProperty( final String nameSpace,
- final String localName ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Read s as a triple
- * @sec.triple create SecTriple( SecNode.Future, RDF.subject, t.getSubject()
- * )
- * @sec.triple create SecTriple( SecNode.Future, RDF.subject,
- * t.getPredicate() )
- * @sec.triple create SecTriple( SecNode.Future, RDF.subject, t.getObject() )
- * @throws AccessDeniedException
- */
- @Override
- public ReifiedStatement createReifiedStatement( final Statement s )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Read s as a triple
- * @sec.triple create SecTriple( uri, RDF.subject, t.getSubject() )
- * @sec.triple create SecTriple( uri, RDF.subject, t.getPredicate() )
- * @sec.triple create SecTriple( uri, RDF.subject, t.getObject() )
- * @throws AccessDeniedException
- */
- @Override
- public ReifiedStatement createReifiedStatement( final String uri,
- final Statement s ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Read s as a triple
- * @sec.triple create SecTriple( SecNode.FUTURE, SecNode.IGNORE,
- * SecNode.IGNORE )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource createResource() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Read s as a triple
- * @sec.triple create SecTriple( Anonymous(id), SecNode.IGNORE,
- * SecNode.IGNORE )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource createResource( final AnonId id )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.type, type )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource createResource( final Resource type )
- throws AccessDeniedException;
-
- @Override
- @Deprecated
- public SecuredResource createResource( final ResourceF f );
-
- @Override
- public SecuredResource createResource( final String uri );
-
- /**
- * @sec.graph Update if uri exists
- * @sec.graph Create if uri does not exist
- * @sec.triple Read if SecTriple( uri, RDF.type, type ) exists
- * @sec.triple Create if SecTriple( uri, RDF.type, type ) does not exist
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource createResource( final String uri, final Resource type )
- throws AccessDeniedException;
-
- @Override
- @Deprecated
- public SecuredResource createResource( final String uri, final ResourceF f );
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.type, RDF.Alt )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredSeq createSeq() throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( uri, RDF.type, RDF.Alt )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredSeq createSeq( final String uri )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final RDFNode o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final String o ) throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final String o, final boolean wellFormed )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s, p, literal(o,l,false ))
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final String o, final String l )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Update
- * @sec.triple Create SecTriple( s, p, literal(o,l,wellFormed )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final String o, final String l,
- final boolean wellFormed ) throws AccessDeniedException;
-
- @Override
- public SecuredLiteral createTypedLiteral( final boolean v );
-
- @Override
- public Literal createTypedLiteral( final Calendar d );
-
- @Override
- public SecuredLiteral createTypedLiteral( final char v );
-
- @Override
- public SecuredLiteral createTypedLiteral( final double v );
-
- @Override
- public SecuredLiteral createTypedLiteral( final float v );
-
- @Override
- public SecuredLiteral createTypedLiteral( final int v );
-
- @Override
- public SecuredLiteral createTypedLiteral( final long v );
-
- @Override
- public SecuredLiteral createTypedLiteral( final Object value );
-
- @Override
- public SecuredLiteral createTypedLiteral( final Object value,
- final RDFDatatype dtype );
-
- @Override
- public SecuredLiteral createTypedLiteral( final Object value,
- final String typeURI );
-
- @Override
- public SecuredLiteral createTypedLiteral( final String v );
-
- @Override
- public SecuredLiteral createTypedLiteral( final String lex,
- final RDFDatatype dtype );
-
- @Override
- public SecuredLiteral createTypedLiteral( final String lex,
- final String typeURI );
-
- /**
- * @sec.graph Read
- * @sec.triple Read for every triple contributed to the difference.
- * @throws AccessDeniedException
- */
- @Override
- public Model difference( final Model model ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read if read lock is requested
- * @sec.graph Update if write lock is requested
- * @throws AccessDeniedException
- */
- @Override
- public void enterCriticalSection( final boolean readLockRequested )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String expandPrefix( final String prefixed )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( resource, RDF.type, RDF.alt )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt getAlt( final Resource r ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( uri, RDF.type, RDF.alt )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredAlt getAlt( final String uri ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read if statement exists
- * @sec.graph Update if statement does not exist
- * @sec.triple Read s as a triple
- * @sec.triple Read SecTriple( result, RDF.subject, s.getSubject() ) if
- * reification existed
- * @sec.triple Read SecTriple( result, RDF.predicate, s.getPredicate() ) if
- * reification existed
- * @sec.triple Read SecTriple( result, RDF.object, s.getObject() ) if
- * reification existed
- * @sec.triple Create SecTriple( result, RDF.subject, s.getSubject() ) if
- * reification did not exist.
- * @sec.triple Create SecTriple( result, RDF.redicate, s.getPredicate() ) if
- * reification did not exist
- * @sec.triple Create SecTriple( result, RDF.object, s.getObject() ) if
- * reification did not exist
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResource getAnyReifiedStatement( final Statement s )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( resource, RDF.type, RDF.Bag )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredBag getBag( final Resource r ) throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @sec.triple Read SecTriple( uri, RDF.type, RDF.Bag )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredBag getBag( final String uri ) throws AccessDeniedException;
-
- @Override
- public SecuredGraph getGraph();
-
- /**
- * @sec.graph Read
- * @sec.triple Read on the returned statement.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatement getProperty( final Resource s, final Property p )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public Property getProperty( final String uri )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public Property getProperty( final String nameSpace, final String localName )
- throws AccessDeniedException;
-
- /**
- * @sec.graph Read if the node exists
- * @sec.graph Update if the node does not exist
- * @throws AccessDeniedException
- */
- @Override
- public RDFNode getRDFNode( final Node n ) throws AccessDeniedException;
-
- /**
- * .
- * If the PropertyNotFoundException was thrown by the enclosed securedModel
- * and the
- * user can not read SecTriple(s, p, SecNode.ANY) AccessDeniedExcepiton is
- * thrown,
- * otherwise the PropertyNotFoundException will be thrown.
- *
- * @sec.graph Read
- * @sec.triple Read on the returned statement
- * @sec.triple Read on SecTriple(s, p, SecNode.ANY) if
- * PropertyNotFoundException
- * was thrown
- * @throws AccessDeniedException
- * @throws PropertyNotFoundException
- */
- @Override
- public SecuredStatement getRequiredProperty( final Resource s,
- final Property p ) throws PropertyNotFoundException,
- AccessDeniedException;
-
- @Override
- public SecuredResource getResource( final String uri );
-
- @Override
- @Deprecated
- public SecuredResource getResource( final String uri, final ResourceF f );
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on SecTriple(resource, RDF.type, RDF.Seq)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredSeq getSeq( final Resource r ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on SecTriple(uri, RDF.type, RDF.Seq)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredSeq getSeq( final String uri ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples contributed to the new securedModel.
- * @throws AccessDeniedException
- */
- @Override
- public Model intersection( final Model model ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public boolean isEmpty() throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read all compared triples. Triples that can not be read will
- * not be compared.
- * @throws AccessDeniedException
- */
- @Override
- public boolean isIsomorphicWith( final Model g )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on s as triple
- * @sec.triple Read on at least one set reified statements.
- * @throws AccessDeniedException
- */
- @Override
- public boolean isReified( final Statement s ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate,
- final boolean object ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned.
- * @throws AccessDeniedException
- */
-
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate, final char object )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned.
- * @throws AccessDeniedException
- */
-
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate,
- final double object ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned.
- * @throws AccessDeniedException
- */
-
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate, final float object )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned.
- * @throws AccessDeniedException
- */
-
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate, final long object )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public NsIterator listNameSpaces() throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on each RDFNode returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredNodeIterator<RDFNode> listObjects() throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on each RDFNode returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredNodeIterator<RDFNode> listObjectsOfProperty( final Property p )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on each RDFNode returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredNodeIterator<RDFNode> listObjectsOfProperty( final Resource s,
- final Property p ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on each Reified statement returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredRSIterator listReifiedStatements()
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on each Reified statement returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredRSIterator listReifiedStatements( final Statement st )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned;
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned;
- * @throws AccessDeniedException
- */
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final boolean o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned;
- * @throws AccessDeniedException
- */
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final char o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned;
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final double o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned;
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final float o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned;
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final long o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned;
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final Object o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final RDFNode o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatementIterator listStatements()
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatementIterator listStatements( final Resource s,
- final Property p, final RDFNode o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatementIterator listStatements( final Resource subject,
- final Property predicate, final String object )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatementIterator listStatements( final Resource subject,
- final Property predicate, final String object, final String lang )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all triples returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredStatementIterator listStatements( final Selector s )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listSubjects() throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listSubjectsWithProperty( final Property p )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listSubjectsWithProperty( final Property p,
- final RDFNode o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listSubjectsWithProperty( final Property p,
- final String o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read at least one SecTriple( resource, p, o ) for each
- * resource
- * returned
- * @throws AccessDeniedException
- */
- @Override
- public SecuredResIterator listSubjectsWithProperty( final Property p,
- final String o, final String l ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredPrefixMapping lock() throws AccessDeniedException;
-
- @Override
- public SecuredModel notifyEvent( final Object e );
-
- /**
- *
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String qnameFor( final String uri ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel query( final Selector s ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel read( final InputStream in, final String base )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel read( final InputStream in, final String base,
- final String lang ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel read( final Reader reader, final String base )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel read( final Reader reader, final String base,
- final String lang ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel read( final String url ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel read( final String url, final String lang )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel read( final String url, final String base,
- final String lang ) throws AccessDeniedException;
-
- /**
- *
- * Listener will be filtered to only report events that the user can see.
- *
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel register( final ModelChangedListener listener )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on every statement in statments.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel remove( final List<Statement> statements )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on every statement in baseModel.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel remove( final Model m ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on SecTriple( s, p, o )
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel remove( final Resource s, final Property p, final RDFNode o ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on statment.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel remove( final Statement s )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on every statement in statments.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel remove( final Statement[] statements )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on every statement in iter.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel remove( final StmtIterator iter )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on every statement in the securedModel
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel removeAll() throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on every statement identified by SecTriple( s,p,o)
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel removeAll( final Resource s, final Property p,
- final RDFNode r ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on every reification statement for each statement in
- * statments.
- * @throws AccessDeniedException
- */
- @Override
- public void removeAllReifications( final Statement s )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public SecuredPrefixMapping removeNsPrefix( final String prefix )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @sec.triple Delete on every reification statement fore each statement in
- * rs.
- * @throws AccessDeniedException
- */
- @Override
- public void removeReification( final ReifiedStatement rs )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public String setReaderClassName( final String lang, final String className )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Update
- * @throws AccessDeniedException
- */
- @Override
- public String setWriterClassName( final String lang, final String className )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public String shortForm( final String uri ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Override
- public long size() throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all statements contributed to the union.
- * @throws AccessDeniedException
- */
- @Override
- public Model union( final Model model ) throws AccessDeniedException;
-
- @Override
- public SecuredModel unregister( final ModelChangedListener listener );
-
- @Override
- public SecuredResource wrapAsResource( final Node n );
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all statements that are written.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel write( final OutputStream out )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all statements that are written.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel write( final OutputStream out, final String lang )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all statements that are written.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel write( final OutputStream out, final String lang,
- final String base ) throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all statements that are written.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel write( final Writer writer )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all statements that are written.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel write( final Writer writer, final String lang )
- throws AccessDeniedException;
-
- /**
- *
- * @sec.graph Read
- * @sec.triple Read on all statements that are written.
- * @throws AccessDeniedException
- */
- @Override
- public SecuredModel write( final Writer writer, final String lang,
- final String base ) throws AccessDeniedException;
-
-}
[05/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/ModelBasedSecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/ModelBasedSecurityEvaluator.java b/jena-security/src/test/java/org/apache/jena/security/ModelBasedSecurityEvaluator.java
deleted file mode 100644
index 0efc9be..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/SecuredAssemblerTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/SecuredAssemblerTest.java b/jena-security/src/test/java/org/apache/jena/security/SecuredAssemblerTest.java
deleted file mode 100644
index 697c5f6..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/SecurityEvaluatorParameters.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/SecurityEvaluatorParameters.java b/jena-security/src/test/java/org/apache/jena/security/SecurityEvaluatorParameters.java
deleted file mode 100644
index d6de485..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/StaticSecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/StaticSecurityEvaluator.java b/jena-security/src/test/java/org/apache/jena/security/StaticSecurityEvaluator.java
deleted file mode 100644
index d59b89c..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/contract/graph/CachedSecurityEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/contract/graph/CachedSecurityEvaluatorTest.java b/jena-security/src/test/java/org/apache/jena/security/contract/graph/CachedSecurityEvaluatorTest.java
deleted file mode 100644
index 6201b5c..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphContractTests.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphContractTests.java b/jena-security/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphContractTests.java
deleted file mode 100644
index e903d75..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphListenerTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphListenerTest.java b/jena-security/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphListenerTest.java
deleted file mode 100644
index fb7f805..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/contract/graph/SecuredTDBGraphContractTests.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/contract/graph/SecuredTDBGraphContractTests.java b/jena-security/src/test/java/org/apache/jena/security/contract/graph/SecuredTDBGraphContractTests.java
deleted file mode 100644
index 6991ea8..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/contract/model/ModelTestSuite.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/contract/model/ModelTestSuite.java b/jena-security/src/test/java/org/apache/jena/security/contract/model/ModelTestSuite.java
deleted file mode 100644
index e3d33e5..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestLiterals.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestLiterals.java b/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestLiterals.java
deleted file mode 100644
index 6247c68..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestPackage.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestPackage.java b/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestPackage.java
deleted file mode 100644
index 4f0650d..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestReaderEvents.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestReaderEvents.java b/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestReaderEvents.java
deleted file mode 100644
index 4a1d662..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestReaders.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestReaders.java b/jena-security/src/test/java/org/apache/jena/security/contract/model/SecTestReaders.java
deleted file mode 100644
index 7ee29fe..0000000
--- a/jena-security/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" );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java b/jena-security/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java
deleted file mode 100644
index 46f8b0b..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java
+++ /dev/null
@@ -1,372 +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.graph;
-
-import java.util.Arrays;
-import java.util.Set;
-
-import org.junit.Assert;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.graph.impl.CollectionGraph ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.Factory;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.graph.SecuredBulkUpdateHandler;
-import org.apache.jena.security.graph.SecuredGraph;
-import org.apache.jena.sparql.graph.GraphFactory ;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class BulkUpdateHandlerTest
-{
- protected SecuredBulkUpdateHandler handler;
- private final SecurityEvaluator securityEvaluator;
- private final Triple[] tripleArray;
- private final Set<Action> deleteAndUpdate;
- private final Set<Action> createAndUpdate;
-
- public BulkUpdateHandlerTest( final SecurityEvaluator securityEvaluator )
- {
- this.securityEvaluator = securityEvaluator;
-
- tripleArray = new Triple[] {
- new Triple(NodeFactory.createURI("http://example.com/1"),
- NodeFactory.createURI("http://example.com/v"),
- NodeFactory.createAnon()),
- new Triple(NodeFactory.createURI("http://example.com/2"),
- NodeFactory.createURI("http://example.com/v"),
- NodeFactory.createAnon()),
- new Triple(NodeFactory.createURI("http://example.com/3"),
- NodeFactory.createURI("http://example.com/v"),
- NodeFactory.createAnon()) };
- createAndUpdate = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
- deleteAndUpdate = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Update });
- }
-
- @Before
- public void setup()
- {
- final Graph g = GraphFactory.createDefaultGraph();
-
- final SecuredGraph sg = Factory.getInstance(securityEvaluator,
- "http://example.com/testGraph", g);
- handler = sg.getBulkUpdateHandler();
- }
-
- @Test
- public void testAdd()
- {
- Object principal = securityEvaluator.getPrincipal();
- try
- {
- handler.add(tripleArray);
- if (!securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- handler.add(Arrays.asList(tripleArray));
- if (!securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- handler.add(Arrays.asList(tripleArray).iterator());
- if (!securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- handler.add(new CollectionGraph(Arrays.asList(tripleArray)));
- if (!securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- handler.add(new CollectionGraph(Arrays.asList(tripleArray)));
- if (!securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- handler.add(new CollectionGraph(Arrays.asList(tripleArray)), true);
- if (!securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, createAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testDelete()
- {
- Object principal = securityEvaluator.getPrincipal();
- try
- {
- handler.delete(tripleArray);
- if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- handler.delete(Arrays.asList(tripleArray));
- if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- handler.delete(Arrays.asList(tripleArray).iterator());
- if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- handler.delete(new CollectionGraph(Arrays.asList(tripleArray)));
- if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- handler.delete(new CollectionGraph(Arrays.asList(tripleArray)),
- true);
- if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- public void testRemove()
- {
- Object principal = securityEvaluator.getPrincipal();
- try
- {
- handler.remove(NodeFactory.createURI("http://example.com/1"),
- NodeFactory.createURI("http://example.com/v"), NodeFactory.createAnon());
- if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- public void testRemoveAll()
- {
- Object principal = securityEvaluator.getPrincipal();
- try
- {
- handler.removeAll();
- if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, deleteAndUpdate,
- handler.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java b/jena-security/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java
deleted file mode 100644
index b8da8e4..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java
+++ /dev/null
@@ -1,77 +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.graph;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.GraphEventManager ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.security.Factory;
-import org.apache.jena.security.StaticSecurityEvaluator;
-import org.apache.jena.sparql.graph.GraphFactory ;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class CrossIDGraphEventManagerTest {
-
- private final GraphEventManager manager;
- private final Graph g;
- private final SecuredGraph sg;
- private final StaticSecurityEvaluator securityEvaluator;
-
- private final RecordingGraphListener annListener;
- private final RecordingGraphListener bobListener;
-
- public CrossIDGraphEventManagerTest() {
- this.securityEvaluator = new StaticSecurityEvaluator("ann");
-
- g = GraphFactory.createDefaultGraph();
- g.add(new Triple(NodeFactory.createURI("urn:ann"), NodeFactory
- .createURI("http://example.com/v"), NodeFactory.createAnon()));
- g.add(new Triple(NodeFactory.createURI("urn:bob"), NodeFactory
- .createURI("http://example.com/v"), NodeFactory.createAnon()));
- g.add(new Triple(NodeFactory.createURI("urn:ann"), NodeFactory
- .createURI("http://example.com/v2"), NodeFactory.createAnon()));
-
- sg = Factory.getInstance(securityEvaluator,
- "http://example.com/testGraph", g);
- manager = sg.getEventManager();
- annListener = new RecordingGraphListener();
- manager.register(annListener);
- this.securityEvaluator.setUser("bob");
- bobListener = new RecordingGraphListener();
- manager.register(bobListener);
- }
-
- @Test
- public void notificationsTest() {
- sg.add(new Triple(NodeFactory.createURI("urn:bob"), NodeFactory
- .createURI("http://example.com/v2"), NodeFactory.createAnon()));
-
- Assert.assertTrue("Should recorded add", bobListener.isAdd());
- Assert.assertFalse("Should not have recorded add", annListener.isAdd());
-
- sg.delete(new Triple(NodeFactory.createURI("urn:bob"), NodeFactory
- .createURI("http://example.com/v2"), NodeFactory.createAnon()));
-
- Assert.assertTrue("Should recorded delete", bobListener.isDelete());
- Assert.assertFalse("Should not have recorded delete",
- annListener.isDelete());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java b/jena-security/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java
deleted file mode 100644
index 10ffd42..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java
+++ /dev/null
@@ -1,239 +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.graph;
-
-import java.util.Arrays;
-import java.util.Set;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.GraphEventManager ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.graph.impl.CollectionGraph ;
-import org.apache.jena.security.Factory;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.graph.SecuredGraph;
-import org.apache.jena.sparql.graph.GraphFactory ;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Verifies that messages are properly filtered when sent to listeners.
- *
- */
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class GraphEventManagerTest
-{
- private final GraphEventManager manager;
- private final Graph g;
- private final SecuredGraph sg;
- private final SecurityEvaluator securityEvaluator;
- private Triple[] tripleArray;
-
- private final RecordingGraphListener listener;
-
- public GraphEventManagerTest( final MockSecurityEvaluator securityEvaluator )
- {
- this.securityEvaluator = securityEvaluator;
- g = GraphFactory.createDefaultGraph();
-
- sg = Factory.getInstance(securityEvaluator,
- "http://example.com/testGraph", g);
- manager = sg.getEventManager();
- listener = new RecordingGraphListener();
- manager.register(listener);
-
- }
-
- @Test
- @SuppressWarnings("deprecation")
- public void notifyAddTest()
- {
- Object principal = securityEvaluator.getPrincipal();
- final Set<Action> ADD = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Read });
- g.add(tripleArray[0]);
- if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
- {
- Assert.assertTrue("Should recorded add", listener.isAdd());
- }
- else
- {
- Assert.assertFalse("Should not have recorded add", listener.isAdd());
- }
- g.delete(Triple.ANY);
- listener.reset();
-
- g.getBulkUpdateHandler().add(tripleArray);
- if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
- {
- Assert.assertTrue("Should recorded add", listener.isAdd());
- }
- else
- {
- Assert.assertFalse("Should not have recorded add", listener.isAdd());
- }
- g.delete(Triple.ANY);
- listener.reset();
-
- g.getBulkUpdateHandler().add(Arrays.asList(tripleArray));
- if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
- {
- Assert.assertTrue("Should recorded add", listener.isAdd());
- }
- else
- {
- Assert.assertFalse("Should not have recorded add", listener.isAdd());
- }
- g.delete(Triple.ANY);
- listener.reset();
-
- g.getBulkUpdateHandler().add(Arrays.asList(tripleArray).iterator());
- if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
- {
- Assert.assertTrue("Should recorded add", listener.isAdd());
- }
- else
- {
- Assert.assertFalse("Should not have recorded add", listener.isAdd());
- }
- g.delete(Triple.ANY);
- listener.reset();
-
- g.getBulkUpdateHandler().add(
- new CollectionGraph(Arrays.asList(tripleArray)));
- if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
- {
- Assert.assertTrue("Should recorded add", listener.isAdd());
- }
- else
- {
- Assert.assertFalse("Should not have recorded add", listener.isAdd());
- }
- g.delete(Triple.ANY);
- listener.reset();
- }
-
- @SuppressWarnings("deprecation")
- @Test
- public void notifyDeleteTest()
- {
- Object principal = securityEvaluator.getPrincipal();
- final Set<Action> DELETE = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Read });
- g.delete(tripleArray[0]);
- if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
- {
- Assert.assertTrue("Should have recorded delete",
- listener.isDelete());
- }
- else
- {
- Assert.assertFalse("Should not have recorded delete",
- listener.isDelete());
- }
-
- listener.reset();
-
- g.getBulkUpdateHandler().delete(tripleArray);
- if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
- {
- Assert.assertTrue("Should recorded delete", listener.isDelete());
- }
- else
- {
- Assert.assertFalse("Should not have recorded delete",
- listener.isDelete());
- }
- listener.reset();
-
- g.getBulkUpdateHandler().delete(Arrays.asList(tripleArray));
- if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
- {
- Assert.assertTrue("Should recorded delete", listener.isDelete());
- }
- else
- {
- Assert.assertFalse("Should not have recorded delete",
- listener.isDelete());
- }
- listener.reset();
-
- g.getBulkUpdateHandler().delete(Arrays.asList(tripleArray).iterator());
- if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
- {
- Assert.assertTrue("Should recorded delete", listener.isDelete());
- }
- else
- {
- Assert.assertFalse("Should not have recorded delete",
- listener.isDelete());
- }
- listener.reset();
-
- g.getBulkUpdateHandler().delete(
- new CollectionGraph(Arrays.asList(tripleArray)));
- if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
- {
- Assert.assertTrue("Should recorded delete", listener.isDelete());
- }
- else
- {
- Assert.assertFalse("Should not have recorded delete",
- listener.isDelete());
- }
- listener.reset();
- }
-
- @Test
- public void notifyEventTest()
- {
- g.getEventManager().notifyEvent(g, "Foo");
- Assert.assertTrue("Should recorded delete", listener.isEvent());
- listener.reset();
- // final RecordingGraphListener listener2 = new
- // RecordingGraphListener();
- // g.getEventManager().register(listener2);
- sg.getEventManager().notifyEvent(sg, "Foo");
- Assert.assertTrue("Should recorded delete", listener.isEvent());
- // Assert.assertTrue("Should recorded delete", listener2.isEvent());
- listener.reset();
-
- }
-
- @Before
- public void setup()
- {
- tripleArray = new Triple[] {
- new Triple(NodeFactory.createURI("http://example.com/1"),
- NodeFactory.createURI("http://example.com/v"),
- NodeFactory.createAnon()),
- new Triple(NodeFactory.createURI("http://example.com/2"),
- NodeFactory.createURI("http://example.com/v"),
- NodeFactory.createAnon()),
- new Triple(NodeFactory.createURI("http://example.com/3"),
- NodeFactory.createURI("http://example.com/v"),
- NodeFactory.createAnon()) };
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/graph/MemGraphTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/graph/MemGraphTest.java b/jena-security/src/test/java/org/apache/jena/security/graph/MemGraphTest.java
deleted file mode 100644
index 3f4685a..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/graph/MemGraphTest.java
+++ /dev/null
@@ -1,387 +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.graph;
-
-import java.lang.reflect.Method;
-import java.util.Set;
-
-import org.apache.jena.graph.* ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.EqualityTester;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.graph.SecuredBulkUpdateHandler;
-import org.apache.jena.security.graph.SecuredGraph;
-import org.apache.jena.sparql.graph.GraphFactory ;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class MemGraphTest
-{
- private SecuredGraph securedGraph;
- private final MockSecurityEvaluator securityEvaluator;
- private Node s;
- private Node p;
- private Node o;
- private Triple t;
-
- private Graph baseGraph;
-
- public MemGraphTest( final MockSecurityEvaluator securityEvaluator )
- {
- this.securityEvaluator = securityEvaluator;
- }
-
- protected Graph createGraph() throws Exception
- {
- return GraphFactory.createDefaultGraph();
- }
-
- @SuppressWarnings("deprecation")
- @Before
- public void setUp() throws Exception
- {
- baseGraph = createGraph();
- baseGraph.getBulkUpdateHandler().removeAll();
- securedGraph = org.apache.jena.security.Factory
- .getInstance(securityEvaluator,
- "http://example.com/securedGraph", baseGraph);
- s = NodeFactory.createURI("http://example.com/securedGraph/s");
- p = NodeFactory.createURI("http://example.com/securedGraph/p");
- o = NodeFactory.createURI("http://example.com/securedGraph/o");
- t = new Triple(s, p, o);
- baseGraph.add(t);
- }
-
- @Test
- public void testBulkUpdateHandler() throws Exception
- {
- final BulkUpdateHandler buh = securedGraph.getBulkUpdateHandler();
- Assert.assertNotNull("BulkUpdateHandler may not be null", buh);
- Assert.assertTrue("BulkUpdateHandler should be secured",
- buh instanceof SecuredBulkUpdateHandler);
- final BulkUpdateHandlerTest buhTest = new BulkUpdateHandlerTest(
- securityEvaluator) {
- @Override
- public void setup()
- {
- this.handler = (SecuredBulkUpdateHandler) buh;
- }
- };
- for (final Method m : buhTest.getClass().getMethods())
- {
- if (m.isAnnotationPresent(Test.class))
- {
- buhTest.setup();
- m.invoke(buhTest);
- }
- }
- }
-
- @Test
- public void testContainsNodes() throws Exception
- {
- try
- {
- Assert.assertTrue(securedGraph.contains(s, p, o));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testContainsTriple() throws Exception
- {
- try
- {
- Assert.assertTrue(securedGraph.contains(t));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testDelete() throws Exception
- {
- final Set<Action> UD = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
- try
- {
- securedGraph.delete(t);
-
- if (!securityEvaluator.evaluate(UD))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- Assert.assertEquals(0, baseGraph.size());
-
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(UD))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testDependsOn() throws Exception
- {
- try
- {
- Assert.assertFalse(securedGraph.dependsOn(GraphFactory
- .createDefaultGraph()));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- Assert.assertTrue(securedGraph.dependsOn(baseGraph));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testFindNodes() throws Exception
- {
- try
- {
-
- Assert.assertFalse(securedGraph.find(Node.ANY, Node.ANY, Node.ANY)
- .toList().isEmpty());
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testFindTriple() throws Exception
- {
- try
- {
- Assert.assertFalse(securedGraph.find(t).toList().isEmpty());
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetPrefixMapping() throws Exception
- {
- SecuredPrefixMappingTest.runTests(securityEvaluator,
- securedGraph.getPrefixMapping());
- }
-
- @Test
- public void testInequality()
- {
- EqualityTester
- .testInequality("proxy and base", securedGraph, baseGraph);
- final Graph g2 = org.apache.jena.security.graph.impl.Factory
- .getInstance(securityEvaluator,
- "http://example.com/securedGraph", baseGraph);
- EqualityTester.testEquality("proxy and proxy2", securedGraph, g2);
- EqualityTester.testInequality("base and proxy2", baseGraph, g2);
- }
-
- @Test
- public void testIsIsomorphicWith() throws Exception
- {
- try
- {
- Assert.assertFalse(securedGraph.isIsomorphicWith(GraphFactory
- .createDefaultGraph()));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- Assert.assertTrue(securedGraph.isIsomorphicWith(baseGraph));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testSize() throws Exception
- {
- try
- {
- Assert.assertEquals(1, securedGraph.size());
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testTripleMatch() throws Exception
- {
- try
- {
- Assert.assertFalse(securedGraph.find(new TripleMatch() {
-
- @Override
- public Triple asTriple()
- {
- return Triple.ANY;
- }
-
- @Override
- public Node getMatchObject()
- {
- return Node.ANY;
- }
-
- @Override
- public Node getMatchPredicate()
- {
- return Node.ANY;
- }
-
- @Override
- public Node getMatchSubject()
- {
- return Node.ANY;
- }
- }).toList().isEmpty());
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java b/jena-security/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java
deleted file mode 100644
index d65d814..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package org.apache.jena.security.graph;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.GraphListener ;
-import org.apache.jena.graph.Triple ;
-
-/*
- * 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.
- */
-
-public class RecordingGraphListener implements GraphListener
-{
-
- private boolean add;
- private boolean delete;
- private boolean event;
-
- public boolean isAdd()
- {
- return add;
- }
-
- public boolean isDelete()
- {
- return delete;
- }
-
- public boolean isEvent()
- {
- return event;
- }
-
- @Override
- public void notifyAddArray( final Graph g, final Triple[] triples )
- {
- add = true;
- }
-
- @Override
- public void notifyAddGraph( final Graph g, final Graph added )
- {
- add = true;
- }
-
- @Override
- public void notifyAddIterator( final Graph g, final Iterator<Triple> it )
- {
- add = true;
- }
-
- @Override
- public void notifyAddList( final Graph g, final List<Triple> triples )
- {
- add = true;
- }
-
- @Override
- public void notifyAddTriple( final Graph g, final Triple t )
- {
- add = true;
- }
-
- @Override
- public void notifyDeleteArray( final Graph g, final Triple[] triples )
- {
- delete = true;
- }
-
- @Override
- public void notifyDeleteGraph( final Graph g, final Graph removed )
- {
- delete = true;
- }
-
- @Override
- public void notifyDeleteIterator( final Graph g,
- final Iterator<Triple> it )
- {
- delete = true;
- }
-
- @Override
- public void notifyDeleteList( final Graph g, final List<Triple> L )
- {
- delete = true;
- }
-
- @Override
- public void notifyDeleteTriple( final Graph g, final Triple t )
- {
- delete = true;
- }
-
- @Override
- public void notifyEvent( final Graph source, final Object value )
- {
- event = true;
- }
-
- public void reset()
- {
- add = false;
- delete = false;
- event = false;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java b/jena-security/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java
deleted file mode 100644
index 7ad4e84..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java
+++ /dev/null
@@ -1,440 +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.graph;
-
-import java.lang.reflect.Method;
-import java.util.HashMap;
-
-import org.junit.Assert;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.Factory;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.graph.SecuredGraph;
-import org.apache.jena.security.graph.SecuredPrefixMapping;
-import org.apache.jena.shared.PrefixMapping ;
-import org.apache.jena.shared.impl.PrefixMappingImpl ;
-import org.apache.jena.sparql.graph.GraphFactory ;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredPrefixMappingTest
-{
- public static void runTests( final SecurityEvaluator securityEvaluator,
- final PrefixMapping prefixMapping ) throws Exception
- {
- final PrefixMapping pm = prefixMapping;
- Assert.assertNotNull("PrefixMapping may not be null", pm);
- Assert.assertTrue("PrefixMapping should be secured",
- pm instanceof SecuredPrefixMapping);
- final SecuredPrefixMappingTest pmTest = new SecuredPrefixMappingTest(
- securityEvaluator) {
- @Override
- public void setup()
- {
- this.securedMapping = (SecuredPrefixMapping) pm;
- }
- };
- Method lockTest = null;
- for (final Method m : pmTest.getClass().getMethods())
- {
- if (m.isAnnotationPresent(Test.class))
- {
- // lock test must come last
- if (m.getName().equals("testLock"))
- {
- lockTest = m;
- }
- else
- {
- pmTest.setup();
- m.invoke(pmTest);
- }
-
- }
- }
- Assert.assertNotNull( "Did not find 'testLock' method", lockTest );
- pmTest.setup();
- lockTest.invoke(pmTest);
-
- }
-
- private final SecurityEvaluator securityEvaluator;
- private final Object principal;
-
- protected SecuredPrefixMapping securedMapping;
-
- public SecuredPrefixMappingTest( final SecurityEvaluator securityEvaluator )
- {
- this.securityEvaluator = securityEvaluator;
- this.principal = securityEvaluator.getPrincipal();
- }
-
- @Before
- public void setup()
- {
- final Graph g = GraphFactory.createDefaultGraph();
-
- final SecuredGraph sg = Factory.getInstance(securityEvaluator,
- "http://example.com/testGraph", g);
- this.securedMapping = sg.getPrefixMapping();
- }
-
- @Test
- public void testExpandPrefix()
- {
- try
- {
- securedMapping.expandPrefix("foo");
- if (!securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetNsPrefixMap()
- {
- try
- {
- securedMapping.getNsPrefixMap();
- if (!securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetNsPrefixURI()
- {
- try
- {
- securedMapping.getNsPrefixURI("foo");
- if (!securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testGetNsURIPrefix()
- {
- try
- {
- securedMapping.getNsURIPrefix("http://example.com/foo");
- if (!securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testLock()
- {
- try
- {
- securedMapping.lock();
- if (!securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testQnameFor()
- {
- try
- {
- securedMapping.qnameFor("http://example.com/foo/bar");
- if (!securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testRemoveNsPrefix()
- {
- try
- {
- securedMapping.removeNsPrefix("foo");
- if (!securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testSamePrefixMappingAs()
- {
- try
- {
- securedMapping.samePrefixMappingAs(GraphFactory
- .createDefaultGraph().getPrefixMapping());
- if (!securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testSetNsPrefix()
- {
- try
- {
- securedMapping.setNsPrefix("foo", "http://example.com/foo");
- if (!securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
-
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedMapping.setNsPrefixes(GraphFactory.createDefaultGraph()
- .getPrefixMapping());
- if (!securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedMapping.setNsPrefixes(new HashMap<String, String>());
- if (!securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testShortForm()
- {
- try
- {
- securedMapping.shortForm("http://example.com/foo/bar");
- if (!securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Read,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testWithDefaultMappings()
- {
- PrefixMapping pm = new PrefixMappingImpl();
- pm.setNsPrefix( "example", "http://example.com");
- try
- {
- // make sure that it must update
- securedMapping.withDefaultMappings(pm);
- if (!securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testWithDefaultMappingsNoAdd()
- {
- PrefixMapping pm = new PrefixMappingImpl();
- try
- {
- // make sure that it must update
- securedMapping.withDefaultMappings(pm);
-// if (!securityEvaluator.evaluate(Action.Update,
-// securedMapping.getModelNode()))
-// {
-// Assert.fail("Should have thrown AccessDenied Exception");
-// }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(principal, Action.Update,
- securedMapping.getModelNode()))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java b/jena-security/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java
deleted file mode 100644
index 5fb7178..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java
+++ /dev/null
@@ -1,58 +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.graph;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.tdb.TDB ;
-import org.apache.jena.tdb.TDBFactory ;
-import org.junit.After;
-
-public class TDBGraphTest extends MemGraphTest
-{
-
- private DatasetGraph dsGraph;
-
- private File f;
-
- public TDBGraphTest( final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- }
-
- @Override
- protected Graph createGraph() throws IOException
- {
- TDB.init();
- dsGraph = TDBFactory.createDataset().asDatasetGraph();
- return dsGraph.getDefaultGraph();
- }
-
- @After
- public void tearDown()
- {
- TDB.sync(dsGraph);
- dsGraph.close();
- TDB.closedown();
- }
-
-}
[21/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredModel.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredModel.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredModel.java
new file mode 100644
index 0000000..4b59115
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredModel.java
@@ -0,0 +1,1566 @@
+/*
+ * 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.model;
+
+import java.io.InputStream ;
+import java.io.OutputStream ;
+import java.io.Reader ;
+import java.io.Writer ;
+import java.util.Calendar ;
+import java.util.Iterator ;
+import java.util.List ;
+
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.AccessDeniedException ;
+import org.apache.jena.security.graph.SecuredGraph ;
+import org.apache.jena.security.graph.SecuredPrefixMapping ;
+import org.apache.jena.security.model.impl.SecuredNodeIterator ;
+import org.apache.jena.security.model.impl.SecuredRSIterator ;
+import org.apache.jena.security.model.impl.SecuredResIterator ;
+import org.apache.jena.security.model.impl.SecuredStatementIterator ;
+import org.apache.jena.shared.PropertyNotFoundException ;
+
+/**
+ * The interface for secured Model instances.
+ *
+ * Use the SecuredModel.Factory to create instances
+ */
+public interface SecuredModel extends Model, SecuredPrefixMapping
+{
+
+ @Override
+ public SecuredModel abort();
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create for each statement as a triple.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final List<Statement> statements )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create for each statement in the securedModel as a triple.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final Model m ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create the triple SecTriple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final Resource s, final Property p, final RDFNode o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create the triple SecTriple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final Resource s, final Property p, final String o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create the triple SecTriple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final Resource s, final Property p,
+ final String o, final boolean wellFormed )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create the triple SecTriple(s,p,literal(lex,datatype))
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final Resource s, final Property p,
+ final String lex, final RDFDatatype datatype )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create the triple SecTriple(s,p,literal(o,l,false))
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final Resource s, final Property p,
+ final String o, final String l ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create the statement as a triple
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final Statement s ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create all the statements as triples.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final Statement[] statements )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create all the statements as triples.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel add( final StmtIterator iter )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create triple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final boolean o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create triple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final char o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create triple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final double o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create triple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final float o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create triple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final int o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create triple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final Literal o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create triple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final long o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create triple(s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ @Deprecated
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final Object o ) throws AccessDeniedException;
+
+ @Override
+ public SecuredRDFNode asRDFNode( final Node n );
+
+ @Override
+ /**
+ * @sec.graph Read if t does exist
+ * @sec.graph Update it t does not exist
+ * @sec.triple Read if t does exist
+ * @sec.triple Create if t does exist
+ * @throws AccessDeniedException
+ */
+ public SecuredStatement asStatement( final Triple t )
+ throws AccessDeniedException;
+
+ @Override
+ public SecuredModel begin();
+
+ @Override
+ public SecuredModel commit();
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, SecNode.ANY )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final Resource s, final Property p )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final Resource s, final Property p, final RDFNode o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final Resource s, final Property p, final String o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, literal(o,l,null) )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final Resource s, final Property p,
+ final String o, final String l ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read s as a triple with null replaced by SecNode.ANY
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final Statement s ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read every statement in securedModel.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsAll( final Model model )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read every statement
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsAll( final StmtIterator iter )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read any statement in securedModel to be included in check, if
+ * no
+ * statement in securedModel can be read will return false;
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsAny( final Model model )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read any statement in iter to be included in check, if no
+ * statement in iter can be read will return false;
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsAny( final StmtIterator iter )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, literal(o) )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final boolean o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, literal(o) )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final char o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, literal(o) )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final double o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, literal(o) )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final float o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, literal(o) )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final int o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, literal(o) )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final long o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, typedLiteral(o) )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final Object o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( s, p, resource) where SecTriple(s,p,resource) is in the
+ * securedModel.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean containsResource( final RDFNode r )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( SecNode.ANY, RDF.type, Rdf.Alt)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt createAlt() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( uri, RDF.type, Rdf.Alt)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt createAlt( final String uri )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( SecNode.ANY, RDF.type, Rdf.Bag)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredBag createBag() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( uri, RDF.type, Rdf.Bag)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredBag createBag( final String uri )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredRDFList createList() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( RDF.nil, SecNode.IGNORE, SecNode.IGNORE)
+ * @sec.triple Create for each member SecTriple(SecNode.ANY,
+ * RDF.first.asNode(),
+ * member.asNode())
+ * @sec.triple Create SecTriple(SecNode.ANY, RDF.rest.asNode(), SecNode.ANY)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredRDFList createList( final Iterator<? extends RDFNode> members )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( RDF.nil, SecNode.IGNORE, SecNode.IGNORE)
+ * @sec.triple Create for each member SecTriple(SecNode.ANY,
+ * RDF.first.asNode(),
+ * member.asNode())
+ * @sec.triple Create SecTriple(SecNode.ANY, RDF.rest.asNode(), SecNode.ANY)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredRDFList createList( final RDFNode[] members )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s,p,o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final boolean o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s,p,o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final char o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s,p,o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final double o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s,p,o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final float o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s,p,o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final int o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s,p,o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final long o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s,p,o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final Object o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s,p,o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Property createProperty( final String uri )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s,p,o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Property createProperty( final String nameSpace,
+ final String localName ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Read s as a triple
+ * @sec.triple create SecTriple( SecNode.Future, RDF.subject, t.getSubject()
+ * )
+ * @sec.triple create SecTriple( SecNode.Future, RDF.subject,
+ * t.getPredicate() )
+ * @sec.triple create SecTriple( SecNode.Future, RDF.subject, t.getObject() )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public ReifiedStatement createReifiedStatement( final Statement s )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Read s as a triple
+ * @sec.triple create SecTriple( uri, RDF.subject, t.getSubject() )
+ * @sec.triple create SecTriple( uri, RDF.subject, t.getPredicate() )
+ * @sec.triple create SecTriple( uri, RDF.subject, t.getObject() )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public ReifiedStatement createReifiedStatement( final String uri,
+ final Statement s ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Read s as a triple
+ * @sec.triple create SecTriple( SecNode.FUTURE, SecNode.IGNORE,
+ * SecNode.IGNORE )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource createResource() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Read s as a triple
+ * @sec.triple create SecTriple( Anonymous(id), SecNode.IGNORE,
+ * SecNode.IGNORE )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource createResource( final AnonId id )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.type, type )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource createResource( final Resource type )
+ throws AccessDeniedException;
+
+ @Override
+ @Deprecated
+ public SecuredResource createResource( final ResourceF f );
+
+ @Override
+ public SecuredResource createResource( final String uri );
+
+ /**
+ * @sec.graph Update if uri exists
+ * @sec.graph Create if uri does not exist
+ * @sec.triple Read if SecTriple( uri, RDF.type, type ) exists
+ * @sec.triple Create if SecTriple( uri, RDF.type, type ) does not exist
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource createResource( final String uri, final Resource type )
+ throws AccessDeniedException;
+
+ @Override
+ @Deprecated
+ public SecuredResource createResource( final String uri, final ResourceF f );
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.type, RDF.Alt )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredSeq createSeq() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( uri, RDF.type, RDF.Alt )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredSeq createSeq( final String uri )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final RDFNode o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final String o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final String o, final boolean wellFormed )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s, p, literal(o,l,false ))
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final String o, final String l )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( s, p, literal(o,l,wellFormed )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final String o, final String l,
+ final boolean wellFormed ) throws AccessDeniedException;
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final boolean v );
+
+ @Override
+ public Literal createTypedLiteral( final Calendar d );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final char v );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final double v );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final float v );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final int v );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final long v );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final Object value );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final Object value,
+ final RDFDatatype dtype );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final Object value,
+ final String typeURI );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final String v );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final String lex,
+ final RDFDatatype dtype );
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final String lex,
+ final String typeURI );
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read for every triple contributed to the difference.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Model difference( final Model model ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read if read lock is requested
+ * @sec.graph Update if write lock is requested
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void enterCriticalSection( final boolean readLockRequested )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String expandPrefix( final String prefixed )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( resource, RDF.type, RDF.alt )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt getAlt( final Resource r ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( uri, RDF.type, RDF.alt )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredAlt getAlt( final String uri ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read if statement exists
+ * @sec.graph Update if statement does not exist
+ * @sec.triple Read s as a triple
+ * @sec.triple Read SecTriple( result, RDF.subject, s.getSubject() ) if
+ * reification existed
+ * @sec.triple Read SecTriple( result, RDF.predicate, s.getPredicate() ) if
+ * reification existed
+ * @sec.triple Read SecTriple( result, RDF.object, s.getObject() ) if
+ * reification existed
+ * @sec.triple Create SecTriple( result, RDF.subject, s.getSubject() ) if
+ * reification did not exist.
+ * @sec.triple Create SecTriple( result, RDF.redicate, s.getPredicate() ) if
+ * reification did not exist
+ * @sec.triple Create SecTriple( result, RDF.object, s.getObject() ) if
+ * reification did not exist
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource getAnyReifiedStatement( final Statement s )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( resource, RDF.type, RDF.Bag )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredBag getBag( final Resource r ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( uri, RDF.type, RDF.Bag )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredBag getBag( final String uri ) throws AccessDeniedException;
+
+ @Override
+ public SecuredGraph getGraph();
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read on the returned statement.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement getProperty( final Resource s, final Property p )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Property getProperty( final String uri )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Property getProperty( final String nameSpace, final String localName )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read if the node exists
+ * @sec.graph Update if the node does not exist
+ * @throws AccessDeniedException
+ */
+ @Override
+ public RDFNode getRDFNode( final Node n ) throws AccessDeniedException;
+
+ /**
+ * .
+ * If the PropertyNotFoundException was thrown by the enclosed securedModel
+ * and the
+ * user can not read SecTriple(s, p, SecNode.ANY) AccessDeniedExcepiton is
+ * thrown,
+ * otherwise the PropertyNotFoundException will be thrown.
+ *
+ * @sec.graph Read
+ * @sec.triple Read on the returned statement
+ * @sec.triple Read on SecTriple(s, p, SecNode.ANY) if
+ * PropertyNotFoundException
+ * was thrown
+ * @throws AccessDeniedException
+ * @throws PropertyNotFoundException
+ */
+ @Override
+ public SecuredStatement getRequiredProperty( final Resource s,
+ final Property p ) throws PropertyNotFoundException,
+ AccessDeniedException;
+
+ @Override
+ public SecuredResource getResource( final String uri );
+
+ @Override
+ @Deprecated
+ public SecuredResource getResource( final String uri, final ResourceF f );
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on SecTriple(resource, RDF.type, RDF.Seq)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredSeq getSeq( final Resource r ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on SecTriple(uri, RDF.type, RDF.Seq)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredSeq getSeq( final String uri ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples contributed to the new securedModel.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Model intersection( final Model model ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean isEmpty() throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read all compared triples. Triples that can not be read will
+ * not be compared.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean isIsomorphicWith( final Model g )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on s as triple
+ * @sec.triple Read on at least one set reified statements.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean isReified( final Statement s ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate,
+ final boolean object ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned.
+ * @throws AccessDeniedException
+ */
+
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate, final char object )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned.
+ * @throws AccessDeniedException
+ */
+
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate,
+ final double object ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned.
+ * @throws AccessDeniedException
+ */
+
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate, final float object )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned.
+ * @throws AccessDeniedException
+ */
+
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate, final long object )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public NsIterator listNameSpaces() throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on each RDFNode returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredNodeIterator<RDFNode> listObjects() throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on each RDFNode returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredNodeIterator<RDFNode> listObjectsOfProperty( final Property p )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on each RDFNode returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredNodeIterator<RDFNode> listObjectsOfProperty( final Resource s,
+ final Property p ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on each Reified statement returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredRSIterator listReifiedStatements()
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on each Reified statement returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredRSIterator listReifiedStatements( final Statement st )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned;
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned;
+ * @throws AccessDeniedException
+ */
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final boolean o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned;
+ * @throws AccessDeniedException
+ */
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final char o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned;
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final double o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned;
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final float o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned;
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final long o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned;
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final Object o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final RDFNode o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatementIterator listStatements()
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatementIterator listStatements( final Resource s,
+ final Property p, final RDFNode o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatementIterator listStatements( final Resource subject,
+ final Property predicate, final String object )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatementIterator listStatements( final Resource subject,
+ final Property predicate, final String object, final String lang )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all triples returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatementIterator listStatements( final Selector s )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listSubjects() throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listSubjectsWithProperty( final Property p )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listSubjectsWithProperty( final Property p,
+ final RDFNode o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listSubjectsWithProperty( final Property p,
+ final String o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read at least one SecTriple( resource, p, o ) for each
+ * resource
+ * returned
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResIterator listSubjectsWithProperty( final Property p,
+ final String o, final String l ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredPrefixMapping lock() throws AccessDeniedException;
+
+ @Override
+ public SecuredModel notifyEvent( final Object e );
+
+ /**
+ *
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String qnameFor( final String uri ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel query( final Selector s ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel read( final InputStream in, final String base )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel read( final InputStream in, final String base,
+ final String lang ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel read( final Reader reader, final String base )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel read( final Reader reader, final String base,
+ final String lang ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel read( final String url ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel read( final String url, final String lang )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel read( final String url, final String base,
+ final String lang ) throws AccessDeniedException;
+
+ /**
+ *
+ * Listener will be filtered to only report events that the user can see.
+ *
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel register( final ModelChangedListener listener )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on every statement in statments.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel remove( final List<Statement> statements )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on every statement in baseModel.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel remove( final Model m ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on SecTriple( s, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel remove( final Resource s, final Property p, final RDFNode o ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on statment.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel remove( final Statement s )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on every statement in statments.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel remove( final Statement[] statements )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on every statement in iter.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel remove( final StmtIterator iter )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on every statement in the securedModel
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel removeAll() throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on every statement identified by SecTriple( s,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel removeAll( final Resource s, final Property p,
+ final RDFNode r ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on every reification statement for each statement in
+ * statments.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void removeAllReifications( final Statement s )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredPrefixMapping removeNsPrefix( final String prefix )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @sec.triple Delete on every reification statement fore each statement in
+ * rs.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void removeReification( final ReifiedStatement rs )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String setReaderClassName( final String lang, final String className )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String setWriterClassName( final String lang, final String className )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String shortForm( final String uri ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public long size() throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all statements contributed to the union.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Model union( final Model model ) throws AccessDeniedException;
+
+ @Override
+ public SecuredModel unregister( final ModelChangedListener listener );
+
+ @Override
+ public SecuredResource wrapAsResource( final Node n );
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all statements that are written.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel write( final OutputStream out )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all statements that are written.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel write( final OutputStream out, final String lang )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all statements that are written.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel write( final OutputStream out, final String lang,
+ final String base ) throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all statements that are written.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel write( final Writer writer )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all statements that are written.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel write( final Writer writer, final String lang )
+ throws AccessDeniedException;
+
+ /**
+ *
+ * @sec.graph Read
+ * @sec.triple Read on all statements that are written.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredModel write( final Writer writer, final String lang,
+ final String base ) throws AccessDeniedException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredProperty.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredProperty.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredProperty.java
new file mode 100644
index 0000000..6c9518f
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredProperty.java
@@ -0,0 +1,38 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.Property ;
+import org.apache.jena.security.AccessDeniedException;
+
+/**
+ * The interface for secured Property instances.
+ *
+ * Use the SecuredProperty.Factory to create instances
+ */
+public interface SecuredProperty extends SecuredResource, Property
+{
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public int getOrdinal() throws AccessDeniedException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredRDFList.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredRDFList.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredRDFList.java
new file mode 100644
index 0000000..08bac61
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredRDFList.java
@@ -0,0 +1,414 @@
+/*
+ * 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.model;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+
+public interface SecuredRDFList extends RDFList, SecuredResource
+{
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple(SecNode.FUTURE, listFirst(), value)
+ * @sec.triple Create SecTriple(SecNode.FUTURE, listFirst(), listNil())
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void add( final RDFNode value ) throws AccessDeniedException;
+
+ /**
+ * Resulting list will contain the readable nodes from this list
+ * concatenated with nodes
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, value )
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.rest, this )
+ */
+ @Override
+ public RDFList append( final Iterator<? extends RDFNode> nodes )
+ throws AccessDeniedException;
+
+ /**
+ * Resulting list will contain the readable nodes from this list
+ * concatenated
+ * with the list argument
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, value )
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.rest, this )
+ */
+ @Override
+ public RDFList append( final RDFList list ) throws AccessDeniedException;
+
+ /**
+ * Uses the security settings for the application of the function calls.
+ * Thus if the function reads data the Read must be allowed, etc.
+ *
+ * @sec.graph Read
+ * @sec.triple Read (to be included in the calculation)
+ * @sec.triple other permissions required by the function.
+ * @throws AccessDeniedException
+ * graph Read or other permissions are not met
+ */
+ @Override
+ public void apply( final ApplyFn fn ) throws AccessDeniedException;
+
+ /**
+ * This method is intended to provide the capabilities to apply functions
+ * that
+ * need to do more than read the graph.
+ *
+ * If the user does not have constraints access to the item in the list the
+ * item
+ * is not included in the function.
+ *
+ * @param constraints
+ * The permissions the user must have on the items in the list.
+ * @param fn
+ * The function to apply.
+ *
+ * @sec.graph Read
+ * @sec.triple Read and constraints
+ * @throws AccessDeniedException
+ */
+ public void apply( Set<Action> constraints, final ApplyFn fn )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.triple Read for triples containing the returned RDFNodes.
+ * @return List<SecuredRDFNode>
+ */
+ @Override
+ public List<RDFNode> asJavaList();
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, node ) for each
+ * node in
+ * nodes.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void concatenate( final Iterator<? extends RDFNode> nodes )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, node ) for each
+ * node in
+ * list.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void concatenate( final RDFList list ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, value )
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.rest, this )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredRDFList cons( final RDFNode value )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read for triple containing value.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean contains( final RDFNode value ) throws AccessDeniedException;
+
+ /**
+ * Creates a copy of this list comprising the readable elements of this
+ * list.
+ * @sec.graph Read to read the items to copy
+ * @sec.triple Read on each triple to be read.
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.first, value )
+ * @sec.triple Create SecTriple( SecNode.FUTURE, RDF.rest, this )
+ */
+ @Override
+ public SecuredRDFList copy();
+
+ /**
+ * Answer the node that is the i'th element of the list, assuming that the
+ * head is item zero. If the list is too
+ * short to have an i'th element, throws a ListIndexException.
+ *
+ * List may be shortened by security constraints.
+ *
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public SecuredRDFNode get( final int i ) throws AccessDeniedException,
+ EmptyListException, ListIndexException, InvalidListException;
+
+ /**
+ * The value that is at the head of the list.
+ *
+ * head may be shifted by security constraints.
+ *
+ * @sec.graph Read
+ * @sec.triple Read for triple containing value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ */
+ @Override
+ public RDFNode getHead() throws AccessDeniedException, EmptyListException;
+
+ /**
+ * The value that is at the tail of the list.
+ *
+ * tail may be shifted by security constraints.
+ *
+ * @sec.graph Read
+ * @sec.triple Read for triple containing value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public SecuredRDFList getTail() throws AccessDeniedException,
+ EmptyListException, ListIndexException, InvalidListException;
+
+ /**
+ * @sec.graph Read
+ */
+ @Override
+ public String getValidityErrorMessage() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read for triple containing value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public int indexOf( final RDFNode value ) throws AccessDeniedException,
+ EmptyListException, ListIndexException, InvalidListException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read for triple containing value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public int indexOf( final RDFNode value, final int start )
+ throws AccessDeniedException, EmptyListException,
+ ListIndexException, InvalidListException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean isEmpty() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean isValid() throws AccessDeniedException, EmptyListException,
+ ListIndexException, InvalidListException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read for triple containing value to be included in the result.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public ExtendedIterator<RDFNode> iterator() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read + requiredPerms for triple containing value to be
+ * included in the result.
+ * @throws AccessDeniedException
+ */
+ public ExtendedIterator<RDFNode> iterator( Set<Action> requiredPerms )
+ throws AccessDeniedException, EmptyListException,
+ ListIndexException, InvalidListException;
+
+ /**
+ * Only readable triples will be passed to the function. If the function
+ * does
+ * any action other than read those permissions must also be granted.
+ *
+ * @sec.graph Read
+ * @sec.triple Read for triple containing value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public Object reduce( final ReduceFn fn, final Object initial )
+ throws AccessDeniedException, EmptyListException,
+ ListIndexException, InvalidListException;
+
+ /**
+ * Only readable triples will be passed to the function. In addition,
+ * only triples that pass the requiredActions tests will be passed to the
+ * function.
+ *
+ * @sec.graph Read
+ * @sec.triple Read for triple containing value.
+ * @param requiredActions
+ * The set of permission (in addition to Read) that the user must
+ * have
+ * @param fn
+ * The reduction function
+ * @param initial
+ * The initial state for the ruduce value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ public Object reduce( Set<Action> requiredActions, final ReduceFn fn,
+ final Object initial ) throws AccessDeniedException,
+ EmptyListException, ListIndexException, InvalidListException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete for triple containing value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public RDFList remove( final RDFNode val ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete for all triples.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ @Deprecated
+ public void removeAll() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete for the head triple.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public RDFList removeHead() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete for triple containing value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public void removeList() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update for triplie i, and value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public SecuredRDFNode replace( final int i, final RDFNode value )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read for triples included in the comparison.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public boolean sameListAs( final RDFList list )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create for triple containing value.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public SecuredRDFNode setHead( final RDFNode value )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void setStrict( final boolean strict ) throws AccessDeniedException;
+
+ /**
+ * Size may be modified by security constraionts.
+ *
+ * @sec.graph Read
+ * @sec.triple Read for triples counted in the result.
+ * @throws AccessDeniedException
+ * @throws EmptyListException
+ * @throws ListIndexException
+ * @throws InvalidListException
+ */
+ @Override
+ public int size() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create for triple containing value.
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredRDFList with( final RDFNode value )
+ throws AccessDeniedException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredRDFNode.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredRDFNode.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredRDFNode.java
new file mode 100644
index 0000000..5002366
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredRDFNode.java
@@ -0,0 +1,59 @@
+/*
+ * 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.model;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.RDFNode ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.impl.SecuredItem;
+
+/**
+ * The interface for secured RDFNode instances.
+ *
+ * Use one the SecuredRDFNode derived class Factories to create instances
+ */
+public interface SecuredRDFNode extends RDFNode, SecuredItem
+{
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Node asNode() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public <T extends RDFNode> boolean canAs( final Class<T> view )
+ throws AccessDeniedException;
+
+ @Override
+ public SecuredModel getModel();
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public RDFNode inModel( final Model m ) throws AccessDeniedException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredReifiedStatement.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredReifiedStatement.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredReifiedStatement.java
new file mode 100644
index 0000000..67e33ad
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredReifiedStatement.java
@@ -0,0 +1,38 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.ReifiedStatement ;
+import org.apache.jena.security.AccessDeniedException;
+
+/**
+ * The interface for secured ReifiedStatement instances.
+ *
+ * Use the SecuredReifiedStatement.Factory to create instances
+ */
+public interface SecuredReifiedStatement extends ReifiedStatement,
+ SecuredResource
+{
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement getStatement();
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredResource.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredResource.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredResource.java
new file mode 100644
index 0000000..18ba568
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredResource.java
@@ -0,0 +1,333 @@
+/*
+ * 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.model;
+
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.model.impl.SecuredStatementIterator;
+
+/**
+ * The interface for secured Resource instances.
+ *
+ * Use the SecuredResource.Factory to create instances
+ */
+public interface SecuredResource extends Resource, SecuredRDFNode
+{
+
+ @Override
+ public SecuredResource abort();
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource addLiteral( final Property p, final boolean o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addLiteral( final Property p, final char o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, value, d )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addLiteral( final Property value, final double d )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, value, d )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addLiteral( final Property value, final float d )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addLiteral( final Property p, final Literal o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addLiteral( final Property p, final long o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addLiteral( final Property p, final Object o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addProperty( final Property p, final RDFNode o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addProperty( final Property p, final String o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, literal(lexicalForm,datatype) )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addProperty( final Property p, final String lexicalForm,
+ final RDFDatatype datatype ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create (this, p, o )
+ * @throws AccessDeniedException
+ */
+ @Override
+ public Resource addProperty( final Property p, final String o,
+ final String l ) throws AccessDeniedException;
+
+ @Override
+ public SecuredResource asResource();
+
+ @Override
+ public SecuredResource begin();
+
+ @Override
+ public SecuredResource commit();
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean equals( final Object o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public AnonId getId() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getLocalName() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getNameSpace() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement getProperty( final Property p )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource getPropertyResourceValue( final Property p )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement getRequiredProperty( final Property p )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getURI() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final boolean o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final char o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final double o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final float o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final long o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final Object o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasProperty( final Property p ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasProperty( final Property p, final RDFNode o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,o)
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasProperty( final Property p, final String o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this,p,literal(o,l))
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasProperty( final Property p, final String o, final String l )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasURI( final String uri ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read on returned Statements
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatementIterator listProperties()
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read on returned Statements
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatementIterator listProperties( final Property p )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete on associated Statements
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource removeAll( final Property p )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete on all Statements
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredResource removeProperties() throws AccessDeniedException;
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredSeq.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredSeq.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredSeq.java
new file mode 100644
index 0000000..05977ea
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredSeq.java
@@ -0,0 +1,385 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.RDFNode ;
+import org.apache.jena.rdf.model.ResourceF ;
+import org.apache.jena.rdf.model.Seq ;
+import org.apache.jena.security.AccessDeniedException;
+
+/**
+ * The interface for secured Seq instances.
+ *
+ * Use the SecuredSeq.Factory to create instances
+ *
+ * Sequence may have breaks in the order.
+ * http://www.w3.org/TR/2004/REC-rdf-mt-20040210/#Containers
+ *
+ */
+public interface SecuredSeq extends Seq, SecuredContainer
+{
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq add( final int index, final boolean o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq add( final int index, final char o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq add( final int index, final double o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq add( final int index, final float o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq add( final int index, final long o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq add( final int index, final Object o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq add( final int index, final RDFNode o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq add( final int index, final String o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq add( final int index, final String o, final String l )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredAlt getAlt( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredBag getBag( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public boolean getBoolean( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public byte getByte( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public char getChar( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public double getDouble( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public float getFloat( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int getInt( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public String getLanguage( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredLiteral getLiteral( final int index )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public long getLong( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredRDFNode getObject( final int index )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredResource getResource( final int index )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ @Deprecated
+ public SecuredResource getResource( final int index, final ResourceF f )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public SecuredSeq getSeq( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public short getShort( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public String getString( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int indexOf( final boolean o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int indexOf( final char o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int indexOf( final double o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int indexOf( final float o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int indexOf( final long o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int indexOf( final Object o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int indexOf( final RDFNode o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int indexOf( final String o ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple( this, RDF.li(1), o )
+ */
+ @Override
+ public int indexOf( final String o, final String l )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete SecTriple( this, RDF.li(1), o )
+ * @sec.triple Update Triples after index
+ */
+ @Override
+ public SecuredSeq remove( final int index ) throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
+ * RDF.li(index), o )
+ */
+ @Override
+ public SecuredSeq set( final int index, final boolean o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
+ * RDF.li(index), o )
+ */
+ @Override
+ public SecuredSeq set( final int index, final char o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
+ * RDF.li(index), o )
+ */
+ @Override
+ public SecuredSeq set( final int index, final double o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
+ * RDF.li(index), o )
+ */
+ @Override
+ public SecuredSeq set( final int index, final float o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
+ * RDF.li(index), o )
+ */
+ @Override
+ public SecuredSeq set( final int index, final long o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
+ * RDF.li(index), o )
+ */
+ @Override
+ public SecuredSeq set( final int index, final Object o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
+ * RDF.li(index), o )
+ */
+ @Override
+ public SecuredSeq set( final int index, final RDFNode o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
+ * RDF.li(index), o )
+ */
+ @Override
+ public SecuredSeq set( final int index, final String o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update SecTriple( this, RDF.li(index), old ) SecTriple( this,
+ * RDF.li(index), o )
+ */
+ @Override
+ public SecuredSeq set( final int index, final String o, final String l )
+ throws AccessDeniedException;
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredStatement.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredStatement.java b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredStatement.java
new file mode 100644
index 0000000..1f293fa
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/SecuredStatement.java
@@ -0,0 +1,295 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.impl.SecuredItem;
+
+/**
+ * The interface for secured Statement instances.
+ *
+ * Use the SecuredStatement.Factory to create instances
+ */
+public interface SecuredStatement extends Statement, SecuredItem
+{
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeLiteralObject( boolean o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeLiteralObject( char o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeLiteralObject( double o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeLiteralObject( float o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeLiteralObject( int o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeLiteralObject( long o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeObject( RDFNode o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeObject( String o )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeObject( String o, boolean wellFormed )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeObject( String o, String l )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Update
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement changeObject( String o, String l, boolean wellFormed )
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read, Update
+ * @sec.triple Create
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredReifiedStatement createReifiedStatement()
+ throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read, Update
+ * @sec.triple Create
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredReifiedStatement createReifiedStatement( String uri )
+ throws AccessDeniedException;
+
+ @Override
+ public SecuredAlt getAlt();
+
+ @Override
+ public SecuredBag getBag();
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean getBoolean() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public byte getByte() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public char getChar() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public double getDouble() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public float getFloat() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public int getInt() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getLanguage() throws AccessDeniedException;
+
+ @Override
+ public SecuredLiteral getLiteral();
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public long getLong() throws AccessDeniedException;
+
+ @Override
+ public SecuredModel getModel();
+
+ @Override
+ public SecuredRDFNode getObject();
+
+ @Override
+ public SecuredProperty getPredicate();
+
+ @Override
+ public SecuredStatement getProperty( Property p );
+
+ @Override
+ public SecuredResource getResource();
+
+ @Override
+ @Deprecated
+ public SecuredResource getResource( ResourceF f );
+
+ @Override
+ public SecuredSeq getSeq();
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public short getShort() throws AccessDeniedException;
+
+ @Override
+ public SecuredStatement getStatementProperty( Property p );
+
+ /**
+ * @sec.graph Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public String getString() throws AccessDeniedException;
+
+ @Override
+ public SecuredResource getSubject();
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean hasWellFormedXML() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public boolean isReified() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read
+ * @throws AccessDeniedException
+ */
+ @Override
+ public RSIterator listReifiedStatements() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ */
+ @Override
+ public SecuredStatement remove() throws AccessDeniedException;
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Delete
+ * @throws AccessDeniedException
+ */
+ @Override
+ public void removeReification() throws AccessDeniedException;
+
+}
[17/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredStatementImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredStatementImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredStatementImpl.java
new file mode 100644
index 0000000..9981b00
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredStatementImpl.java
@@ -0,0 +1,560 @@
+/*
+ * 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.model.impl;
+
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.impl.ItemHolder ;
+import org.apache.jena.security.impl.SecuredItemImpl ;
+import org.apache.jena.security.impl.SecuredItemInvoker ;
+import org.apache.jena.security.model.* ;
+import org.apache.jena.shared.PropertyNotFoundException ;
+
+/**
+ * Implementation of SecuredStatement to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredStatementImpl extends SecuredItemImpl implements
+ SecuredStatement
+{
+ /**
+ * get a SecuredStatement
+ *
+ * @param securedModel
+ * The secured model that provides the security context
+ * @param stmt
+ * The statement to secure.
+ * @return the SecuredStatement
+ */
+ public static SecuredStatement getInstance(
+ final SecuredModel securedModel, final Statement stmt )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (stmt == null)
+ {
+ throw new IllegalArgumentException("Statement may not be null");
+ }
+
+ final ItemHolder<Statement, SecuredStatement> holder = new ItemHolder<Statement, SecuredStatement>(
+ stmt);
+
+ final SecuredStatementImpl checker = new SecuredStatementImpl(
+ securedModel, holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (stmt instanceof SecuredStatement)
+ {
+ if (checker.isEquivalent((SecuredStatement) stmt))
+ {
+ return (SecuredStatement) stmt;
+ }
+ }
+ return holder.setSecuredItem(new SecuredItemInvoker(holder
+ .getBaseItem().getClass(), checker));
+ }
+
+ // the item holder that contains this SecuredStatement.
+ private final ItemHolder<Statement, SecuredStatement> holder;
+
+ private final SecuredModel securedModel;
+
+ /**
+ * Constructor.
+ *
+ * @param securityEvaluator
+ * The security evaluator to use.
+ * @param graphIRI
+ * the graph IRI to verify against.
+ * @param holder
+ * The item holder that will contain this SecuredStatement.
+ */
+ private SecuredStatementImpl( final SecuredModel securedModel,
+ final ItemHolder<Statement, SecuredStatement> holder )
+ {
+ super(securedModel, holder);
+ this.holder = holder;
+ this.securedModel = securedModel;
+ }
+
+ @Override
+ public Triple asTriple()
+ {
+ checkRead();
+ final Triple retval = holder.getBaseItem().asTriple();
+ checkRead(retval);
+ return retval;
+ }
+
+ @Override
+ public boolean canCreate()
+ {
+ return super.canCreate() ? canCreate(holder.getBaseItem()) : false;
+ }
+
+ @Override
+ public boolean canDelete()
+ {
+ return super.canDelete() ? canDelete(holder.getBaseItem()) : false;
+ }
+
+ @Override
+ public boolean canRead()
+ {
+ return super.canRead() ? canRead(holder.getBaseItem()) : false;
+ }
+
+ @Override
+ public SecuredStatement changeLiteralObject( final boolean o )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = getNewTriple(base, o);
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeLiteralObject(o));
+ }
+
+ @Override
+ public SecuredStatement changeLiteralObject( final char o )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = getNewTriple(base, o);
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeLiteralObject(o));
+ }
+
+ @Override
+ public SecuredStatement changeLiteralObject( final double o )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = getNewTriple(base, o);
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeLiteralObject(o));
+ }
+
+ @Override
+ public SecuredStatement changeLiteralObject( final float o )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = getNewTriple(base, o);
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeLiteralObject(o));
+ }
+
+ @Override
+ public SecuredStatement changeLiteralObject( final int o )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = getNewTriple(base, o);
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeLiteralObject(o));
+ }
+
+ @Override
+ public SecuredStatement changeLiteralObject( final long o )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = getNewTriple(base, o);
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeLiteralObject(o));
+ }
+
+ @Override
+ public SecuredStatement changeObject( final RDFNode o )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = new Triple(base.getSubject(),
+ base.getPredicate(), o.asNode());
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeObject(o));
+ }
+
+ @Override
+ public SecuredStatement changeObject( final String o )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = getNewTriple(base, o);
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeObject(o));
+ }
+
+ @Override
+ public SecuredStatement changeObject( final String o,
+ final boolean wellFormed )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = new Triple(base.getSubject(),
+ base.getPredicate(), NodeFactory.createLiteral(o, "", wellFormed));
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeObject(o));
+ }
+
+ @Override
+ public SecuredStatement changeObject( final String o, final String l )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = new Triple(base.getSubject(),
+ base.getPredicate(), NodeFactory.createLiteral(o, l, false));
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeObject(o, l));
+ }
+
+ @Override
+ public SecuredStatement changeObject( final String o, final String l,
+ final boolean wellFormed )
+ {
+ checkUpdate();
+ final Triple base = holder.getBaseItem().asTriple();
+ final Triple newBase = new Triple(base.getSubject(),
+ base.getPredicate(), NodeFactory.createLiteral(o, l, wellFormed));
+ checkUpdate(base, newBase);
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().changeObject(o, l, wellFormed));
+ }
+
+ @Override
+ public SecuredReifiedStatement createReifiedStatement()
+ {
+ checkUpdate();
+ checkCreateReified(null,
+ SecuredItemImpl.convert(holder.getBaseItem().asTriple()));
+ return SecuredReifiedStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().createReifiedStatement());
+ }
+
+ @Override
+ public SecuredReifiedStatement createReifiedStatement( final String uri )
+ {
+ checkUpdate();
+ checkCreateReified(uri,
+ SecuredItemImpl.convert(holder.getBaseItem().asTriple()));
+ return SecuredReifiedStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().createReifiedStatement(uri));
+ }
+
+ @Override
+ public SecuredAlt getAlt()
+ {
+ return SecuredAltImpl.getInstance(getModel(), holder.getBaseItem()
+ .getAlt());
+ }
+
+ @Override
+ public SecuredBag getBag()
+ {
+ return SecuredBagImpl.getInstance(getModel(), holder.getBaseItem()
+ .getBag());
+ }
+
+ @Override
+ public boolean getBoolean()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getBoolean();
+ }
+
+ @Override
+ public byte getByte()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getByte();
+ }
+
+ @Override
+ public char getChar()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getChar();
+
+ }
+
+ @Override
+ public double getDouble()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getDouble();
+ }
+
+ @Override
+ public float getFloat()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getFloat();
+ }
+
+ @Override
+ public int getInt()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getInt();
+ }
+
+ @Override
+ public String getLanguage()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getLiteral().getLanguage();
+ }
+
+ @Override
+ public SecuredLiteral getLiteral()
+ {
+ return SecuredLiteralImpl.getInstance(getModel(), holder.getBaseItem()
+ .getLiteral());
+ }
+
+ @Override
+ public long getLong()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getLong();
+ }
+
+ @Override
+ public SecuredModel getModel()
+ {
+ return securedModel;
+ }
+
+ private Triple getNewTriple( final Triple t, final Object o )
+ {
+ return new Triple(t.getSubject(), t.getPredicate(),
+ NodeFactory.createLiteral(String.valueOf(o), "", false));
+ }
+
+ @Override
+ public SecuredRDFNode getObject()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ final RDFNode rdfNode = holder.getBaseItem().getObject();
+ return SecuredRDFNodeImpl.getInstance(getModel(), rdfNode);
+
+ }
+
+ @Override
+ public SecuredProperty getPredicate()
+ {
+ return SecuredPropertyImpl.getInstance(getModel(), holder.getBaseItem()
+ .getPredicate());
+ }
+
+ @Override
+ public SecuredStatement getProperty( final Property p )
+ {
+ final StmtIterator s = holder
+ .getBaseItem()
+ .getModel()
+ .listStatements(holder.getBaseItem().getObject().asResource(),
+ p, (RDFNode) null);
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ getModel(), s);
+ try
+ {
+ if (iter.hasNext())
+ {
+ return SecuredStatementImpl
+ .getInstance(getModel(), iter.next());
+ }
+ else
+ {
+ throw new PropertyNotFoundException(p);
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public SecuredResource getResource()
+ {
+ return SecuredResourceImpl.getInstance(getModel(), holder.getBaseItem()
+ .getResource());
+ }
+
+ @Override
+ @Deprecated
+ public SecuredResource getResource( final ResourceF f )
+ {
+ return SecuredResourceImpl.getInstance(getModel(), holder.getBaseItem()
+ .getResource(f));
+ }
+
+ @Override
+ public SecuredSeq getSeq()
+ {
+ return SecuredSeqImpl.getInstance(getModel(), holder.getBaseItem()
+ .getSeq());
+ }
+
+ @Override
+ public short getShort()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getShort();
+ }
+
+ @Override
+ public SecuredStatement getStatementProperty( final Property p )
+ {
+ final RSIterator rsIter = holder.getBaseItem().listReifiedStatements();
+ try
+ {
+ while (rsIter.hasNext())
+ {
+ final ReifiedStatement s = rsIter.next();
+ if (s.hasProperty(p))
+ {
+ return SecuredStatementImpl.getInstance(getModel(),
+ s.getProperty(p));
+ }
+ }
+ throw new PropertyNotFoundException(p);
+ }
+ finally
+ {
+ rsIter.close();
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ if (canRead() && canRead(holder.getBaseItem().asTriple()))
+ {
+ return holder.getBaseItem().toString();
+ }
+ else
+ {
+ return super.toString();
+ }
+ }
+
+ @Override
+ public String getString()
+ { return getLiteral().getLexicalForm(); }
+
+ @Override
+ public SecuredResource getSubject()
+ {
+ return SecuredResourceImpl.getInstance(getModel(), holder.getBaseItem()
+ .getSubject());
+ }
+
+ @Override
+ public boolean hasWellFormedXML()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().getLiteral().isWellFormedXML();
+ }
+
+ @Override
+ public boolean isReified()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return holder.getBaseItem().isReified();
+ }
+
+ @Override
+ public RSIterator listReifiedStatements()
+ {
+ checkRead();
+ checkRead(holder.getBaseItem().asTriple());
+ return new SecuredRSIterator(getModel(), holder.getBaseItem()
+ .listReifiedStatements());
+ }
+
+ @Override
+ public SecuredStatement remove()
+ {
+ checkUpdate();
+ checkDelete(holder.getBaseItem());
+ holder.getBaseItem().remove();
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public void removeReification()
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ StmtIterator iter = null;
+ final RSIterator rsIter = holder.getBaseItem()
+ .listReifiedStatements();
+ try
+ {
+ while (rsIter.hasNext())
+ {
+ final ReifiedStatement stmt = rsIter.next();
+ iter = stmt.listProperties();
+ while (iter.hasNext())
+ {
+ final Statement s = iter.next();
+ checkDelete(s);
+ }
+ }
+ }
+ finally
+ {
+ rsIter.close();
+ if (iter != null)
+ {
+ iter.close();
+ }
+ }
+ }
+ holder.getBaseItem().removeReification();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredStatementIterator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredStatementIterator.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredStatementIterator.java
new file mode 100644
index 0000000..6066da7
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredStatementIterator.java
@@ -0,0 +1,148 @@
+/*
+ * 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.model.impl;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import org.apache.jena.rdf.model.Statement ;
+import org.apache.jena.rdf.model.StmtIterator ;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredStatement;
+import org.apache.jena.security.utils.PermStatementFilter;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.Filter ;
+import org.apache.jena.util.iterator.Map1 ;
+
+/**
+ * A secured StatementIterator implementation
+ */
+public class SecuredStatementIterator implements StmtIterator
+{
+
+ private class PermStatementMap implements Map1<Statement, Statement>
+ {
+ private final SecuredModel securedModel;
+
+ public PermStatementMap( final SecuredModel securedModel )
+ {
+ this.securedModel = securedModel;
+ }
+
+ @Override
+ public SecuredStatement map1( final Statement o )
+ {
+ return SecuredStatementImpl.getInstance(securedModel, o);
+ }
+ }
+
+ private final ExtendedIterator<Statement> iter;
+
+ /**
+ * Constructor.
+ *
+ * @param securedModel
+ * The item providing the security context.
+ * @param wrapped
+ * The iterator to wrap.
+ */
+ public SecuredStatementIterator( final SecuredModel securedModel,
+ final ExtendedIterator<Statement> wrapped )
+ {
+ final PermStatementFilter filter = new PermStatementFilter(
+ new Action[] { Action.Read }, securedModel);
+ final PermStatementMap map1 = new PermStatementMap(securedModel);
+ iter = wrapped.filterKeep(filter).mapWith(map1);
+ }
+
+ @Override
+ public <X extends Statement> ExtendedIterator<Statement> andThen(
+ final Iterator<X> other )
+ {
+ return iter.andThen(other);
+ }
+
+ @Override
+ public void close()
+ {
+ iter.close();
+ }
+
+ @Override
+ public ExtendedIterator<Statement> filterDrop( final Filter<Statement> f )
+ {
+ return iter.filterDrop(f);
+ }
+
+ @Override
+ public ExtendedIterator<Statement> filterKeep( final Filter<Statement> f )
+ {
+ return iter.filterKeep(f);
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return iter.hasNext();
+ }
+
+ @Override
+ public <U> ExtendedIterator<U> mapWith( final Map1<Statement, U> map1 )
+ {
+ return iter.mapWith(map1);
+ }
+
+ @Override
+ public Statement next()
+ {
+ return iter.next();
+ }
+
+ @Override
+ public Statement nextStatement() throws NoSuchElementException
+ {
+ return next();
+ }
+
+ @Override
+ public void remove()
+ {
+ iter.remove();
+ }
+
+ @Override
+ public Statement removeNext()
+ {
+ return iter.removeNext();
+ }
+
+ @Override
+ public List<Statement> toList()
+ {
+ return iter.toList();
+ }
+
+ @Override
+ public Set<Statement> toSet()
+ {
+ return iter.toSet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/package-info.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/package-info.java b/jena-permissions/src/main/java/org/apache/jena/security/package-info.java
new file mode 100644
index 0000000..359dc3b
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/package-info.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+/**
+ * JenaSecurity is a SecurityEvaluator interface and a set of dynamic proxies that apply that
+ * interface to Jena Graphs, Models, and associated methods and classes.
+ * <p>
+ * The SecurityEvaluator class must be implemented. This class provides the interface to the
+ * authentication results (e.g. <code>getPrincipal()</code>) and the authorization system.
+ * </p><p>
+ * <ul>
+ * <li>
+ * Create a SecuredGraph by calling <code>Factory.getInstance( SecurityEvaluator, String, Graph );</code>
+ * </li><li>
+ * Create a SecuredModel by calling <code>Factory.getInstance( SecurityEvaluator, String, Model )</code>
+ * </li><li>
+ * It is not recommended that you create a model by calling the Jena <code>ModelFactory.createModelForGraph( SecuredGraph )</code>
+ * See Overview for discussion.
+ * </li>
+ * </ul>
+ * </p><p>
+ * <em>NOTES:</em>
+ * <ul>
+ * <li>See SecurityEvaluator documentation for description of cascading security checks</li>
+ * <li>Secured methods are annotated with:
+ * @sec.graph for permissions required on the graph to execute the method.
+ * @sec.triple for permissions required on the associated triples (if any) to execute the method.
+ * </li>
+ * <li>It is possible to implement a SecurityEvaluator that does not enforce security at the triple
+ * level. See SecurityEvaluator documentation for details</li>
+ * </ul>
+ * </p>
+ */
+package org.apache.jena.security;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngine.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngine.java b/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngine.java
new file mode 100644
index 0000000..1afec86
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngine.java
@@ -0,0 +1,152 @@
+/*
+ * 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.query;
+
+import java.security.Principal;
+import java.util.Set;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.query.Query ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
+import org.apache.jena.security.graph.SecuredGraph;
+import org.apache.jena.security.query.rewriter.OpRewriter;
+import org.apache.jena.sparql.algebra.Op ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.engine.main.QueryEngineMain ;
+import org.apache.jena.sparql.util.Context ;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SecuredQueryEngine extends QueryEngineMain
+{
+ private static Logger LOG = LoggerFactory
+ .getLogger(SecuredQueryEngine.class);
+
+ private SecurityEvaluator securityEvaluator;
+ private SecNode graphIRI;
+
+ /*
+ * public SecuredQueryEngine( Op op, DatasetGraph dataset, Binding input,
+ * Context context )
+ * {
+ * super(op, dataset, input, context);
+ * setGraphIRI( dataset );
+ * }
+ */
+ public SecuredQueryEngine( final Query query, final DatasetGraph dataset,
+ final Binding input, final Context context )
+ {
+ super(query, dataset, input, context);
+ setGraphIRI(dataset);
+ }
+
+ public SecurityEvaluator getSecurityEvaluator()
+ {
+ return securityEvaluator;
+ }
+
+ @Override
+ protected Op modifyOp( final Op op )
+ {
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
+ SecuredQueryEngine.LOG.debug("Before: {}", op);
+ op.visit(rewriter);
+ Op result = rewriter.getResult();
+ result = result == null ? op : result;
+ SecuredQueryEngine.LOG.debug("After: {}", result);
+ result = super.modifyOp(result);
+ SecuredQueryEngine.LOG.debug("After Optimize: {}", result);
+ return result;
+ }
+
+ 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 = new SecNode(Type.URI, "urn:x-arq:DefaultGraph");
+ this.securityEvaluator = new SecurityEvaluator() {
+
+ @Override
+ public boolean evaluate( final Object principal, final Action action,
+ final SecNode graphIRI )
+ {
+ return true;
+ }
+
+ @Override
+ public boolean evaluate( final Object principal, final Action action,
+ final SecNode graphIRI, final SecTriple triple )
+ {
+ return true;
+ }
+
+ @Override
+ public boolean evaluate( final Object principal, final Set<Action> action,
+ final SecNode graphIRI )
+ {
+ return true;
+ }
+
+ @Override
+ public boolean evaluate( final Object principal, final Set<Action> action,
+ final SecNode graphIRI, final SecTriple triple )
+ {
+ return true;
+ }
+
+ @Override
+ public boolean evaluateAny( final Object principal, final Set<Action> action,
+ final SecNode graphIRI )
+ {
+ return true;
+ }
+
+ @Override
+ public boolean evaluateAny( final Object principal, final Set<Action> action,
+ final SecNode graphIRI, final SecTriple triple )
+ {
+ return true;
+ }
+
+ @Override
+ public boolean evaluateUpdate( final Object principal, final SecNode graphIRI,
+ final SecTriple from, final SecTriple to )
+ {
+ return true;
+ }
+
+ @Override
+ public Principal getPrincipal()
+ {
+ return null;
+ }
+ };
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngineConfig.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngineConfig.java b/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngineConfig.java
new file mode 100644
index 0000000..479814b
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngineConfig.java
@@ -0,0 +1,29 @@
+/*
+ * 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.query;
+
+import org.apache.jena.sparql.util.Context ;
+
+public class SecuredQueryEngineConfig
+{
+
+ public void initializeContext(Context context)
+ {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngineFactory.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngineFactory.java b/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngineFactory.java
new file mode 100644
index 0000000..41988b2
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/query/SecuredQueryEngineFactory.java
@@ -0,0 +1,115 @@
+/*
+ * 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.query;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.query.Query ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.graph.SecuredGraph;
+import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.sparql.algebra.Op ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.engine.Plan ;
+import org.apache.jena.sparql.engine.QueryEngineFactory ;
+import org.apache.jena.sparql.engine.QueryEngineRegistry ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.util.Context ;
+
+public class SecuredQueryEngineFactory implements QueryEngineFactory
+{
+ private boolean silentService = true;
+ private SecuredQueryEngineConfig cfgResource;
+ private SecurityEvaluator securityEvaluator;
+
+ private static SecuredQueryEngineFactory factory = new SecuredQueryEngineFactory();
+
+ static public SecuredQueryEngineFactory getFactory() {
+ return factory;
+ }
+
+ static public void register() {
+ QueryEngineRegistry.addFactory(factory);
+ }
+
+ static public void unregister() {
+ QueryEngineRegistry.removeFactory(factory);
+ }
+
+ public SecurityEvaluator getSecurityEvaluator() {
+ return securityEvaluator;
+ }
+
+ public void setSecurityEvaluator(SecurityEvaluator securityEvaluator) {
+ this.securityEvaluator = securityEvaluator;
+ }
+
+ public boolean isSilentService() {
+ return silentService;
+ }
+
+ public void setSilentService(boolean silentService) {
+ this.silentService = silentService;
+ }
+
+ public void setSecuredQueryEngineConfig(SecuredQueryEngineConfig cfgResource) {
+ this.cfgResource = cfgResource;
+
+ }
+
+ /**
+ * Only accept a secured dataset
+ */
+ @Override
+ public boolean accept(Query query, DatasetGraph dataset, Context context) {
+ Graph g = dataset.getDefaultGraph();
+ return g instanceof SecuredGraph;
+ }
+
+ @Override
+ public Plan create(Query query, DatasetGraph dataset, Binding initial,
+ Context context) {
+ // set up the context
+ if (cfgResource != null) {
+ cfgResource.initializeContext( context );
+ }
+
+ // Create a query engine instance.
+ SecuredQueryEngine engine = new SecuredQueryEngine(query, dataset,
+ initial, context);
+ return engine.getPlan();
+ }
+
+ @Override
+ public boolean accept(Op op, DatasetGraph dataset, Context context) { // Refuse
+ // to
+ // accept
+ // algebra
+ // expressions
+ // directly.
+ return false;
+ }
+
+ @Override
+ public Plan create(Op op, DatasetGraph dataset, Binding inputBinding,
+ Context context) { // Should not be called because acceept/Op is
+ // false
+ throw new ARQInternalErrorException(this.getClass().getSimpleName()
+ + ": factory called directly with an algebra expression");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/query/rewriter/OpRewriter.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/query/rewriter/OpRewriter.java b/jena-permissions/src/main/java/org/apache/jena/security/query/rewriter/OpRewriter.java
new file mode 100644
index 0000000..1cd59c1
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/query/rewriter/OpRewriter.java
@@ -0,0 +1,592 @@
+/*
+ * 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.query.rewriter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.SecurityEvaluator.SecTriple;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.sparql.algebra.Op ;
+import org.apache.jena.sparql.algebra.OpVisitor ;
+import org.apache.jena.sparql.algebra.op.* ;
+import org.apache.jena.sparql.core.BasicPattern ;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class rewrites the query by examining each operation in the algebra
+ * returned by the Jena SPARQL parser.
+ * <p>
+ * This implementation inserts security evaluator checks where necessary.
+ * </p>
+ */
+public class OpRewriter implements OpVisitor
+{
+ private static Logger LOG = LoggerFactory.getLogger(OpRewriter.class);
+ private OpSequence result;
+ private final SecNode graphIRI;
+ private final SecurityEvaluator securityEvaluator;
+ // if true the restricted data are silently ignored.
+ // default false
+ private final boolean silentFail;
+
+ /**
+ * Constructor
+ * @param securityEvaluator The security evaluator to use
+ * @param graphIRI The IRI for the default graph.
+ */
+ public OpRewriter( final SecurityEvaluator securityEvaluator,
+ final SecNode graphIRI )
+ {
+ this.securityEvaluator = securityEvaluator;
+ this.graphIRI = graphIRI;
+ this.silentFail = false;
+ reset();
+ }
+
+ /**
+ * Constructor
+ * @param securityEvaluator The security evaluator to use
+ * @param graphIRI The IRI for the default graph.
+ */
+ public OpRewriter( final SecurityEvaluator securityEvaluator,
+ final String graphIRI )
+ {
+ this(securityEvaluator, new SecNode(SecNode.Type.URI, graphIRI));
+ }
+
+ /**
+ * Add the operation to the result.
+ * @param op the operation to add.
+ */
+ private void addOp( final Op op )
+ {
+ result.add(op);
+ }
+
+ /**
+ * Get the result of the rewrite.
+ * @return the resulting operator
+ */
+ public Op getResult()
+ {
+ if (result.size() == 0)
+ {
+ return OpNull.create();
+ }
+ if (result.size() == 1)
+ {
+ return result.get(0);
+ }
+ return result;
+
+ }
+
+ /**
+ * Register variables.
+ *
+ * Registers n as a variable if it is one.
+ *
+ * @param n the node to check
+ * @param variables the list of variable nodes
+ * @Return n for chaining.
+ */
+ private Node registerVariables( final Node n, final List<Node> variables )
+ {
+ if (n.isVariable() && !variables.contains(n))
+ {
+ variables.add(n);
+ }
+ return n;
+ }
+
+ /**
+ * Reset the rewriter to the initial state.
+ * @return this rewriter for chaining.
+ */
+ public OpRewriter reset()
+ {
+ result = OpSequence.create();
+ return this;
+ }
+
+ /**
+ * Register all the variables in the triple.
+ * @param t the triple to register.
+ * @param variables The list of variables.
+ * @return t for chaining
+ */
+ private Triple registerBGPTriple( final Triple t,
+ final List<Node> variables )
+ {
+ registerVariables(t.getSubject(), variables);
+ registerVariables(t.getPredicate(), variables);
+ registerVariables(t.getObject(), variables);
+ return t;
+ }
+
+ /**
+ * Rewrites the subop of op1 and returns the result.
+ *
+ * @param op1
+ * @return the rewritten op.
+ */
+ private Op rewriteOp1( final Op1 op1 )
+ {
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
+ op1.getSubOp().visit(rewriter);
+ return rewriter.getResult();
+ }
+
+ /**
+ * rewrites the left and right parts of the op2 the left part is
+ * returned the right part is placed in the rewriter
+ *
+ * @param op2
+ * @param rewriter
+ * @return the rewritten op.
+ */
+ private Op rewriteOp2( final Op2 op2, final OpRewriter rewriter )
+ {
+ op2.getLeft().visit(rewriter.reset());
+ final Op left = rewriter.getResult();
+ op2.getRight().visit(rewriter.reset());
+ return left;
+ }
+
+ /**
+ * rewrite source to dest and returns dest
+ *
+ * @param source
+ * @param dest
+ * @return the rewritten op.
+ */
+ private OpN rewriteOpN( final OpN source, final OpN dest )
+ {
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
+ for (final Op o : source.getElements())
+ {
+ o.visit(rewriter.reset());
+ dest.add(rewriter.getResult());
+ }
+ return dest;
+ }
+
+ /**
+ * rewrites the subop of assign.
+ */
+ @Override
+ public void visit( final OpAssign opAssign )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpAssign"); }
+ addOp(OpAssign.assign(rewriteOp1(opAssign), opAssign.getVarExprList()));
+ }
+
+ @Override
+ public void visit( final OpBGP opBGP )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpBGP"); }
+ Object principal = securityEvaluator.getPrincipal();
+ if (!securityEvaluator.evaluate(principal, Action.Read, graphIRI))
+ {
+ if (silentFail)
+ {
+ return;
+ }
+ else
+ {
+ throw new AccessDeniedException(graphIRI, Action.Read);
+ }
+ }
+
+ // if the user can read any triple just add the opBGP
+ if (securityEvaluator.evaluate(principal, Action.Read, graphIRI, SecTriple.ANY))
+ {
+ addOp(opBGP);
+ }
+ else
+ {
+ // add security filtering to the resulting triples
+ final List<Triple> newBGP = new ArrayList<Triple>();
+ final List<Node> variables = new ArrayList<Node>();
+ // register all variables
+ for (final Triple t : opBGP.getPattern().getList())
+ {
+ newBGP.add(registerBGPTriple(t, variables));
+ }
+ // create the security function.
+ final SecuredFunction secFunc = new SecuredFunction(graphIRI,
+ securityEvaluator, variables, newBGP);
+ // create the filter
+ Op filter = OpFilter.filter(secFunc, new OpBGP(BasicPattern.wrap(newBGP)));
+ // add the filter
+ addOp(filter);
+ }
+ }
+
+ /**
+ * Rewrite left and right
+ */
+ @Override
+ public void visit( final OpConditional opCondition )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpConditional"); }
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
+ addOp(new OpConditional(rewriteOp2(opCondition, rewriter),
+ rewriter.getResult()));
+ }
+
+ /**
+ * returns the dsNames
+ */
+ @Override
+ public void visit( final OpDatasetNames dsNames )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpDatasetName"); }
+ addOp(dsNames);
+ }
+
+ /**
+ * Rewrite left and right
+ */
+ @Override
+ public void visit( final OpDiff opDiff )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpDiff"); }
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
+ addOp(OpDiff.create(rewriteOp2(opDiff, rewriter), rewriter.getResult()));
+ }
+
+ /**
+ * Rewrite sequence elements
+ */
+ @Override
+ public void visit( final OpDisjunction opDisjunction )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpDisjunction"); }
+ addOp(rewriteOpN(opDisjunction, OpDisjunction.create()));
+ }
+
+ /**
+ * rewrites the subop of distinct
+ */
+ @Override
+ public void visit( final OpDistinct opDistinct )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpDistinct"); }
+ addOp(new OpDistinct(rewriteOp1(opDistinct)));
+ }
+
+ /**
+ * Returns the Ext
+ */
+ @Override
+ public void visit( final OpExt opExt )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpExt"); }
+ addOp(opExt);
+ }
+
+ /**
+ * rewrites the subop of extend.
+ */
+ @Override
+ public void visit( final OpExtend opExtend )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpExtend"); }
+ addOp(OpExtend.extend(rewriteOp1(opExtend), opExtend.getVarExprList()));
+ }
+
+ /**
+ * rewrites the subop of filter.
+ */
+ @Override
+ public void visit( final OpFilter opFilter )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpFilter"); }
+ addOp(OpFilter.filter(opFilter.getExprs(), rewriteOp1(opFilter)));
+ }
+
+ /**
+ * rewrites the subop of graph.
+ */
+ @Override
+ public void visit( final OpGraph opGraph )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpGraph"); }
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator,
+ SecuredItemImpl.convert(opGraph.getNode()));
+ opGraph.getSubOp().visit(rewriter);
+ addOp(new OpGraph(opGraph.getNode(), rewriter.getResult()));
+ }
+
+ /**
+ * rewrites the subop of group.
+ */
+ @Override
+ public void visit( final OpGroup opGroup )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpGroup"); }
+ addOp(new OpGroup(rewriteOp1(opGroup), opGroup.getGroupVars(),
+ opGroup.getAggregators()));
+ }
+
+ /**
+ * Parses the joins and recursively calls the left and right parts
+ */
+ @Override
+ public void visit( final OpJoin opJoin )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpJoin"); }
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
+ addOp(OpJoin.create(rewriteOp2(opJoin, rewriter), rewriter.getResult()));
+ }
+
+ /**
+ * returns the label
+ */
+ @Override
+ public void visit( final OpLabel opLabel )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpLabel"); }
+ addOp(opLabel);
+ }
+
+ /**
+ * Parses the joins and recursively calls the left and right parts
+ */
+ @Override
+ public void visit( final OpLeftJoin opLeftJoin )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpLeftJoin"); }
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
+ addOp(OpLeftJoin.create(rewriteOp2(opLeftJoin, rewriter),
+ rewriter.getResult(), opLeftJoin.getExprs()));
+ }
+
+ /**
+ * rewrites the subop of list.
+ */
+ @Override
+ public void visit( final OpList opList )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpList"); }
+ addOp(new OpList(rewriteOp1(opList)));
+ }
+
+ /**
+ * Rewrite left and right
+ */
+ @Override
+ public void visit( final OpMinus opMinus )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpMinus"); }
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
+ addOp(OpMinus.create(rewriteOp2(opMinus, rewriter),
+ rewriter.getResult()));
+ }
+
+ /**
+ * returns the null
+ */
+ @Override
+ public void visit( final OpNull opNull )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpNull"); }
+ addOp(opNull);
+ }
+
+ /**
+ * rewrites the subop of order.
+ */
+ @Override
+ public void visit( final OpOrder opOrder )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpOrder"); }
+ addOp(new OpOrder(rewriteOp1(opOrder), opOrder.getConditions()));
+ }
+
+ /**
+ * Returns the path
+ */
+ @Override
+ public void visit( final OpPath opPath )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpPath"); }
+ addOp(opPath);
+ }
+
+ /**
+ * rewrites the subop of proc.
+ */
+ @Override
+ public void visit( final OpProcedure opProc )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpProc"); }
+ if (opProc.getProcId() != null)
+ {
+ addOp(new OpProcedure(opProc.getProcId(), opProc.getArgs(),
+ rewriteOp1(opProc)));
+ }
+ else
+ {
+ addOp(new OpProcedure(opProc.getURI(), opProc.getArgs(),
+ rewriteOp1(opProc)));
+ }
+ }
+
+ /**
+ * rewrites the subop of project.
+ */
+ @Override
+ public void visit( final OpProject opProject )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpProject"); }
+ addOp(new OpProject(rewriteOp1(opProject), opProject.getVars()));
+ }
+
+ /**
+ * rewrites the subop of propFunc.
+ */
+ @Override
+ public void visit( final OpPropFunc opPropFunc )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpPropFunc"); }
+ addOp(new OpPropFunc(opPropFunc.getProperty(),
+ opPropFunc.getSubjectArgs(), opPropFunc.getObjectArgs(),
+ rewriteOp1(opPropFunc)));
+ }
+
+ /**
+ * Returns the quad
+ */
+ @Override
+ public void visit( final OpQuad opQuad )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpQuad"); }
+ addOp(opQuad);
+ }
+
+ /**
+ * Returns the quadpattern
+ */
+ @Override
+ public void visit( final OpQuadPattern quadPattern )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpQuadPattern"); }
+ addOp(quadPattern);
+ }
+
+ /**
+ * rewrites the subop of reduced.
+ */
+ @Override
+ public void visit( final OpReduced opReduced )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpReduced"); }
+ addOp(OpReduced.create(rewriteOp1(opReduced)));
+ }
+
+ /**
+ * Rewrite sequence elements
+ */
+ @Override
+ public void visit( final OpSequence opSequence )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpSequence"); }
+ addOp(rewriteOpN(opSequence, OpSequence.create()));
+ }
+
+ /**
+ * returns the service
+ */
+ @Override
+ public void visit( final OpService opService )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting opService"); }
+ addOp(opService);
+ }
+
+ /**
+ * rewrites the subop of slice
+ *
+ * This also handles the limit case
+ */
+ @Override
+ public void visit( final OpSlice opSlice )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpSlice"); }
+ addOp(opSlice);
+ }
+
+ /**
+ * returns the table
+ */
+ @Override
+ public void visit( final OpTable opTable )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpTable"); }
+ addOp(opTable);
+ }
+
+ /**
+ * rewrites the subop of top.
+ */
+ @Override
+ public void visit( final OpTopN opTop )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpTop"); }
+ addOp(new OpTopN(rewriteOp1(opTop), opTop.getLimit(),
+ opTop.getConditions()));
+ }
+
+ /**
+ * Converts to BGP
+ */
+ @Override
+ public void visit( final OpTriple opTriple )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpTriple"); }
+ visit(opTriple.asBGP());
+ }
+
+ /**
+ * Rewrite left and right
+ */
+ @Override
+ public void visit( final OpUnion opUnion )
+ {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpUnion"); }
+ final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
+ addOp(OpUnion.create(rewriteOp2(opUnion, rewriter),
+ rewriter.getResult()));
+ }
+
+ @Override
+ public void visit(OpQuadBlock quadBlock) {
+ if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpQuadBlock"); }
+ addOp(quadBlock);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/query/rewriter/SecuredFunction.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/query/rewriter/SecuredFunction.java b/jena-permissions/src/main/java/org/apache/jena/security/query/rewriter/SecuredFunction.java
new file mode 100644
index 0000000..b765061
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/query/rewriter/SecuredFunction.java
@@ -0,0 +1,138 @@
+/*
+ * 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.query.rewriter;
+
+import java.util.List;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.SecurityEvaluator.SecTriple;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.expr.* ;
+import org.apache.jena.sparql.function.FunctionEnv ;
+import org.apache.jena.sparql.graph.NodeTransform ;
+
+public class SecuredFunction extends ExprFunctionN
+{
+ private final SecurityEvaluator securityEvaluator;
+ private final List<Node> variables;
+ private final List<Triple> bgp;
+ private final SecNode graphIRI;
+
+ private static ExprList createArgs( List<Node> variables )
+ {
+ ExprList retval = new ExprList();
+ for (Node n : variables )
+ {
+ retval.add( new ExprVar( n ));
+ }
+ return retval;
+ }
+
+ public SecuredFunction( final SecNode graphIRI,
+ final SecurityEvaluator securityEvaluator,
+ final List<Node> variables, final List<Triple> bgp )
+ {
+ super(String.format("<java:%s>", SecuredFunction.class.getName() ), createArgs( variables));
+ //,
+ // new ElementTriplesBlock( BasicPattern.wrap(bgp) ),
+ // new OpBGP( BasicPattern.wrap(bgp) )
+ // );
+ this.securityEvaluator = securityEvaluator;
+ this.variables = variables;
+ this.bgp = bgp;
+ this.graphIRI = graphIRI;
+ }
+
+ private boolean checkAccess( Binding values )
+ {
+ Object principal = securityEvaluator.getPrincipal();
+ for (final Triple t : bgp)
+ {
+ final SecTriple secT = createSecTriple(t, values);
+ if (!securityEvaluator.evaluate(principal, Action.Read, graphIRI, secT))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private SecTriple createSecTriple( final Triple t, final Binding values )
+ {
+ int idx = variables.indexOf(t.getSubject());
+
+ final SecNode s = SecuredItemImpl.convert(idx ==-1 ? t.getSubject()
+ : values.get(Var.alloc( variables.get(idx))));
+
+ idx = variables.indexOf(t.getPredicate());
+ final SecNode p = SecuredItemImpl.convert(idx == -1 ? t
+ .getPredicate()
+ : values.get(Var.alloc( variables.get(idx))));
+ idx = variables.indexOf(t.getObject());
+ final SecNode o = SecuredItemImpl.convert(idx == -1 ? t.getObject()
+ : values.get(Var.alloc( variables.get(idx))));
+ return new SecTriple(s, p, o);
+ }
+
+
+ @Override
+ public Expr copySubstitute( Binding binding )
+ {
+ return this;
+ }
+
+ @Override
+ public Expr applyNodeTransform( NodeTransform transform )
+ {
+ return this;
+ }
+
+ @Override
+ public void visit( ExprVisitor visitor )
+ {
+ visitor.visit( this );
+ }
+
+ @Override
+ public NodeValue eval( List<NodeValue> args )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Expr copy( ExprList newArgs )
+ {
+ return this;
+ }
+
+ @Override
+ protected NodeValue evalSpecial( Binding binding, FunctionEnv env )
+ {
+ return NodeValue.booleanReturn( checkAccess( binding ));
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/utils/ContainerFilter.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/utils/ContainerFilter.java b/jena-permissions/src/main/java/org/apache/jena/security/utils/ContainerFilter.java
new file mode 100644
index 0000000..d49792f
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/utils/ContainerFilter.java
@@ -0,0 +1,48 @@
+/*
+ * 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.utils;
+
+import org.apache.jena.rdf.model.Property ;
+import org.apache.jena.rdf.model.Statement ;
+import org.apache.jena.util.iterator.Filter ;
+import org.apache.jena.vocabulary.RDF ;
+
+public class ContainerFilter extends Filter<Statement>
+{
+
+ @Override
+ public boolean accept( final Statement o )
+ {
+ final Property p = o.getPredicate();
+ if (p.getNameSpace().equals(RDF.getURI())
+ && p.getLocalName().startsWith("_"))
+ {
+ try
+ {
+ Integer.parseInt(p.getLocalName().substring(1));
+ return true;
+ }
+ catch (final NumberFormatException e)
+ {
+ // acceptable;
+ }
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/utils/PermStatementFilter.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/utils/PermStatementFilter.java b/jena-permissions/src/main/java/org/apache/jena/security/utils/PermStatementFilter.java
new file mode 100644
index 0000000..b2217a1
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/utils/PermStatementFilter.java
@@ -0,0 +1,164 @@
+/*
+ * 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.utils;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.jena.rdf.model.Statement ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.impl.SecuredItem;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.util.iterator.Filter ;
+
+/**
+ * A filter for to filter ExtendedIterators on Statements.
+ * This filter removes any triple that the user can not perform all
+ * the actions on.
+ */
+public class PermStatementFilter extends Filter<Statement>
+{
+ private final SecurityEvaluator evaluator;
+ private final SecNode modelNode;
+ private final Set<Action> actions;
+ private final Object principal;
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param action
+ * The action the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ */
+ public PermStatementFilter( final Action action,
+ final SecuredItem securedItem )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(new Action[] { action });
+ this.evaluator = securedItem.getSecurityEvaluator();
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param action
+ * The action the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ * @param evaluator
+ * The security evaluator to evaluate the security queries.
+ */
+ public PermStatementFilter( final Action action,
+ final SecuredItem securedItem, final SecurityEvaluator evaluator )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(new Action[] { action });
+ this.evaluator = evaluator;
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param actions
+ * The actions the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ */
+ public PermStatementFilter( final Action[] actions,
+ final SecuredItem securedItem )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(actions);
+ this.evaluator = securedItem.getSecurityEvaluator();
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param actions
+ * The actions the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ * @param evaluator
+ * The security evaluator to evaluate the security queries.
+ */
+ public PermStatementFilter( final Action[] actions,
+ final SecuredItem securedItem, final SecurityEvaluator evaluator )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(actions);
+ this.evaluator = evaluator;
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param actions
+ * The actions the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ */
+ public PermStatementFilter( final Collection<Action> actions,
+ final SecuredItem securedItem )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(actions);
+ this.evaluator = securedItem.getSecurityEvaluator();
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param actions
+ * The actions the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ * @param evaluator
+ * The security evaluator to evaluate the security queries.
+ */
+ public PermStatementFilter( final Collection<Action> actions,
+ final SecuredItem securedItem, final SecurityEvaluator evaluator )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(actions);
+ this.evaluator = evaluator;
+ this.principal = evaluator.getPrincipal();
+ }
+
+ @Override
+ public boolean accept( final Statement s )
+ {
+ return evaluator.evaluateAny(principal, actions, modelNode,
+ SecuredItemImpl.convert(s.asTriple()));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/utils/PermTripleFilter.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/utils/PermTripleFilter.java b/jena-permissions/src/main/java/org/apache/jena/security/utils/PermTripleFilter.java
new file mode 100644
index 0000000..5f6cfa1
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/utils/PermTripleFilter.java
@@ -0,0 +1,163 @@
+/*
+ * 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.utils;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.impl.SecuredItem;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.util.iterator.Filter ;
+
+/**
+ * A filter for to filter ExtendedIterators on Triples.
+ * This filter removes any triple that the user can not perform all
+ * the actions on.
+ */
+public class PermTripleFilter extends Filter<Triple>
+{
+ private final SecurityEvaluator evaluator;
+ private final SecNode modelNode;
+ private final Set<Action> actions;
+ private final Object principal;
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param action
+ * The action the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ */
+ public PermTripleFilter( final Action action, final SecuredItem securedItem )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(new Action[] { action });
+ this.evaluator = securedItem.getSecurityEvaluator();
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param action
+ * The action the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ * @param evaluator
+ * The security evaluator to evaluate the security queries.
+ */
+ public PermTripleFilter( final Action action,
+ final SecuredItem securedItem, final SecurityEvaluator evaluator )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(new Action[] { action });
+ this.evaluator = evaluator;
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param actions
+ * The actions the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ */
+ public PermTripleFilter( final Action[] actions,
+ final SecuredItem securedItem )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(actions);
+ this.evaluator = securedItem.getSecurityEvaluator();
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param actions
+ * The actions the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ * @param evaluator
+ * The security evaluator to evaluate the security queries.
+ */
+ public PermTripleFilter( final Action[] actions,
+ final SecuredItem securedItem, final SecurityEvaluator evaluator )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(actions);
+ this.evaluator = evaluator;
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param actions
+ * The actions the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ */
+ public PermTripleFilter( final Collection<Action> actions,
+ final SecuredItem securedItem )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(actions);
+ this.evaluator = securedItem.getSecurityEvaluator();
+ this.principal = evaluator.getPrincipal();
+ }
+
+ /**
+ * Creates a filter that requires that the user have all the permissions
+ * listed in the actions parameter
+ *
+ * @param actions
+ * The actions the user must be permitted to perform.
+ * @param securedItem
+ * The secured item that secures this iterator.
+ * @param evaluator
+ * The security evaluator to evaluate the security queries.
+ */
+ public PermTripleFilter( final Collection<Action> actions,
+ final SecuredItem securedItem, final SecurityEvaluator evaluator )
+ {
+ this.modelNode = securedItem.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(actions);
+ this.evaluator = evaluator;
+ this.principal = evaluator.getPrincipal();
+ }
+
+ @Override
+ public boolean accept( final Triple t )
+ {
+ return evaluator.evaluateAny(principal, actions, modelNode,
+ SecuredItemImpl.convert(t));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/utils/RDFListIterator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/utils/RDFListIterator.java b/jena-permissions/src/main/java/org/apache/jena/security/utils/RDFListIterator.java
new file mode 100644
index 0000000..9c86b95
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/utils/RDFListIterator.java
@@ -0,0 +1,79 @@
+/*
+ * 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.utils;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.jena.rdf.model.RDFList ;
+import org.apache.jena.vocabulary.RDF ;
+
+public class RDFListIterator implements Iterator<RDFList>
+{
+ private RDFList current;
+ private Boolean found;
+
+ public RDFListIterator( final RDFList start )
+ {
+ this.current = start;
+ }
+
+ private boolean endOfList()
+ {
+ return current.equals(RDF.nil);
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ if ((found == null) && !endOfList())
+ {
+ found = !endOfList();
+ }
+ return found == null ? false : found;
+ }
+
+ private void incrementCurrent()
+ {
+ if (!endOfList())
+ {
+ current = current.getRequiredProperty(RDF.rest).getResource()
+ .as(RDFList.class);
+ }
+ }
+
+ @Override
+ public RDFList next()
+ {
+ if (hasNext())
+ {
+ found = null;
+ final RDFList retval = current;
+ incrementCurrent();
+ return retval;
+ }
+ throw new NoSuchElementException();
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/utils/RDFListSecFilter.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/utils/RDFListSecFilter.java b/jena-permissions/src/main/java/org/apache/jena/security/utils/RDFListSecFilter.java
new file mode 100644
index 0000000..3127c4f
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/utils/RDFListSecFilter.java
@@ -0,0 +1,58 @@
+/*
+ * 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.utils;
+
+import java.util.Set;
+
+import org.apache.jena.rdf.model.RDFList ;
+import org.apache.jena.rdf.model.Statement ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.impl.SecuredItem;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.util.iterator.Filter ;
+import org.apache.jena.vocabulary.RDF ;
+
+public class RDFListSecFilter<T extends RDFList> extends Filter<T>
+{
+ private final SecuredItem securedItem;
+ private final Set<Action> perms;
+ private final Object principal;
+
+ public RDFListSecFilter( final SecuredItem securedItem, final Action perm )
+ {
+ this(securedItem, SecurityEvaluator.Util.asSet(new Action[] { perm }));
+ }
+
+ public RDFListSecFilter( final SecuredItem securedItem,
+ final Set<Action> perms )
+ {
+ this.securedItem = securedItem;
+ this.perms = perms;
+ this.principal = securedItem.getSecurityEvaluator().getPrincipal();
+ }
+
+ @Override
+ public boolean accept( final RDFList o )
+ {
+ final Statement s = o.getRequiredProperty(RDF.first);
+ return securedItem.getSecurityEvaluator().evaluate(principal, perms,
+ securedItem.getModelNode(),
+ SecuredItemImpl.convert(s.asTriple()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/overview.html
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/overview.html b/jena-permissions/src/main/overview.html
new file mode 100644
index 0000000..561c53a
--- /dev/null
+++ b/jena-permissions/src/main/overview.html
@@ -0,0 +1,83 @@
+<html>
+<body>
+ <p>JenaSecurity is a SecurityEvaluator interface and a set of
+ dynamic proxies that apply that interface to Jena Graphs, Models, and
+ associated methods and classes.</p>
+ <p>
+ The SecurityEvaluator class must be implemented. This class provides
+ the interface to the authentication results (e.g.
+ <code>getPrincipal()</code>
+ ) and the authorization system.
+ </p>
+ <p>
+ <ul>
+ <li>Create a SecuredGraph by calling <code>Factory.getInstance(
+ SecurityEvaluator, String, Graph );</code>
+ </li>
+ <li>Create a SecuredModel by calling <code>Factory.getInstance(
+ SecurityEvaluator, String, Model )</code>
+ </li>
+ <li>It is not recommended that you use the Jena <code>ModelFactory.createModelForGraph(
+ SecuredGraph )</code> See Differences Between Graph and Model below for
+ reasons.
+ </li>
+ </ul>
+ </p>
+ <p>
+ <ul>
+ <li>See SecurityEvaluator documentation for description of
+ cascading security checks</li>
+ <li>Secured methods are annotated with: @sec.graph for
+ permissions required on the graph to execute the method.
+ @sec.triple for permissions required on the associated triples
+ (if any) to execute the method.</li>
+ <li>It is possible to implement a SecurityEvaluator that does not
+ enforce security at the triple level. See SecurityEvaluator
+ documentation for details</li>
+ </ul>
+ </p>
+ <h2>
+ Differences Between
+ <code>Graph</code>
+ and
+ <code>Model</code>
+ </h2>
+ <p>
+ The Graph interface does not have the concept of "update". Thus all
+ updates are implemented as a delete and an insert. The Model interface
+ does have the concept of update as evidenced by the
+ <code>replace()</code>
+ method in the
+ <code>RDFList</code>
+ class. This difference means that a
+ <code>Model</code>
+ created by calling
+ <code>ModelFactory.createModelForGraph( SecuredGraph )</code>
+ will yield a model that evaluates
+ <code>Update</code>
+ actions differently from one created with
+ <Code>Factory.getInstance( SecurityEvaluator, modelIRI, model)</Code>
+ .
+ <ul>
+ <li>Models created by the Jena ModelFactory will require that the
+ user have both delete and create permissions on the underlying graph
+ to perform the update. And will delete the existing triple before
+ attempting to create the new one. Since the graph interface does not
+ have visibility to the model's request for update these are, to the
+ graph, separate events. It is possible that the delete may succeed
+ while the create fails.</li>
+ <li>Models created by the JenaSecurity Factory will require that
+ the user have update permissions on the underlying model to perform
+ the update. As long as the user has the update permission on the
+ graph, and the triple where required, the update is performed as a
+ single event.</li>
+ </ul>
+ This is the well documented case of differences between the two secured
+ model creation methods. For this reason it is recommended that the
+ model be created with the
+ <code>Factory.getInsance()</code>
+ method.
+ </p>
+
+</body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/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
new file mode 100644
index 0000000..4b1d882
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/EqualityTester.java
@@ -0,0 +1,49 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..5db2402
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/MockPrefixMapping.java
@@ -0,0 +1,105 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..797bdf0
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/MockSecurityEvaluator.java
@@ -0,0 +1,228 @@
+/*
+ * 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);
+ }
+
+}
[03/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredModelTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredModelTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredModelTest.java
deleted file mode 100644
index 0e251d7..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredModelTest.java
+++ /dev/null
@@ -1,2034 +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.model;
-
-import java.io.* ;
-import java.net.URL ;
-import java.util.ArrayList ;
-import java.util.List ;
-import java.util.Set ;
-
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.* ;
-import org.apache.jena.security.SecurityEvaluator.Action ;
-import org.apache.jena.security.graph.SecuredGraph ;
-import org.apache.jena.security.graph.SecuredPrefixMappingTest ;
-import org.junit.Assert ;
-import org.junit.Before ;
-import org.junit.Test ;
-import org.junit.runner.RunWith ;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredModelTest
-{
- protected final MockSecurityEvaluator securityEvaluator;
- protected SecuredModel securedModel;
- protected Model baseModel;
- protected Resource s;
- protected Property p;
- protected Resource o;
-
- public SecuredModelTest( final MockSecurityEvaluator securityEvaluator )
- {
- this.securityEvaluator = securityEvaluator;
- }
-
- /**
- * create an unsecured securedModel.
- *
- * @return
- */
- protected Model createModel()
- {
- return ModelFactory.createDefaultModel();
- }
-
- @Before
- public void setup()
- {
- baseModel = createModel();
- baseModel.removeAll();
- securedModel = Factory.getInstance(securityEvaluator,
- "http://example.com/securedGraph", baseModel);
- s = ResourceFactory.createResource("http://example.com/graph/s");
- p = ResourceFactory.createProperty("http://example.com/graph/p");
- o = ResourceFactory.createResource("http://example.com/graph/o");
- baseModel.add(s, p, o);
- }
-
- @Test
- public void testAdd() throws Exception
- {
- final List<Statement> stmt = baseModel.listStatements().toList();
- final Set<Action> createAndUpdate = SecurityEvaluator.Util
- .asSet(new Action[] { Action.Update, Action.Create });
- try
- {
- securedModel.add(stmt);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.add(baseModel);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.add(stmt.get(0));
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
-
- securedModel.add(stmt.toArray(new Statement[stmt.size()]));
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.add(baseModel.listStatements());
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.add(baseModel);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.add(s, p, o);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.add(s, p, "foo");
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.add(s, p, "foo", false);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.add(s, p, "foo", XSDDatatype.XSDstring);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.add(s, p, "foo", "en");
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testAnonymousInModel()
- {
- // test anonymous
- final RDFNode rdfNode = ResourceFactory.createResource();
- final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
- Assert.assertEquals(
- "Should have placed RDFNode in secured securedModel",
- securedModel, rdfNode2.getModel());
- }
-
- @Test
- public void testAsRDFNode() throws Exception
- {
- securedModel.asRDFNode(NodeFactory.createURI("http://example.com/rdfNode"));
- }
-
- @Test
- public void testAsStatement()
- {
- final Triple t = new Triple(s.asNode(), p.asNode(), o.asNode());
- try
- {
- securedModel.asStatement(t);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testContains() throws Exception
- {
- final Statement stmt = baseModel.listStatements().next();
- try
- {
- securedModel.contains(stmt);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedModel.contains(s, p);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.contains(s, p, o);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.contains(s, p, "foo");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.contains(s, p, "foo", "en");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testContainsAll() throws Exception
- {
- try
- {
- securedModel.containsAll(baseModel);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.containsAll(baseModel.listStatements());
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCreateAlt() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
- try
- {
- securedModel.createAlt();
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.createAlt("foo");
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCreateBag() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
- try
- {
- securedModel.createBag();
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.createBag("foo");
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCreateList() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- final List<RDFNode> nodeList = new ArrayList<RDFNode>();
- try
- {
- securedModel.createList();
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- baseModel.removeAll();
-
- try
- {
- securedModel.createList(nodeList.iterator());
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- baseModel.removeAll();
-
- try
- {
- final RDFNode[] list = new RDFNode[] {
- ResourceFactory.createResource(),
- ResourceFactory.createResource(),
- ResourceFactory.createResource(),
- ResourceFactory.createResource(), };
-
- securedModel.createList(list);
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- baseModel.removeAll();
-
- }
-
- @Test
- public void testCreateLiteral() throws Exception
- {
- securedModel.createLiteral("foo");
- securedModel.createLiteral("foo", false);
- }
-
- @Test
- public void testCreateLiteralBoolean() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
-
- try
- {
- securedModel.createLiteralStatement(s, p, true);
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCreateLiteralChar() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
- try
- {
- securedModel.createLiteralStatement(s, p, 'a');
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCreateLiteralDouble() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
-
- try
- {
- securedModel.createLiteralStatement(s, p, 1.0d);
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCreateLiteralFloat() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
-
- try
- {
- securedModel.createLiteralStatement(s, p, 1.0f);
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCreateLiteralInt() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
-
- try
- {
- securedModel.createLiteralStatement(s, p, 1);
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testCreateLiteralLong() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
-
- try
- {
- securedModel.createLiteralStatement(s, p, 1L);
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCreateLiteralObject() throws Exception
- {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
-
- try
- {
- securedModel.createLiteralStatement(s, p, new URL( "http://example.com/testing/URIType"));
- if (!securityEvaluator.evaluate(CU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(CU))
- {
- e.printStackTrace();
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testDifference() throws Exception
- {
- try
- {
- securedModel.difference(baseModel);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testEquals() throws Exception
- {
- securedModel.equals(baseModel);
- baseModel.equals(securedModel);
- }
-
- @Test
- public void testExpandPrefix() throws Exception
- {
- try
- {
- securedModel.expandPrefix("foo");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetAlt() throws Exception
- {
- final Resource a = baseModel
- .createAlt("http://example.com/securedModel/alt");
- try
- {
-
- securedModel.getAlt(a);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedModel.getAlt("http://example.com/securedModel/alt");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetAnyReifiedStmt()
- {
- // first with create.
- final Set<Action> UCR = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create, Action.Read });
- try
- {
- securedModel.getAnyReifiedStatement(baseModel.listStatements()
- .next());
- if (!securityEvaluator.evaluate(UCR))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(UCR))
- {
- e.printStackTrace();
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- final Statement st = baseModel.listStatements().next();
- baseModel.createReifiedStatement(st);
- // now it is there so try with read
- try
- {
- securedModel.getAnyReifiedStatement(st);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetBag()
- {
- final Resource b = baseModel
- .createBag("http://example.com/securedModel/bag");
- try
- {
- securedModel.getBag(b);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedModel.getBag("http://example.com/securedModel/bag");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetGraph() throws Exception
- {
- final Graph g = securedModel.getGraph();
- Assert.assertTrue(g instanceof SecuredGraph);
- EqualityTester.testInequality("getGraph test", g, baseModel.getGraph());
- }
-
- @Test
- public void testGetLock()
- {
- securedModel.getLock();
- }
-
- @Test
- public void testGetProperty()
- {
-
- try
- {
- securedModel.getProperty("foo");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.getProperty(s, p);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.getProperty("fooNS", "foo");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetQNameFor() throws Exception
- {
- try
- {
- securedModel.qnameFor("foo");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testgetRDFNode()
- {
-
- try
- {
- securedModel.getRDFNode(NodeFactory.createURI("foo"));
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetReader()
- {
- securedModel.getReader();
- securedModel.getReader("TURTLE");
- }
-
- @Test
- public void testGetResource()
- {
- securedModel.getResource("foo");
- }
-
- @Test
- public void testGetSeq()
- {
- final Resource s = baseModel
- .createSeq("http://example.com/securedModel/seq");
- try
- {
- securedModel.getSeq(s);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.getSeq("http://example.com/securedModel/seq");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetWriter()
- {
- securedModel.getWriter();
- securedModel.getWriter("TURTLE");
- }
-
- @Test
- public void testIndependent() throws Exception
- {
- Assert.assertFalse(securedModel.independent());
- }
-
- @Test
- public void testIntersection() throws Exception
- {
- try
- {
- securedModel.intersection(baseModel);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testIsClosed() throws Exception
- {
- securedModel.isClosed();
- }
-
- @Test
- public void testIsEmpty() throws Exception
- {
- try
- {
- securedModel.isEmpty();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testIsIsomorphicWith()
- {
- try
- {
- securedModel.isIsomorphicWith(baseModel);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- baseModel.isIsomorphicWith(securedModel);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testIsReified()
- {
- try
- {
- securedModel.isReified(baseModel.listStatements().next());
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testListLiteralStatements() throws Exception
- {
- try
- {
- securedModel.listLiteralStatements(s, p, true);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.listLiteralStatements(s, p, '0');
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.listLiteralStatements(s, p, 2.0d);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.listLiteralStatements(s, p, 2.0f);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.listLiteralStatements(s, p, 1);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testLock() throws Exception
- {
- try
- {
- securedModel.lock();
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testPrefixMapping() throws Exception
- {
- SecuredPrefixMappingTest.runTests(securityEvaluator, securedModel);
- }
-
- @Test
- public void testQuery() throws Exception
- {
- final Selector s = new SimpleSelector();
- try
- {
- securedModel.query(s);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testRDFNodeInModel()
- {
- // test uri
- final RDFNode rdfNode = ResourceFactory
- .createResource("http://exmple.com/testInModel");
- final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
- Assert.assertEquals(
- "Should have placed RDFNode in secured securedModel",
- securedModel, rdfNode2.getModel());
- }
-
- @Test
- public void testReadEmpty() throws Exception
- {
- final Set<Action> createAndUpdate = SecurityEvaluator.Util
- .asSet(new Action[] { Action.Update, Action.Create });
-
- final String XML_INPUT = "<rdf:RDF"
- + " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' "
- + " xmlns:rt='http://example.com/readTest#' "
- + " xmlns:j.0='http://example.com/readTest#3' > "
- + " <rdf:Description rdf:about='http://example.com/readTest#1'> "
- + " <rdf:type rdf:resource='http://example.com/readTest#3'/>"
- + " </rdf:Description>" + "</rdf:RDF>";
- final String TTL_INPUT = "@prefix rt: <http://example.com/readTest#> . rt:1 a rt:3 .";
- final String base = "http://example.com/test";
- final String lang = "TURTLE";
- try
- {
- final URL url = SecuredModelTest.class.getResource("./test.xml");
- securedModel.read(url.toString());
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- finally
- {
- baseModel.removeAll();
- }
-
- try
- {
- final InputStream in = new ByteArrayInputStream(
- XML_INPUT.getBytes());
- securedModel.read(in, base);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- finally
- {
- baseModel.removeAll();
- }
-
- try
- {
- final Reader reader = new StringReader(XML_INPUT);
- securedModel.read(reader, base);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- finally
- {
- baseModel.removeAll();
- }
-
- try
- {
- final URL url = SecuredModelTest.class.getResource("./test.ttl");
- securedModel.read(url.toString(), lang);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- finally
- {
- baseModel.removeAll();
- }
-
- try
- {
- final InputStream in = new ByteArrayInputStream(
- TTL_INPUT.getBytes());
- securedModel.read(in, base, lang);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- finally
- {
- baseModel.removeAll();
- }
-
- try
- {
- final Reader reader = new StringReader(TTL_INPUT);
- securedModel.read(reader, base, lang);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- finally
- {
- baseModel.removeAll();
- }
-
- try
- {
- final URL url = SecuredModelTest.class.getResource("./test.ttl");
- securedModel.read(url.toString(), base, lang);
- if (!securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(createAndUpdate))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- finally
- {
- baseModel.removeAll();
- }
-
- }
-
- @Test
- public void testRemove() throws Exception
- {
- final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Update });
-
- final List<Statement> stmt = baseModel.listStatements().toList();
- try
- {
- securedModel.remove(baseModel.listStatements().toList());
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedModel.remove(baseModel);
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.remove(stmt.get(0));
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedModel.remove(stmt.toArray(new Statement[stmt.size()]));
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedModel.remove(baseModel.listStatements());
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedModel.remove(baseModel);
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- securedModel.remove(s, p, o);
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testRemoveAll() throws Exception
- {
- final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Update });
-
- try
- {
- securedModel.removeAll();
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- // put some data back
- baseModel.add(s, p, o);
- try
- {
- securedModel.removeAll(s, p, o);
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testRemoveAllReifications()
- {
- final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Update });
-
- final List<Statement> stmt = baseModel.listStatements().toList();
- baseModel.createReifiedStatement(stmt.get(0));
-
- try
- {
- securedModel.removeAllReifications(stmt.get(0));
- if (!securityEvaluator.evaluate(DU))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(DU))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testRequiredProperty()
- {
-
- try
- {
- securedModel.getRequiredProperty(s, p);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testSize() throws Exception
- {
- try
- {
- securedModel.size();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testUnion() throws Exception
- {
- try
- {
- securedModel.union(baseModel);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- try
- {
- baseModel.union(securedModel);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testVariableInModel()
- {
- try
- {
- final RDFNode rdfNode = ResourceFactory
- .createTypedLiteral("yeehaw");
- final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- Assert.assertEquals(
- "Should have placed RDFNode in secured securedModel",
- securedModel, rdfNode2.getModel());
-
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testWrapAsResource() throws Exception
- {
- securedModel.wrapAsResource(NodeFactory.createURI("http://example.com/rdfNode"));
- }
-
- @Test
- public void testWrite() throws Exception
- {
- final OutputStream out = new ByteArrayOutputStream();
- final Writer writer = new CharArrayWriter();
- final String lang = "TURTLE";
- try
- {
- securedModel.write(out);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.write(writer);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.write(out, lang);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.write(writer, lang);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.write(out, lang, "http://example.com/securedGraph");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- try
- {
- securedModel.write(writer, lang, "http://example.com/securedGraph");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredPropertyTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredPropertyTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredPropertyTest.java
deleted file mode 100644
index d035bae..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredPropertyTest.java
+++ /dev/null
@@ -1,79 +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.model;
-
-import org.apache.jena.rdf.model.Property ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredProperty;
-import org.apache.jena.security.model.impl.SecuredPropertyImpl;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredPropertyTest extends SecuredResourceTest
-{
-
- public SecuredPropertyTest( final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- }
-
- private SecuredProperty getSecuredProperty()
- {
- return (SecuredProperty) getSecuredRDFNode();
- }
-
- @Override
- @Before
- public void setup()
- {
- super.setup();
- final Property p = ResourceFactory
- .createProperty("http://example.com/testProperty");
- setSecuredRDFNode(SecuredPropertyImpl.getInstance(securedModel, p), p);
- }
-
- @Test
- public void testGetOrdinal()
- {
- try
- {
- getSecuredProperty().getOrdinal();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredRDFListTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredRDFListTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredRDFListTest.java
deleted file mode 100644
index d1c32aa..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredRDFListTest.java
+++ /dev/null
@@ -1,970 +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.model;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.rdf.model.RDFList.ApplyFn ;
-import org.apache.jena.rdf.model.RDFList.ReduceFn ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredRDFList;
-import org.apache.jena.security.model.impl.SecuredRDFListImpl;
-import org.apache.jena.security.utils.RDFListIterator;
-import org.apache.jena.security.utils.RDFListSecFilter;
-import org.apache.jena.util.iterator.WrappedIterator ;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredRDFListTest extends SecuredResourceTest
-{
- private RDFList baseList;
-
- public SecuredRDFListTest( final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- }
-
- private int count( final Action action )
- {
- final Iterator<RDFList> iter = new RDFListIterator(
- (RDFList) getBaseRDFNode());
- return WrappedIterator.create(iter)
- .filterKeep(new RDFListSecFilter<RDFList>(getSecuredRDFList(), action))
- .toList().size();
- }
-
- private int count( final Set<Action> action )
- {
- final Iterator<RDFList> iter = new RDFListIterator(
- (RDFList) getBaseRDFNode());
- return WrappedIterator.create(iter)
- .filterKeep(new RDFListSecFilter<RDFList>(getSecuredRDFList(), action))
- .toList().size();
- }
-
- private SecuredRDFList getSecuredRDFList()
- {
- return (SecuredRDFList) getSecuredRDFNode();
- }
-
- @Override
- @Before
- public void setup()
- {
- super.setup();
- final RDFNode[] listElements = {
- ResourceFactory.createResource("http://example.com/ListNode1"),
- ResourceFactory.createResource("http://example.com/ListNode2"),
- ResourceFactory.createResource("http://example.com/ListNode3"),
- ResourceFactory.createResource("http://example.com/ListNode4") };
- baseList = baseModel.createList(listElements);
- setSecuredRDFNode(SecuredRDFListImpl.getInstance(securedModel, baseList), baseList);
- }
-
- @Test
- public void testAdd()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredRDFList().add(baseModel.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()));
- }
- }
-
- }
-
- @Test
- public void testAppendNodeIterator()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredRDFList().append(baseModel.listObjects());
- 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 testAppendRDFList()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- try {
- getSecuredRDFList().append(baseModel.createList());
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- if (!securityEvaluator.evaluate(Action.Create) && (baseList.size()>0 && securityEvaluator.evaluate(Action.Read) ))
- {
- 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 testApply()
- {
-
- final ApplyFn fn = new ApplyFn() {
-
- @Override
- public void apply( final RDFNode node )
- {
- // do nothing
- }
- };
-
- try
- {
- getSecuredRDFList().apply(fn);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Read });
- try
- {
- getSecuredRDFList().apply(perms, fn);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testAsJaveList()
- {
- try
- {
- getSecuredRDFList().asJavaList();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
- @Test
- public void testConcatenate()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredRDFList().concatenate(baseModel.listObjects());
- 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 List<Resource> lst = new ArrayList<Resource>();
- lst.add(ResourceFactory
- .createResource("http://example.com/dummyList"));
- getSecuredRDFList().concatenate(
- baseModel.createList(lst.iterator()));
- 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 testCons()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
- try
- {
- getSecuredRDFList().cons(SecuredRDFNodeTest.s);
- 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 testContains()
- {
- try
- {
- getSecuredRDFList().contains(SecuredRDFNodeTest.s);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCopy()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Read, Action.Update, Action.Create });
- try
- {
- getSecuredRDFList().copy();
- }
- 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 testGet()
- {
- try
- {
- getSecuredRDFList().get(0);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final ListIndexException e)
- {
- if (((RDFList) getBaseRDFNode()).size() < 0)
- {
- // acceptable exception
- }
- else
- {
- throw e;
- }
- }
- }
-
- @Test
- public void testGetHead()
- {
- try
- {
- getSecuredRDFList().getHead();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final ListIndexException e)
- {
- if (((RDFList) getBaseRDFNode()).size() == 0)
- {
- // acceptable exception
- }
- else
- {
- throw e;
- }
- }
- }
-
- @Test
- public void testGetTail()
- {
- try
- {
- getSecuredRDFList().getTail();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final ListIndexException e)
- {
- if (((RDFList) getBaseRDFNode()).size() == 0)
- {
- // acceptable exception
- }
- else
- {
- throw e;
- }
- }
- }
-
- @Test
- public void testGetValidityErrorMessage()
- {
- try
- {
- getSecuredRDFList().getValidityErrorMessage();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testIndexOf()
- {
- try
- {
- getSecuredRDFList().indexOf(SecuredRDFNodeTest.s);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final ListIndexException e)
- {
- if (((RDFList) getBaseRDFNode()).size() == 0)
- {
- // acceptable exception
- }
- else
- {
- throw e;
- }
- }
-
- try
- {
- getSecuredRDFList().indexOf(SecuredRDFNodeTest.s, 1);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final ListIndexException e)
- {
- if (((RDFList) getBaseRDFNode()).size() <= 0)
-
- {
- // acceptable exception
- }
- else
- {
- throw e;
- }
- }
- }
-
- @Test
- public void testIsEmpty()
- {
- try
- {
- getSecuredRDFList().isEmpty();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testIterator()
- {
- try
- {
- getSecuredRDFList().iterator();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- try
- {
- getSecuredRDFList().iterator(perms);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testReduce()
- {
- final ReduceFn fn = new ReduceFn() {
-
- @Override
- public Object reduce( final RDFNode node, final Object accumulator )
- {
- return accumulator;
- }
- };
-
- try
- {
- getSecuredRDFList().reduce(fn, "Hello");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- try
- {
- getSecuredRDFList().reduce(perms, fn, "Hello");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- 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
- {
- final int count = count(Action.Delete);
- getSecuredRDFList().remove(SecuredRDFNodeTest.s);
- if (!securityEvaluator.evaluate(Action.Update)
- || ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- 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()));
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- @Override
- @Test
- public void testRemoveAll()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
-
- try
- {
- final int count = count(SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Read }));
- getSecuredRDFList().removeAll();
- if (!securityEvaluator.evaluate(Action.Update)
- || ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- 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()));
- }
- }
- catch (final EmptyListException e)
- {
- if (count(Action.Read) == 0)
- {
- // expected.
- }
- else
- {
- throw e;
- }
- }
- }
-
- @Test
- public void testRemoveHead()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
-
- try
- {
- getSecuredRDFList().removeHead();
- 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()));
- }
- }
- catch (final EmptyListException e)
- {
- if (count(Action.Read) == 0)
- {
- // expected.
- }
- else
- {
- throw e;
- }
- }
- }
-
- @Test
- public void testRemoveList()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
-
- try
- {
- final int count = count(Action.Delete);
- getSecuredRDFList().removeList();
- if (!securityEvaluator.evaluate(Action.Update)
- || ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- 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 testReplace()
- {
- try
- {
- getSecuredRDFList().replace(1, SecuredRDFNodeTest.s);
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final ListIndexException e)
- {
- if (count(Action.Read) == 0)
- {
- // expected.
- }
- else
- {
- throw e;
- }
- }
- }
-
- @Test
- public void testSameListAs()
- {
- try
- {
- getSecuredRDFList().sameListAs(baseModel.createList());
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testSetHead()
- {
-
- try
- {
- getSecuredRDFList().setHead(SecuredRDFNodeTest.s);
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- catch (final EmptyListException e)
- {
- if (count(Action.Read) == 0)
- {
- // expected.
- }
- else
- {
- throw e;
- }
- }
- }
-
- @Test
- public void testSetStrict()
- {
- try
- {
- getSecuredRDFList().setStrict(true);
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testSize()
- {
- try
- {
- getSecuredRDFList().size();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testValid()
- {
- try
- {
- getSecuredRDFList().isValid();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testWith()
- {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
-
- try
- {
- getSecuredRDFList().with(SecuredRDFNodeTest.s);
- 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()));
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredRDFNodeTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredRDFNodeTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredRDFNodeTest.java
deleted file mode 100644
index 79ba3e2..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredRDFNodeTest.java
+++ /dev/null
@@ -1,209 +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.model;
-
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.Factory;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredRDFNode;
-import org.apache.jena.security.model.impl.SecuredRDFNodeImpl;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredRDFNodeTest
-{
- protected final MockSecurityEvaluator securityEvaluator;
- protected Model baseModel;
- protected SecuredModel securedModel;
- private SecuredRDFNode securedRDFNode;
- private RDFNode baseRDFNode;
-
- public static Resource s = ResourceFactory
- .createResource("http://example.com/graph/s");
- public static Property p = ResourceFactory
- .createProperty("http://example.com/graph/p");
- public static Property p2 = ResourceFactory
- .createProperty("http://example.com/graph/p2");
- public static Resource o = ResourceFactory
- .createResource("http://example.com/graph/o");
-
- public SecuredRDFNodeTest( final MockSecurityEvaluator securityEvaluator )
- {
- this.securityEvaluator = securityEvaluator;
- }
-
- protected Model createModel()
- {
- return ModelFactory.createDefaultModel();
- }
-
- protected RDFNode getBaseRDFNode()
- {
- return baseRDFNode;
- }
-
- protected SecuredRDFNode getSecuredRDFNode()
- {
- return securedRDFNode;
- }
-
- protected void setSecuredRDFNode( final SecuredRDFNode securedRDFNode,
- final RDFNode baseRDFNode )
- {
- this.securedRDFNode = securedRDFNode;
- this.baseRDFNode = baseRDFNode;
- }
-
- @Before
- public void setup()
- {
- baseModel = createModel();
- baseModel.removeAll();
- baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p,
- SecuredRDFNodeTest.o);
- baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p2, "yeehaw");
- securedModel = Factory.getInstance(securityEvaluator,
- "http://example.com/securedGraph", baseModel);
- securedRDFNode = SecuredRDFNodeImpl.getInstance(
- securedModel,
- baseModel.listObjectsOfProperty(SecuredRDFNodeTest.s,
- SecuredRDFNodeTest.p).next());
- }
-
- @After
- public void teardown()
- {
- securedModel.close();
- securedModel = null;
- }
-
- @Test
- public void testAsNode()
- {
- try
- {
- securedRDFNode.asNode();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testCanAs()
- {
- try
- {
- securedRDFNode.canAs(Resource.class);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-
- @Test
- public void testGetModel()
- {
- final Model m2 = securedRDFNode.getModel();
- Assert.assertTrue("Model should have been secured",
- m2 instanceof SecuredModel);
- }
-
- @Test
- public void testInModel()
- {
- final Model m2 = ModelFactory.createDefaultModel();
- try
- {
- final RDFNode n2 = securedRDFNode.inModel(m2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- Assert.assertFalse("RDFNode should not have been secured",
- n2 instanceof SecuredRDFNode);
- Assert.assertEquals("Wrong securedModel returned", n2.getModel(),
- m2);
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- m2.removeAll();
- final SecuredModel m3 = Factory.getInstance(securityEvaluator,
- "http://example.com/securedGraph2", m2);
-
- try
- {
- final RDFNode n2 = securedRDFNode.inModel(m3);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- Assert.assertTrue("RDFNode should have been secured",
- n2 instanceof SecuredRDFNode);
- Assert.assertEquals("Wrong securedModel returned", n2.getModel(),
- m3);
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/model/SecuredReifiedStatementTest.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/model/SecuredReifiedStatementTest.java b/jena-security/src/test/java/org/apache/jena/security/model/SecuredReifiedStatementTest.java
deleted file mode 100644
index 00aceb2..0000000
--- a/jena-security/src/test/java/org/apache/jena/security/model/SecuredReifiedStatementTest.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.model;
-
-import org.apache.jena.rdf.model.ReifiedStatement ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.MockSecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluatorParameters;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredReifiedStatement;
-import org.apache.jena.security.model.impl.SecuredReifiedStatementImpl;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredReifiedStatementTest extends SecuredResourceTest
-{
-
- public SecuredReifiedStatementTest(
- final MockSecurityEvaluator securityEvaluator )
- {
- super(securityEvaluator);
- }
-
- private SecuredReifiedStatement getSecuredReifiedStatement()
- {
- return (SecuredReifiedStatement) getSecuredRDFNode();
- }
-
- @Override
- @Before
- public void setup()
- {
- super.setup();
- final ReifiedStatement stmt = baseModel.listStatements().next()
- .createReifiedStatement();
- setSecuredRDFNode(
- SecuredReifiedStatementImpl.getInstance(securedModel, stmt),
- stmt);
- }
-
- /**
- * @sec.graph Read
- * @throws AccessDeniedException
- */
- @Test
- public void testGetStatement()
- {
- try
- {
- getSecuredReifiedStatement().getStatement();
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
- }
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
- e, e.getTriple()));
- }
- }
- }
-}
[19/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredModelImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredModelImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredModelImpl.java
new file mode 100644
index 0000000..d0a21c5
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredModelImpl.java
@@ -0,0 +1,2739 @@
+/*
+ * 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.model.impl;
+
+import java.io.* ;
+import java.net.URL ;
+import java.util.* ;
+
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.CollectionGraph ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.rdf.model.impl.RDFReaderFImpl ;
+import org.apache.jena.security.AccessDeniedException ;
+import org.apache.jena.security.SecurityEvaluator ;
+import org.apache.jena.security.SecurityEvaluator.SecTriple ;
+import org.apache.jena.security.graph.SecuredGraph ;
+import org.apache.jena.security.graph.SecuredPrefixMapping ;
+import org.apache.jena.security.impl.ItemHolder ;
+import org.apache.jena.security.impl.SecuredItem ;
+import org.apache.jena.security.impl.SecuredItemImpl ;
+import org.apache.jena.security.impl.SecuredItemInvoker ;
+import org.apache.jena.security.model.* ;
+import org.apache.jena.shared.* ;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.Filter ;
+import org.apache.jena.util.iterator.WrappedIterator ;
+import org.apache.jena.vocabulary.RDF ;
+
+/**
+ * Implementation of SecuredModel to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredModelImpl extends SecuredItemImpl implements SecuredModel
+{
+
+ // a class that implements ModelChangedListener
+ private class SecuredModelChangedListener implements ModelChangedListener
+ {
+ private final ModelChangedListener wrapped;
+
+ private SecuredModelChangedListener( final ModelChangedListener wrapped )
+ {
+ this.wrapped = wrapped;
+ }
+
+ @Override
+ public void addedStatement( final Statement s )
+ {
+ if (canRead(s.asTriple()))
+ {
+ wrapped.addedStatement(s);
+ }
+ }
+
+ @Override
+ public void addedStatements( final List<Statement> statements )
+ {
+ if (canRead(Triple.ANY))
+ {
+ wrapped.addedStatements(statements);
+ }
+ else
+ {
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(),
+ WrappedIterator.create(statements.iterator()));
+ try
+ {
+ wrapped.addedStatements(iter.toList());
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ }
+
+ @Override
+ public void addedStatements( final Model m )
+ {
+ if (canRead(Triple.ANY))
+ {
+ wrapped.addedStatements(m);
+ }
+ else
+ {
+ wrapped.addedStatements(SecuredModelImpl.getInstance(
+ holder.getSecuredItem(), m));
+ }
+ }
+
+ @Override
+ public void addedStatements( final Statement[] statements )
+ {
+ if (canRead(Triple.ANY))
+ {
+ wrapped.addedStatements(statements);
+ }
+ else
+ {
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(), WrappedIterator.create(Arrays
+ .asList(statements).iterator()));
+ try
+ {
+ final List<Statement> stmts = iter.toList();
+ wrapped.addedStatements(stmts.toArray(new Statement[stmts
+ .size()]));
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ }
+
+ @Override
+ public void addedStatements( final StmtIterator statements )
+ {
+ if (canRead(Triple.ANY))
+ {
+ wrapped.addedStatements(statements);
+ }
+ else
+ {
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(), statements);
+ try
+ {
+ wrapped.addedStatements(iter);
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ }
+
+ @Override
+ public void notifyEvent( final Model m, final Object event )
+ {
+ wrapped.notifyEvent(m, event);
+ }
+
+ @Override
+ public void removedStatement( final Statement s )
+ {
+ if (canRead(s.asTriple()))
+ {
+ wrapped.removedStatement(s);
+ }
+ }
+
+ @Override
+ public void removedStatements( final List<Statement> statements )
+ {
+
+ if (canRead(Triple.ANY))
+ {
+ wrapped.removedStatements(statements);
+ }
+ else
+ {
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(),
+ WrappedIterator.create(statements.iterator()));
+ try
+ {
+ wrapped.removedStatements(iter.toList());
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ }
+
+ @Override
+ public void removedStatements( final Model m )
+ {
+ if (canRead(Triple.ANY))
+ {
+ wrapped.removedStatements(m);
+ }
+ else
+ {
+ wrapped.removedStatements(SecuredModelImpl.getInstance(
+ holder.getSecuredItem(), m));
+ }
+ }
+
+ @Override
+ public void removedStatements( final Statement[] statements )
+ {
+ if (canRead(Triple.ANY))
+ {
+ wrapped.removedStatements(statements);
+ }
+ else
+ {
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(), WrappedIterator.create(Arrays
+ .asList(statements).iterator()));
+ try
+ {
+ final List<Statement> stmts = iter.toList();
+ wrapped.removedStatements(stmts.toArray(new Statement[stmts
+ .size()]));
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ }
+
+ @Override
+ public void removedStatements( final StmtIterator statements )
+ {
+ if (canRead(Triple.ANY))
+ {
+ wrapped.removedStatements(statements);
+ }
+ else
+ {
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(), statements);
+ try
+ {
+ wrapped.removedStatements(iter);
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ }
+ }
+
+ /*private class ReadFilter extends Filter<Resource> {
+ private SecuredItem si;
+ private SecuredResource r;
+ private Property p;
+ ReadFilter( SecuredItem si, SecuredResource r, Property p )
+ {
+ this.si = si;
+ this.r = r;
+ this.p = p;
+ }
+ @Override
+ public boolean accept(Resource o) {
+ Triple t = new Triple( r.asNode(), p.asNode(), o.asNode());
+ return si.canRead( SecuredItemImpl.convert( t ) );
+ }};
+*/
+ private static final RDFReaderF readerFactory = new RDFReaderFImpl();
+ //private static final RDFWriterF writerFactory = new RDFWriterFImpl();
+
+ /**
+ * Get an instance of SecuredModel
+ *
+ * @param securedItem
+ * the item providing the security context.
+ * @param model
+ * the Model to secure.
+ * @return The SecuredModel
+ */
+ public static SecuredModel getInstance( final SecuredItem securedItem,
+ final Model model )
+ {
+ return org.apache.jena.security.Factory.getInstance(
+ securedItem.getSecurityEvaluator(), securedItem.getModelIRI(),
+ model);
+ }
+
+ /**
+ * Get an instance of SecuredModel
+ *
+ * @param securityEvaluator
+ * The security evaluator to use
+ * @param modelIRI
+ * The IRI (graph IRI) to name this model.
+ * @param model
+ * The Model to secure.
+ * @return the SecuredModel
+ */
+ public static SecuredModel getInstance(
+ final SecurityEvaluator securityEvaluator, final String modelIRI,
+ final Model model )
+ {
+ final ItemHolder<Model, SecuredModel> holder = new ItemHolder<Model, SecuredModel>(
+ model);
+
+ final SecuredModelImpl checker = new SecuredModelImpl(
+ securityEvaluator, modelIRI, holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (model instanceof SecuredModel)
+ {
+ if (checker.isEquivalent((SecuredModel) model))
+ {
+ return (SecuredModel) model;
+ }
+ }
+ return holder.setSecuredItem(new SecuredItemInvoker(model.getClass(),
+ checker));
+ }
+
+ // the item holder that contains this SecuredModel.
+ private final ItemHolder<Model, SecuredModel> holder;
+
+ // The secured graph that this securedModel contains.
+ private final SecuredGraph graph;
+
+ //
+ Map<ModelChangedListener, SecuredModelChangedListener> listeners = new HashMap<ModelChangedListener, SecuredModelChangedListener>();
+
+ /**
+ * Constructor.
+ *
+ * @param securityEvaluator
+ * The security evaluator to use
+ * @param modelURI
+ * The securedModel IRI to verify against.
+ * @param holder
+ * The item holder that will contain this SecuredModel.
+ */
+ private SecuredModelImpl( final SecurityEvaluator securityEvaluator,
+ final String modelURI, final ItemHolder<Model, SecuredModel> holder )
+ {
+ super(securityEvaluator, modelURI, holder);
+ this.graph = org.apache.jena.security.Factory.getInstance(securityEvaluator, modelURI, holder
+ .getBaseItem().getGraph());
+ this.holder = holder; // FIXME -- this should just access the super holder.
+ }
+
+ private RDFNode asObject( Object o )
+ {
+ return o instanceof RDFNode ? (RDFNode) o : ResourceFactory.createTypedLiteral( o );
+ }
+
+ @Override
+ public SecuredModel abort()
+ {
+ holder.getBaseItem().abort();
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel add( final List<Statement> statements )
+ {
+ checkUpdate();
+ checkCreateStatement(WrappedIterator.create(statements.iterator()));
+ holder.getBaseItem().add(statements);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel add( final Model m )
+ {
+ checkUpdate();
+ if (!canCreate(Triple.ANY))
+ {
+ checkCreateStatement(m.listStatements());
+ }
+ holder.getBaseItem().add(m);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel add( final Resource s, final Property p, final RDFNode o )
+ {
+ checkUpdate();
+ checkCreate(new Triple(s.asNode(), p.asNode(), o.asNode()));
+ holder.getBaseItem().add(s, p, o);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel add( final Resource s, final Property p, final String o )
+ {
+ return add( s, p, o, false );
+ }
+
+ @Override
+ public SecuredModel add( final Resource s, final Property p,
+ final String o, final boolean wellFormed )
+ {
+ checkUpdate();
+ checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(o,
+ "", wellFormed)));
+ holder.getBaseItem().add(s, p, o, wellFormed);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel add( final Resource s, final Property p,
+ final String lex, final RDFDatatype datatype )
+ {
+ checkUpdate();
+ checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(lex,
+ datatype)));
+ holder.getBaseItem().add(s, p, lex, datatype);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel add( final Resource s, final Property p,
+ final String o, final String l )
+ {
+ checkUpdate();
+ checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(o, l,
+ false)));
+ holder.getBaseItem().add(s, p, o, l);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel add( final Statement s )
+ {
+ checkUpdate();
+ checkCreate(s.asTriple());
+ holder.getBaseItem().add(s);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel add( final Statement[] statements )
+ {
+ checkUpdate();
+ if (!canCreate(Triple.ANY))
+ {
+ for (final Statement s : statements)
+ {
+ checkCreate(s.asTriple());
+ }
+ }
+ holder.getBaseItem().add(statements);
+ return holder.getSecuredItem();
+
+ }
+
+ @Override
+ public SecuredModel add( final StmtIterator iter )
+ {
+ checkUpdate();
+ if (!canCreate(Triple.ANY))
+ {
+ final List<Triple> lst = new ArrayList<Triple>();
+ try
+ {
+ while (iter.hasNext())
+ {
+ final Statement s = iter.next();
+ checkCreate(s.asTriple());
+ lst.add(s.asTriple());
+ }
+ final Model m = ModelFactory
+ .createModelForGraph(new CollectionGraph(lst));
+ holder.getBaseItem().add(m.listStatements());
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ else
+ {
+ holder.getBaseItem().add(iter);
+ }
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final boolean o )
+ {
+ final Literal l = ResourceFactory.createTypedLiteral(o);
+ if (l == null)
+ {
+ throw new IllegalArgumentException( "HOw did we get a null");
+ }
+ return add(s, p, l);
+ }
+
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final char o )
+ {
+ final Literal l = ResourceFactory.createTypedLiteral(o);
+ return add(s, p, l);
+ }
+
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final double o )
+ {
+ final Literal l = ResourceFactory.createTypedLiteral(o);
+ return add(s, p, l);
+ }
+
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final float o )
+ {
+ final Literal l = ResourceFactory.createTypedLiteral(o);
+ return add(s, p, l);
+ }
+
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final int o )
+ {
+ final Literal l = ResourceFactory.createTypedLiteral(o);
+ return add(s, p, l);
+ }
+
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final Literal o )
+ {
+ return add(s, p, o);
+ }
+
+ @Override
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final long o )
+ {
+ final Literal l = ResourceFactory.createTypedLiteral(o);
+ return add(s, p, l);
+ }
+
+ @Override
+ @Deprecated
+ public SecuredModel addLiteral( final Resource s, final Property p,
+ final Object o )
+ {
+ return add(s, p, asObject(o));
+ }
+
+ @Override
+ public SecuredRDFNode asRDFNode( final Node n )
+ {
+ return SecuredRDFNodeImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .asRDFNode(n));
+ }
+
+ @Override
+ public SecuredStatement asStatement( final Triple t )
+ {
+ final ExtendedIterator<Triple> iter = holder.getBaseItem().getGraph()
+ .find(t);
+ final boolean exists = iter.hasNext();
+ iter.close();
+ if (exists)
+ {
+ checkRead();
+ checkRead(t);
+ }
+ else
+ {
+ checkUpdate();
+ checkCreate(t);
+ }
+ return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .asStatement(t));
+ }
+
+ @Override
+ public SecuredModel begin()
+ {
+ holder.getBaseItem().begin();
+ return holder.getSecuredItem();
+ }
+
+ private void checkCreate( final SecurityEvaluator.SecNode n, final Triple t )
+ {
+ checkRead(t);
+ checkCreate(new SecurityEvaluator.SecTriple(n,
+ SecuredItemImpl.convert(RDF.subject.asNode()),
+ SecuredItemImpl.convert(t.getSubject())));
+ checkCreate(new SecurityEvaluator.SecTriple(n,
+ SecuredItemImpl.convert(RDF.predicate.asNode()),
+ SecuredItemImpl.convert(t.getPredicate())));
+ checkCreate(new SecurityEvaluator.SecTriple(n,
+ SecuredItemImpl.convert(RDF.object.asNode()),
+ SecuredItemImpl.convert(t.getObject())));
+ }
+
+ /*
+ * private void checkCreateAnonymousResource( final
+ * SecurityEvaluator.SecNode n )
+ * {
+ * checkUpdate();
+ * final SecurityEvaluator.SecTriple t = new SecurityEvaluator.SecTriple(n,
+ * SecurityEvaluator.SecNode.IGNORE, SecurityEvaluator.SecNode.IGNORE);
+ * checkCreate(t);
+ * }
+ */
+ @Override
+ public void close()
+ {
+ holder.getBaseItem().close();
+ }
+
+ @Override
+ public SecuredModel commit()
+ {
+ holder.getBaseItem().commit();
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public boolean contains( final Resource s, final Property p )
+ {
+ checkRead();
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(), holder.getBaseItem().listStatements(s, p, (RDFNode) null));
+ try
+ {
+ return iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public boolean contains( final Resource s, final Property p, final RDFNode o )
+ {
+ checkRead();
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(), holder.getBaseItem().listStatements(s, p, o));
+ try
+ {
+ return iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public boolean contains( final Resource s, final Property p, final String o )
+ {
+ checkRead();
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(), holder.getBaseItem().listStatements(s, p, o));
+ try
+ {
+ return iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public boolean contains( final Resource s, final Property p,
+ final String o, final String l )
+ {
+ checkRead();
+ final SecuredStatementIterator iter = new SecuredStatementIterator(
+ holder.getSecuredItem(), holder.getBaseItem().listStatements(s, p, o, l));
+ try
+ {
+ return iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public boolean contains( final Statement s )
+ {
+ checkRead();
+ checkRead(s);
+ return holder.getBaseItem().contains(s);
+ }
+
+ @Override
+ public boolean containsAll( final Model model )
+ {
+ return containsAll(model.listStatements());
+ }
+
+ @Override
+ public boolean containsAll( final StmtIterator iter )
+ {
+ checkRead();
+ final boolean doCheck = canRead(Triple.ANY);
+ try
+ {
+ while (iter.hasNext())
+ {
+ final Statement stmt = iter.next();
+ if (doCheck)
+ {
+ checkRead(stmt);
+ }
+ if (!holder.getBaseItem().contains(stmt))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public boolean containsAny( final Model model )
+ {
+ return containsAny(model.listStatements());
+
+ }
+
+ @Override
+ public boolean containsAny( final StmtIterator iter )
+ {
+ checkRead();
+ final boolean skipCheck = canRead(Triple.ANY);
+ try
+ {
+ while (iter.hasNext())
+ {
+ final Statement stmt = iter.next();
+ if (skipCheck || canRead(stmt))
+ {
+ if (holder.getBaseItem().contains(stmt))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final boolean o )
+ {
+ return contains(s, p, ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final char o )
+ {
+ return contains(s, p, ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final double o )
+ {
+ return contains(s, p, ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final float o )
+ {
+ return contains(s, p, ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final int o )
+ {
+ return contains(s, p, ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final long o )
+ {
+ return contains(s, p, ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public boolean containsLiteral( final Resource s, final Property p,
+ final Object o )
+ {
+ return contains(s, p, asObject(o));
+ }
+
+ @Override
+ public boolean containsResource( final RDFNode r )
+ {
+ checkRead();
+ if (canRead(new Triple(Node.ANY, Node.ANY, Node.ANY)))
+ {
+ return holder.getBaseItem().containsResource(r);
+ }
+ else
+ {
+ ExtendedIterator<Statement> iter = listStatements(null, null, r);
+ if (r.isResource())
+ {
+
+ if (r.isURIResource())
+ {
+ iter = iter
+ .andThen(listStatements(null, ResourceFactory
+ .createProperty(r.asNode().getURI()),
+ (RDFNode) null));
+ }
+ else
+ {
+ iter = iter.andThen(listStatements(null, ResourceFactory
+ .createProperty(r.asNode().getBlankNodeLabel()),
+ (RDFNode) null));
+ }
+ iter = iter.andThen(listStatements(r.asResource(), null,
+ (RDFNode) null));
+ }
+ try
+ {
+ return iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ }
+
+ @Override
+ public SecuredAlt createAlt()
+ {
+ checkUpdate();
+ checkCreate(new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(RDF.type.asNode()),
+ SecuredItemImpl.convert(RDF.Alt.asNode())));
+ return SecuredAltImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createAlt());
+ }
+
+ @Override
+ public SecuredAlt createAlt( final String uri )
+ {
+ checkUpdate();
+ checkCreate(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
+ RDF.Alt.asNode()));
+ return SecuredAltImpl.getInstance(holder.getSecuredItem(),
+ holder.getBaseItem().createAlt(uri));
+ }
+
+ @Override
+ public SecuredBag createBag()
+ {
+ checkUpdate();
+ checkCreate(new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(RDF.type.asNode()),
+ SecuredItemImpl.convert(RDF.Bag.asNode())));
+ return SecuredBagImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createBag());
+ }
+
+ @Override
+ public SecuredBag createBag( final String uri )
+ {
+ checkUpdate();
+ checkCreate(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
+ RDF.Bag.asNode()));
+ return SecuredBagImpl.getInstance(holder.getSecuredItem(),
+ holder.getBaseItem().createBag(uri));
+ }
+
+ private Model createCopy()
+ {
+ return ModelFactory.createDefaultModel().add(holder.getSecuredItem());
+ }
+
+ @Override
+ public SecuredRDFList createList()
+ {
+ checkUpdate();
+ return SecuredRDFListImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createList());
+ }
+
+ @Override
+ public SecuredRDFList createList( final Iterator<? extends RDFNode> members )
+ {
+ checkUpdate();
+ checkCreate(new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(RDF.rest.asNode()),
+ SecurityEvaluator.SecNode.FUTURE));
+ if (!(canCreate(new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(RDF.first.asNode()),
+ SecuredItemImpl.convert(Node.ANY)))))
+ {
+ final List<RDFNode> nodes = new ArrayList<RDFNode>();
+ while (members.hasNext())
+ {
+
+ final RDFNode n = members.next();
+ checkCreate(new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(RDF.first.asNode()),
+ SecuredItemImpl.convert(n.asNode())));
+ nodes.add(n);
+ }
+ return SecuredRDFListImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createList(nodes.iterator()));
+
+ }
+ else
+ {
+ return SecuredRDFListImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createList(members));
+ }
+ }
+
+ @Override
+ public SecuredRDFList createList( final RDFNode[] members )
+ {
+ return createList(Arrays.asList(members).iterator());
+ }
+
+ @Override
+ public SecuredLiteral createLiteral( final String v )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createLiteral(v));
+ }
+
+ @Override
+ public SecuredLiteral createLiteral( final String v,
+ final boolean wellFormed )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createLiteral(v, wellFormed));
+
+ }
+
+ @Override
+ public SecuredLiteral createLiteral( final String v, final String language )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createLiteral(v, language));
+ }
+
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final boolean o )
+ {
+ return createStatement(s, p,
+ ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final char o )
+ {
+ return createStatement(s, p,
+ ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final double o )
+ {
+ return createStatement(s, p,
+ ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final float o )
+ {
+ return createStatement(s, p,
+ ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final int o )
+ {
+ return createStatement(s, p,
+ ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final long o )
+ {
+ return createStatement(s, p,
+ ResourceFactory.createTypedLiteral(o));
+ }
+
+ @Override
+ public SecuredStatement createLiteralStatement( final Resource s,
+ final Property p, final Object o )
+ {
+ return createStatement(s, p, asObject(o));
+ }
+
+ @Override
+ public SecuredProperty createProperty( final String uri )
+ {
+ return SecuredPropertyImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createProperty(uri));
+ }
+
+ @Override
+ public SecuredProperty createProperty( final String nameSpace,
+ final String localName )
+ {
+ checkUpdate();
+ return SecuredPropertyImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createProperty(nameSpace, localName));
+ }
+
+ @Override
+ public ReifiedStatement createReifiedStatement( final Statement s )
+ {
+ checkUpdate();
+ checkCreate(SecurityEvaluator.SecNode.FUTURE, s.asTriple());
+ return SecuredReifiedStatementImpl.getInstance(holder.getSecuredItem(), holder
+ .getBaseItem().createReifiedStatement(s));
+ }
+
+ @Override
+ public ReifiedStatement createReifiedStatement( final String uri,
+ final Statement s )
+ {
+ checkUpdate();
+ checkCreate(new SecurityEvaluator.SecNode(
+ SecurityEvaluator.SecNode.Type.URI, uri), s.asTriple());
+ return SecuredReifiedStatementImpl.getInstance(holder.getSecuredItem(), holder
+ .getBaseItem().createReifiedStatement(uri, s));
+ }
+
+ @Override
+ public SecuredResource createResource()
+ {
+ // checkCreateAnonymousResource(SecurityEvaluator.SecNode.FUTURE);
+ return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createResource());
+ }
+
+ @Override
+ public SecuredResource createResource( final AnonId id )
+ {
+ // checkCreateAnonymousResource(new SecurityEvaluator.SecNode(
+ // SecurityEvaluator.SecNode.Type.Anonymous, id.getLabelString()));
+ return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createResource(id));
+ }
+
+ @Override
+ public SecuredResource createResource( final Resource type )
+ {
+ checkUpdate();
+ final SecurityEvaluator.SecTriple t = new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(RDF.type.asNode()),
+ SecuredItemImpl.convert(type.asNode()));
+ checkCreate(t);
+
+ return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createResource(type));
+ }
+
+ @Override
+ @Deprecated
+ public SecuredResource createResource( final ResourceF f )
+ {
+ return createResource(null, f);
+ }
+
+ @Override
+ public SecuredResource createResource( final String uri )
+ {
+ return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createResource(uri));
+
+ }
+
+ @Override
+ public SecuredResource createResource( final String uri, final Resource type )
+ {
+ final Resource r = ResourceFactory.createResource(uri);
+ final SecurityEvaluator.SecTriple t = new SecurityEvaluator.SecTriple(
+ SecuredItemImpl.convert(r.asNode()),
+ SecuredItemImpl.convert(RDF.type.asNode()),
+ SecuredItemImpl.convert(type.asNode()));
+ if (holder.getBaseItem().contains(r, RDF.type, type))
+ {
+ checkRead();
+ checkRead(t);
+ }
+ else
+ {
+ checkUpdate();
+ checkCreate(t);
+ }
+ return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createResource(uri, type));
+
+ }
+
+ @Override
+ @Deprecated
+ public SecuredResource createResource( final String uri, final ResourceF f )
+ {
+ // Resource resource = f.createResource( ResourceFactory.createResource( uri )
+ // );
+ // checkCreateResource( resource );
+ return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createResource(uri, f));
+ }
+
+ @Override
+ public SecuredSeq createSeq()
+ {
+ checkUpdate();
+ checkCreate(new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(RDF.type.asNode()),
+ SecuredItemImpl.convert(RDF.Alt.asNode())));
+ return SecuredSeqImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createSeq());
+ }
+
+ @Override
+ public SecuredSeq createSeq( final String uri )
+ {
+ checkUpdate();
+ checkCreate(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
+ RDF.Alt.asNode()));
+ return SecuredSeqImpl.getInstance(holder.getSecuredItem(),
+ holder.getBaseItem().createSeq(uri));
+ }
+
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final RDFNode o )
+ {
+ checkUpdate();
+ checkCreate(new Triple(s.asNode(), p.asNode(), o.asNode()));
+ return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createStatement(s, p, o));
+ }
+
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final String o )
+ {
+ checkUpdate();
+ checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createURI(o)));
+ return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createStatement(s, p, o));
+ }
+
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final String o, final boolean wellFormed )
+ {
+ return createStatement(s, p, o, "", wellFormed);
+ }
+
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final String o, final String l )
+ {
+ return createStatement(s, p, o, l, false);
+ }
+
+ @Override
+ public SecuredStatement createStatement( final Resource s,
+ final Property p, final String o, final String l,
+ final boolean wellFormed )
+ {
+ checkUpdate();
+ checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(o, l,
+ wellFormed)));
+ return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createStatement(s, p, o, l, wellFormed));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final boolean v )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(v));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final Calendar d )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(d));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final char v )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(v));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final double v )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(v));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final float v )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(v));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final int v )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(v));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final long v )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(v));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final Object value )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(value));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final Object value,
+ final RDFDatatype dtype )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(value, dtype));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final Object value,
+ final String typeURI )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(value, typeURI));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final String v )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(v));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final String lex,
+ final RDFDatatype dtype )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(lex, dtype));
+ }
+
+ @Override
+ public SecuredLiteral createTypedLiteral( final String lex,
+ final String typeURI )
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .createTypedLiteral(lex, typeURI));
+ }
+
+ @Override
+ public Model difference( final Model model )
+ {
+ checkRead();
+ if (canRead(Triple.ANY))
+ {
+ return holder.getBaseItem().difference(model);
+ }
+ else
+ {
+ return createCopy().difference(model);
+ }
+ }
+
+ @Override
+ public void enterCriticalSection( final boolean readLockRequested )
+ {
+ if (readLockRequested)
+ {
+ checkRead();
+ }
+ else
+ {
+ checkUpdate();
+ }
+ holder.getBaseItem().enterCriticalSection(readLockRequested);
+ }
+
+ @Override
+ public Object executeInTransaction( final Command cmd )
+ {
+ return holder.getBaseItem().executeInTransaction(cmd);
+ }
+
+ @Override
+ public String expandPrefix( final String prefixed )
+ {
+ checkRead();
+ return holder.getBaseItem().expandPrefix(prefixed);
+ }
+
+ @Override
+ public SecuredAlt getAlt( final Resource r )
+ {
+ checkRead();
+ checkRead(new Triple(r.asNode(), RDF.type.asNode(), RDF.Alt.asNode()));
+ return SecuredAltImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().getAlt(r));
+ }
+
+ @Override
+ public SecuredAlt getAlt( final String uri )
+ {
+ checkRead();
+ checkRead(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
+ RDF.Alt.asNode()));
+ return SecuredAltImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .getAlt(uri));
+ }
+
+ @Override
+ public SecuredResource getAnyReifiedStatement( final Statement s )
+ {
+ final RSIterator it = listReifiedStatements(s);
+ if (it.hasNext())
+ {
+ try
+ {
+ return SecuredReifiedStatementImpl.getInstance(holder.getSecuredItem(),
+ it.nextRS());
+ }
+ finally
+ {
+ it.close();
+ }
+ }
+ else
+ {
+ return SecuredReifiedStatementImpl.getInstance(holder.getSecuredItem(),
+ createReifiedStatement(s));
+ }
+ }
+
+ @Override
+ public SecuredBag getBag( final Resource r )
+ {
+ checkRead();
+ checkRead(new Triple(r.asNode(), RDF.type.asNode(), RDF.Bag.asNode()));
+ return SecuredBagImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().getBag(r));
+ }
+
+ @Override
+ public SecuredBag getBag( final String uri )
+ {
+ checkRead();
+ checkRead(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
+ RDF.Bag.asNode()));
+ return SecuredBagImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .getBag(uri));
+ }
+
+ @Override
+ public SecuredGraph getGraph()
+ {
+ return graph;
+ }
+
+ @Override
+ public Lock getLock()
+ {
+ return holder.getBaseItem().getLock();
+ }
+
+ @Override
+ public Map<String, String> getNsPrefixMap()
+ {
+ checkRead();
+ return holder.getBaseItem().getNsPrefixMap();
+ }
+
+ @Override
+ public String getNsPrefixURI( final String prefix )
+ {
+ checkRead();
+ return holder.getBaseItem().getNsPrefixURI(prefix);
+ }
+
+ @Override
+ public String getNsURIPrefix( final String uri )
+ {
+ checkRead();
+ return holder.getBaseItem().getNsURIPrefix(uri);
+ }
+
+ @Override
+ public SecuredStatement getProperty( final Resource s, final Property p )
+ {
+ final StmtIterator stmt = listStatements(s, p, (RDFNode) null);
+ try
+ {
+ if (stmt.hasNext())
+ {
+ return SecuredStatementImpl.getInstance(holder.getSecuredItem(), stmt.next());
+ }
+ return null;
+ }
+ finally
+ {
+ if (stmt != null)
+ {
+ stmt.close();
+ }
+ }
+ }
+
+ @Override
+ public SecuredProperty getProperty( final String uri )
+ {
+ checkRead();
+ return SecuredPropertyImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .getProperty(uri));
+ }
+
+ @Override
+ public SecuredProperty getProperty( final String nameSpace,
+ final String localName )
+ {
+ checkRead();
+ return SecuredPropertyImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .getProperty(nameSpace, localName));
+ }
+
+ @Override
+ public SecuredRDFNode getRDFNode( final Node n )
+ {
+ RDFNode rdfNode = null;
+ if (n.isLiteral())
+ {
+ rdfNode = ResourceFactory.createTypedLiteral(
+ n.getLiteralLexicalForm(), n.getLiteralDatatype());
+ }
+ else if (n.isURI())
+ {
+ rdfNode = ResourceFactory.createProperty(n.getURI());
+ }
+ else if (n.isBlank())
+ {
+ rdfNode = ResourceFactory.createResource(n.getBlankNodeId()
+ .toString());
+ }
+ else
+ {
+ throw new IllegalArgumentException("Illegal SecNode type: " + n);
+ }
+
+ if (holder.getBaseItem().containsResource(rdfNode))
+ {
+ checkRead();
+ }
+ else
+ {
+ checkUpdate();
+ }
+ if (n.isLiteral())
+ {
+ return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .getRDFNode(n).asLiteral());
+ }
+ else
+ {
+ return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .getRDFNode(n).asResource());
+ }
+ }
+
+ @Override
+ public RDFReader getReader()
+ {
+ return holder.getBaseItem().getReader();
+ }
+
+ @Override
+ public RDFReader getReader( final String lang )
+ {
+ return holder.getBaseItem().getReader(lang);
+ }
+
+ @Override
+ public void resetRDFReaderF() {
+ holder.getBaseItem().resetRDFReaderF();
+ }
+
+ @Override
+ public String removeReader(String lang) throws IllegalArgumentException {
+ return holder.getBaseItem().removeReader(lang);
+ }
+
+ @Override
+ public SecuredStatement getRequiredProperty( final Resource s,
+ final Property p )
+ {
+ checkRead();
+ if (canRead(Triple.ANY))
+ {
+ return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .getRequiredProperty(s, p));
+ }
+ else
+ {
+ final SecuredStatementIterator si = listStatements(s, p,
+ (RDFNode) null);
+ try
+ {
+ if (si.hasNext())
+ {
+ return (SecuredStatement) si.next();
+ }
+ else
+ {
+ throw new PropertyNotFoundException(p);
+ }
+ }
+ finally
+ {
+ si.close();
+ }
+ }
+ }
+
+ @Override
+ public SecuredResource getResource( final String uri )
+ {
+ return createResource(uri);
+ }
+
+ @Override
+ @Deprecated
+ public SecuredResource getResource( final String uri, final ResourceF f )
+ {
+ return createResource(uri, f);
+ }
+
+ @Override
+ public SecuredSeq getSeq( final Resource r )
+ {
+ checkRead();
+ checkRead(new Triple(r.asNode(), RDF.type.asNode(), RDF.Seq.asNode()));
+ return SecuredSeqImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().getSeq(r));
+ }
+
+ @Override
+ public SecuredSeq getSeq( final String uri )
+ {
+ checkRead();
+ checkRead(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
+ RDF.Seq.asNode()));
+ return SecuredSeqImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .getSeq(uri));
+ }
+
+ @Override
+ public RDFWriter getWriter()
+ {
+ return holder.getBaseItem().getWriter();
+ }
+
+ @Override
+ public RDFWriter getWriter( final String lang )
+ {
+ return holder.getBaseItem().getWriter(lang);
+ }
+
+ @Override
+ public void resetRDFWriterF() {
+ holder.getBaseItem().resetRDFWriterF();
+ }
+
+ @Override
+ public String removeWriter(String lang) throws IllegalArgumentException {
+ return holder.getBaseItem().removeWriter(lang);
+ }
+
+ @Override
+ public boolean independent()
+ {
+ return false;
+ }
+
+ @Override
+ public Model intersection( final Model model )
+ {
+ checkRead();
+ if (!canRead(Triple.ANY))
+ {
+ return holder.getBaseItem().intersection(model);
+ }
+ else
+ {
+ return createCopy().intersection(model);
+ }
+ }
+
+ @Override
+ public boolean isClosed()
+ {
+ return holder.getBaseItem().isClosed();
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ checkRead();
+ return holder.getBaseItem().isEmpty();
+ }
+
+ @Override
+ public boolean isIsomorphicWith( final Model g )
+ {
+ checkRead();
+ final boolean retval = holder.getBaseItem().isIsomorphicWith(g);
+ if (retval && !canRead(Triple.ANY))
+ {
+ // in this case we have to check all the items in the graph to see
+ // if the user can read
+ // them all.
+ final ExtendedIterator<Statement> stmtIter = holder.getBaseItem()
+ .listStatements();
+ try
+ {
+ while (stmtIter.hasNext())
+ {
+ if (!canRead(stmtIter.next().asTriple()))
+ {
+ return false;
+ }
+ }
+ }
+ finally
+ {
+ if (stmtIter != null)
+ {
+ stmtIter.close();
+ }
+ }
+ }
+ return retval;
+ }
+
+ @Override
+ public boolean isReified( final Statement s )
+ {
+ checkRead();
+ checkRead(s.asTriple());
+
+ final RSIterator it = listReifiedStatements(s);
+ try
+ {
+ return it.hasNext();
+ }
+ finally
+ {
+ it.close();
+ }
+ }
+
+ @Override
+ public void leaveCriticalSection()
+ {
+ holder.getBaseItem().leaveCriticalSection();
+ }
+
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate,
+ final boolean object )
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listLiteralStatements(subject, predicate, object));
+ }
+
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate, final char object )
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listLiteralStatements(subject, predicate, object));
+ }
+
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate,
+ final double object )
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listLiteralStatements(subject, predicate, object));
+ }
+
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate, final float object )
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listLiteralStatements(subject, predicate, object));
+ }
+
+ @Override
+ public SecuredStatementIterator listLiteralStatements(
+ final Resource subject, final Property predicate, final long object )
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listLiteralStatements(subject, predicate, object));
+ }
+
+ @Override
+ public NsIterator listNameSpaces()
+ {
+ checkRead();
+ return holder.getBaseItem().listNameSpaces();
+ }
+
+ @Override
+ public SecuredNodeIterator<RDFNode> listObjects()
+ {
+ checkRead();
+ ExtendedIterator<RDFNode> nIter = holder.getBaseItem().listObjects();
+ if (!canRead(SecTriple.ANY))
+ {
+ nIter = nIter.filterKeep( new ObjectFilter());
+ }
+ return new SecuredNodeIterator<RDFNode>(holder.getSecuredItem(), nIter);
+ }
+
+ @Override
+ public SecuredNodeIterator<RDFNode> listObjectsOfProperty( final Property p )
+ {
+ checkRead();
+ ExtendedIterator<RDFNode> nIter = holder.getBaseItem().listObjectsOfProperty(p);
+ if (!canRead(SecTriple.ANY))
+ {
+ nIter = nIter.filterKeep( new ObjectFilter(p));
+ }
+ return new SecuredNodeIterator<RDFNode>(holder.getSecuredItem(), nIter);
+ }
+
+ @Override
+ public SecuredNodeIterator<RDFNode> listObjectsOfProperty( final Resource s,
+ final Property p )
+ {
+ checkRead();
+ ExtendedIterator<RDFNode> nIter = holder.getBaseItem().listObjectsOfProperty(s, p);
+ if (!canRead(SecTriple.ANY))
+ {
+ nIter = nIter.filterKeep( new ObjectFilter(p));
+ }
+ return new SecuredNodeIterator<RDFNode>(holder.getSecuredItem(), nIter);
+ }
+
+ @Override
+ public SecuredRSIterator listReifiedStatements()
+ {
+ checkRead();
+ return new SecuredRSIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listReifiedStatements());
+ }
+
+ @Override
+ public SecuredRSIterator listReifiedStatements( final Statement st )
+ {
+ checkRead();
+ checkRead(st);
+ return new SecuredRSIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listReifiedStatements(st));
+ }
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p));
+ }
+ return new SecuredResIterator( holder.getSecuredItem(), rIter );
+
+ }
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final boolean o )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
+ }
+ return new SecuredResIterator( holder.getSecuredItem(), rIter );
+ }
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final char o )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
+ }
+ return new SecuredResIterator( holder.getSecuredItem(), rIter );
+ }
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final double o )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
+ }
+ return new SecuredResIterator( holder.getSecuredItem(), rIter );
+ }
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final float o )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
+ }
+ return new SecuredResIterator( holder.getSecuredItem(), rIter );
+ }
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final long o )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
+ }
+ return new SecuredResIterator( holder.getSecuredItem(), rIter );
+ }
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final Object o )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
+ }
+ return new SecuredResIterator( holder.getSecuredItem(), rIter );
+ }
+
+ @Override
+ public SecuredResIterator listResourcesWithProperty( final Property p,
+ final RDFNode o )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, o));
+ }
+ return new SecuredResIterator( holder.getSecuredItem(), rIter );
+ }
+
+ @Override
+ public SecuredStatementIterator listStatements()
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listStatements());
+ }
+
+ @Override
+ public SecuredStatementIterator listStatements( final Resource s,
+ final Property p, final RDFNode o )
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listStatements(s, p, o));
+ }
+
+ @Override
+ public SecuredStatementIterator listStatements( final Resource subject,
+ final Property predicate, final String object )
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listStatements(subject, predicate, object));
+ }
+
+ @Override
+ public SecuredStatementIterator listStatements( final Resource subject,
+ final Property predicate, final String object, final String lang )
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listStatements(subject, predicate, object, lang));
+ }
+
+ @Override
+ public SecuredStatementIterator listStatements( final Selector s )
+ {
+ checkRead();
+ return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
+ .listStatements(s));
+ }
+
+ @Override
+ public SecuredResIterator listSubjects()
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjects();
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter());
+ }
+ return new SecuredResIterator(holder.getSecuredItem(),rIter);
+ }
+
+ @Override
+ public SecuredResIterator listSubjectsWithProperty( final Property p )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjectsWithProperty(p);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p));
+ }
+ return new SecuredResIterator(holder.getSecuredItem(),rIter);
+ }
+
+ @Override
+ public SecuredResIterator listSubjectsWithProperty( final Property p,
+ final RDFNode o )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjectsWithProperty(p, o);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, o));
+ }
+ return new SecuredResIterator(holder.getSecuredItem(),rIter);
+ }
+
+ @Override
+ public SecuredResIterator listSubjectsWithProperty( final Property p,
+ final String o )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjectsWithProperty(p, o);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createPlainLiteral(o)));
+ }
+ return new SecuredResIterator(holder.getSecuredItem(),rIter);
+ }
+
+ @Override
+ public SecuredResIterator listSubjectsWithProperty( final Property p,
+ final String o, final String l )
+ {
+ checkRead();
+ ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjectsWithProperty(p, o, l);
+ if (!canRead( SecTriple.ANY))
+ {
+ rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createLangLiteral(o, l)));
+ }
+ return new SecuredResIterator(holder.getSecuredItem(),rIter);
+ }
+
+ @Override
+ public SecuredPrefixMapping lock()
+ {
+ checkUpdate();
+ holder.getBaseItem().lock();
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel notifyEvent( final Object e )
+ {
+ holder.getBaseItem().notifyEvent(e);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public String qnameFor( final String uri )
+ {
+ checkRead();
+ return holder.getBaseItem().qnameFor(uri);
+ }
+
+ @Override
+ public SecuredModel query( final Selector s )
+ {
+ checkRead();
+ return SecuredModelImpl.getInstance(holder.getSecuredItem(),
+ holder.getBaseItem().query(new SecuredSelector(holder.getSecuredItem(), s)));
+ }
+
+ @Override
+ public SecuredModel read( final InputStream in, final String base )
+ {
+ checkUpdate();
+ try
+ {
+ SecuredModelImpl.readerFactory.getReader().read(holder.getSecuredItem(), in, base);
+ return holder.getSecuredItem();
+ }
+ catch (final JenaException e)
+ {
+ if ((e.getCause() != null)
+ && (e.getCause() instanceof AccessDeniedException))
+ {
+ throw (AccessDeniedException) e.getCause();
+ }
+ throw e;
+ }
+ }
+
+ @Override
+ public SecuredModel read( final InputStream in, final String base,
+ final String lang )
+ {
+ checkUpdate();
+ try
+ {
+ SecuredModelImpl.readerFactory.getReader(lang).read(holder.getSecuredItem(), in, base);
+ return holder.getSecuredItem();
+ }
+ catch (final JenaException e)
+ {
+ if ((e.getCause() != null)
+ && (e.getCause() instanceof AccessDeniedException))
+ {
+ throw (AccessDeniedException) e.getCause();
+ }
+ throw e;
+ }
+ }
+
+ @Override
+ public SecuredModel read( final Reader reader, final String base )
+ {
+ checkUpdate();
+ try
+ {
+ SecuredModelImpl.readerFactory.getReader().read(holder.getSecuredItem(), reader, base);
+ return holder.getSecuredItem();
+ }
+ catch (final JenaException e)
+ {
+ if ((e.getCause() != null)
+ && (e.getCause() instanceof AccessDeniedException))
+ {
+ throw (AccessDeniedException) e.getCause();
+ }
+ throw e;
+ }
+ }
+
+ @Override
+ public SecuredModel read( final Reader reader, final String base,
+ final String lang )
+ {
+ checkUpdate();
+ try
+ {
+ SecuredModelImpl.readerFactory.getReader(lang).read(holder.getSecuredItem(), reader,
+ base);
+ return holder.getSecuredItem();
+ }
+ catch (final JenaException e)
+ {
+ if ((e.getCause() != null)
+ && (e.getCause() instanceof AccessDeniedException))
+ {
+ throw (AccessDeniedException) e.getCause();
+ }
+ throw e;
+ }
+ }
+
+ @Override
+ public SecuredModel read( final String url )
+ {
+ checkUpdate();
+ try
+ {
+ SecuredModelImpl.readerFactory.getReader().read(holder.getSecuredItem(), url);
+ return holder.getSecuredItem();
+ }
+ catch (final JenaException e)
+ {
+ if ((e.getCause() != null)
+ && (e.getCause() instanceof AccessDeniedException))
+ {
+ throw (AccessDeniedException) e.getCause();
+ }
+ throw e;
+ }
+ }
+
+ @Override
+ public SecuredModel read( final String url, final String lang )
+ {
+ checkUpdate();
+ try
+ {
+ SecuredModelImpl.readerFactory.getReader(lang).read(holder.getSecuredItem(), url);
+ return holder.getSecuredItem();
+ }
+ catch (final JenaException e)
+ {
+ if ((e.getCause() != null)
+ && (e.getCause() instanceof AccessDeniedException))
+ {
+ throw (AccessDeniedException) e.getCause();
+ }
+ throw e;
+ }
+ }
+
+ @Override
+ public SecuredModel read( final String url, final String base,
+ final String lang )
+ {
+ try
+ {
+ final InputStream is = new URL(url).openStream();
+ try
+ {
+ read(is, base, lang);
+ }
+ finally
+ {
+ if (null != is)
+ {
+ is.close();
+ }
+ }
+ }
+ catch (final IOException e)
+ {
+ throw new WrappedIOException(e);
+ }
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel register( final ModelChangedListener listener )
+ {
+ checkRead();
+ if (!listeners.containsKey(listener))
+ {
+ final SecuredModelChangedListener secL = new SecuredModelChangedListener(
+ listener);
+ listeners.put(listener, secL);
+ holder.getBaseItem().register(secL);
+ }
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel remove( final List<Statement> statements )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ for (final Statement s : statements)
+ {
+ checkDelete(s.asTriple());
+ }
+ }
+ holder.getBaseItem().remove(statements);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel remove( final Model m )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ final StmtIterator iter = m.listStatements();
+ try
+ {
+ while (iter.hasNext())
+ {
+ final Statement stmt = iter.next();
+ checkDelete(stmt);
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ holder.getBaseItem().remove(m);
+
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel remove( final Resource s, final Property p, final RDFNode o )
+ {
+ checkUpdate();
+ checkDelete(new Triple(s.asNode(), p.asNode(), o.asNode()));
+ holder.getBaseItem().remove(s, p, o);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel remove( final Statement s )
+ {
+ checkUpdate();
+ checkDelete(wildCardTriple(s));
+ holder.getBaseItem().remove(s);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel remove( final Statement[] statements )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ for (final Statement s : statements)
+ {
+ checkDelete(s.asTriple());
+ }
+ }
+ holder.getBaseItem().remove(statements);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel remove( final StmtIterator iter )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ final List<Triple> lst = new ArrayList<Triple>();
+ try
+ {
+ while (iter.hasNext())
+ {
+ final Statement s = iter.next();
+ checkDelete(s.asTriple());
+ lst.add(s.asTriple());
+ }
+ final Model m = ModelFactory
+ .createModelForGraph(new CollectionGraph(lst));
+ holder.getBaseItem().remove(m.listStatements());
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ else
+ {
+ holder.getBaseItem().remove(iter);
+ }
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel removeAll()
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ final StmtIterator iter = holder.getBaseItem().listStatements();
+ try
+ {
+ while (iter.hasNext())
+ {
+ checkDelete(iter.next());
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ holder.getBaseItem().removeAll();
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel removeAll( final Resource s, final Property p,
+ final RDFNode r )
+ {
+ checkUpdate();
+ if (!canDelete(new Triple(wildCardNode(s), wildCardNode(p),
+ wildCardNode(r))))
+ {
+ final StmtIterator iter = holder.getBaseItem().listStatements(s, p,
+ r);
+ try
+ {
+ while (iter.hasNext())
+ {
+ checkDelete(iter.next());
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ holder.getBaseItem().removeAll(s, p, r);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public void removeAllReifications( final Statement s )
+ {
+ checkUpdate();
+ if (canDelete(new Triple(Node.ANY, RDF.subject.asNode(),
+ wildCardNode(s.getSubject())))
+ && canDelete(new Triple(Node.ANY, RDF.predicate.asNode(),
+ wildCardNode(s.getPredicate())))
+ && canDelete(new Triple(Node.ANY, RDF.object.asNode(),
+ wildCardNode(s.getObject()))))
+ {
+ holder.getBaseItem().removeAllReifications(s);
+ }
+ else
+ {
+ final RSIterator iter = holder.getBaseItem().listReifiedStatements(
+ s);
+ try
+ {
+ while (iter.hasNext())
+ {
+ final ReifiedStatement rs = iter.next();
+ checkDelete(new Triple(rs.asNode(), RDF.subject.asNode(),
+ wildCardNode(s.getSubject())));
+ checkDelete(new Triple(rs.asNode(), RDF.predicate.asNode(),
+ wildCardNode(s.getPredicate())));
+ checkDelete(new Triple(rs.asNode(), RDF.object.asNode(),
+ wildCardNode(s.getObject())));
+ }
+ holder.getBaseItem().removeAllReifications(s);
+ }
+ finally
+ {
+ iter.close();
+ }
+
+ }
+ }
+
+ @Override
+ public SecuredPrefixMapping removeNsPrefix( final String prefix )
+ {
+ checkUpdate();
+ holder.getBaseItem().removeNsPrefix(prefix);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public void removeReification( final ReifiedStatement rs )
+ {
+ checkUpdate();
+ if (!canDelete(Triple.ANY))
+ {
+ final StmtIterator stmtIter = rs.listProperties();
+ try
+ {
+ while (stmtIter.hasNext())
+ {
+ checkDelete(stmtIter.next().asTriple());
+ }
+ }
+ finally
+ {
+ stmtIter.close();
+ }
+ }
+ holder.getBaseItem().removeReification(rs);
+ }
+
+ @Override
+ public boolean samePrefixMappingAs( final PrefixMapping other )
+ {
+ checkRead();
+ return holder.getBaseItem().samePrefixMappingAs(other);
+ }
+
+ @Override
+ public SecuredPrefixMapping setNsPrefix( final String prefix,
+ final String uri )
+ {
+ checkUpdate();
+ holder.getBaseItem().setNsPrefix(prefix, uri);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredPrefixMapping setNsPrefixes( final Map<String, String> map )
+ {
+ checkUpdate();
+ holder.getBaseItem().setNsPrefixes(map);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredPrefixMapping setNsPrefixes( final PrefixMapping other )
+ {
+ checkUpdate();
+ holder.getBaseItem().setNsPrefixes(other);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public String setReaderClassName( final String lang, final String className )
+ {
+ checkUpdate();
+ return holder.getBaseItem().setReaderClassName(lang, className);
+ }
+
+ @Override
+ public String setWriterClassName( final String lang, final String className )
+ {
+ checkUpdate();
+ return holder.getBaseItem().setWriterClassName(lang, className);
+ }
+
+ @Override
+ public String shortForm( final String uri )
+ {
+ checkRead();
+ return holder.getBaseItem().shortForm(uri);
+ }
+
+ @Override
+ public long size()
+ {
+ checkRead();
+ return holder.getBaseItem().size();
+ }
+
+ @Override
+ public boolean supportsSetOperations()
+ {
+ return holder.getBaseItem().supportsTransactions();
+ }
+
+ @Override
+ public boolean supportsTransactions()
+ {
+ return holder.getBaseItem().supportsTransactions();
+ }
+
+ @Override
+ public Model union( final Model model )
+ {
+ checkRead();
+ if (canRead(Triple.ANY))
+ {
+ return holder.getBaseItem().union(model);
+ }
+ else
+ {
+ return createCopy().union(model);
+ }
+ }
+
+ @Override
+ public SecuredModel unregister( final ModelChangedListener listener )
+ {
+ if (listeners.containsKey(listener))
+ {
+ final SecuredModelChangedListener secL = listeners.get(listener);
+ holder.getBaseItem().unregister(secL);
+ listeners.remove(listener);
+ }
+ return holder.getSecuredItem();
+ }
+
+ private Node wildCardNode( final RDFNode node )
+ {
+ return node == null ? Node.ANY : node.asNode();
+ }
+
+ private Triple wildCardTriple( final Statement s )
+ {
+ return new Triple(wildCardNode(s.getSubject()),
+ wildCardNode(s.getPredicate()), wildCardNode(s.getObject()));
+ }
+
+ @Override
+ public SecuredPrefixMapping withDefaultMappings( final PrefixMapping map )
+ {
+ checkUpdate();
+ holder.getBaseItem().withDefaultMappings(map);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredResource wrapAsResource( final Node n )
+ {
+ return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
+ .wrapAsResource(n));
+ }
+
+ @Override
+ public SecuredModel write( final OutputStream out )
+ {
+ checkRead();
+ if (canRead(Triple.ANY))
+ {
+ holder.getBaseItem().write(out);
+ }
+ else
+ {
+ getWriter().write(holder.getSecuredItem(), out, "");
+ }
+ return holder.getSecuredItem();
+
+ }
+
+ @Override
+ public SecuredModel write( final OutputStream out, final String lang )
+ {
+ checkRead();
+ if (canRead(Triple.ANY))
+ {
+ holder.getBaseItem().write(out, lang);
+ }
+ else
+ {
+ getWriter(lang).write(holder.getSecuredItem(), out, "");
+ }
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel write( final OutputStream out, final String lang,
+ final String base )
+ {
+ checkRead();
+ if (canRead(Triple.ANY))
+ {
+ holder.getBaseItem().write(out, lang, base);
+ }
+ else
+ {
+ getWriter(lang).write(holder.getSecuredItem(), out, base);
+ }
+ return holder.getSecuredItem();
+
+ }
+
+ @Override
+ public SecuredModel write( final Writer writer )
+ {
+ checkRead();
+ if (canRead(Triple.ANY))
+ {
+ holder.getBaseItem().write(writer);
+ }
+ else
+ {
+ getWriter().write(holder.getSecuredItem(), writer, "");
+ }
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel write( final Writer writer, final String lang )
+ {
+ checkRead();
+ if (canRead(Triple.ANY))
+ {
+ holder.getBaseItem().write(writer, lang);
+ }
+ else
+ {
+ getWriter(lang).write(holder.getSecuredItem(), writer, "");
+ }
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredModel write( final Writer writer, final String lang,
+ final String base )
+ {
+ checkRead();
+ if (canRead(Triple.ANY))
+ {
+ holder.getBaseItem().write(writer, lang, base);
+ }
+ else
+ {
+ getWriter(lang).write(holder.getSecuredItem(), writer, base);
+ }
+ return holder.getSecuredItem();
+
+ }
+
+ private class ResourceFilter extends Filter<Resource> {
+ Property p;
+ RDFNode o;
+
+ ResourceFilter() {
+ this(null, null);
+ }
+
+ ResourceFilter( Property p)
+ {
+ this(p,null);
+ }
+
+ ResourceFilter( Property p, RDFNode o)
+ {
+ this.p = p;
+ this.o = o;
+ }
+
+ @Override
+ public boolean accept(Resource s) {
+ StmtIterator iter = listStatements(s, p, o);
+ try {
+ return iter.hasNext();
+ }
+ finally {
+ iter.close();
+ }
+ }
+
+ }
+
+ private class ObjectFilter extends Filter<RDFNode> {
+ Resource s;
+ Property p;
+
+ ObjectFilter( ) {
+ this(null,null);
+ }
+
+ ObjectFilter( Property p )
+ {
+ this(null, p );
+ }
+
+ ObjectFilter( Resource s, Property p)
+ {
+ this.s = s;
+ this.p = p;
+ }
+
+ @Override
+ public boolean accept(RDFNode o) {
+ StmtIterator iter = listStatements(s, p, o);
+ try {
+ return iter.hasNext();
+ }
+ finally {
+ iter.close();
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredNodeIterator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredNodeIterator.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredNodeIterator.java
new file mode 100644
index 0000000..2fd93ce
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredNodeIterator.java
@@ -0,0 +1,143 @@
+/*
+ * 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.model.impl;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import org.apache.jena.rdf.model.NodeIterator ;
+import org.apache.jena.rdf.model.RDFNode ;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredRDFNode;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.Filter ;
+import org.apache.jena.util.iterator.Map1 ;
+
+/**
+ * A secured RDFNode iterator implementation
+ */
+public class SecuredNodeIterator<T extends RDFNode> implements NodeIterator
+{
+ private class PermNodeMap<N extends RDFNode> implements Map1<N, RDFNode>
+ {
+ private final SecuredModel securedModel;
+
+ public PermNodeMap( final SecuredModel securedModel )
+ {
+ this.securedModel = securedModel;
+ }
+
+ @Override
+ public SecuredRDFNode map1( final RDFNode o )
+ {
+ return SecuredRDFNodeImpl.getInstance(securedModel, o);
+ }
+ }
+
+ private final ExtendedIterator<RDFNode> iter;
+
+ /**
+ * Constructor
+ *
+ * @param securedItem
+ * the item defining the security context
+ * @param wrapped
+ * the iterator to be wrapped.
+ */
+ SecuredNodeIterator( final SecuredModel securedModel,
+ final ExtendedIterator<T> wrapped )
+ {
+ final PermNodeMap<T> map1 = new PermNodeMap<T>(securedModel);
+ iter = wrapped.mapWith(map1);
+ }
+
+ @Override
+ public <X extends RDFNode> ExtendedIterator<RDFNode> andThen(
+ final Iterator<X> other )
+ {
+ return iter.andThen(other);
+ }
+
+ @Override
+ public void close()
+ {
+ iter.close();
+ }
+
+ @Override
+ public ExtendedIterator<RDFNode> filterDrop( final Filter<RDFNode> f )
+ {
+ return iter.filterDrop(f);
+ }
+
+ @Override
+ public ExtendedIterator<RDFNode> filterKeep( final Filter<RDFNode> f )
+ {
+ return iter.filterKeep(f);
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return iter.hasNext();
+ }
+
+ @Override
+ public <U> ExtendedIterator<U> mapWith( final Map1<RDFNode, U> map1 )
+ {
+ return iter.mapWith(map1);
+ }
+
+ @Override
+ public RDFNode next()
+ {
+ return iter.next();
+ }
+
+ @Override
+ public RDFNode nextNode() throws NoSuchElementException
+ {
+ return next();
+ }
+
+ @Override
+ public void remove()
+ {
+ iter.remove();
+ }
+
+ @Override
+ public RDFNode removeNext()
+ {
+ return iter.removeNext();
+ }
+
+ @Override
+ public List<RDFNode> toList()
+ {
+ return iter.toList();
+ }
+
+ @Override
+ public Set<RDFNode> toSet()
+ {
+ return iter.toSet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredPropertyImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredPropertyImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredPropertyImpl.java
new file mode 100644
index 0000000..c0ee426
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredPropertyImpl.java
@@ -0,0 +1,129 @@
+/*
+ * 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.model.impl;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.Property ;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemInvoker;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredProperty;
+
+/**
+ * Implementation of SecuredProperty to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredPropertyImpl extends SecuredResourceImpl implements
+ SecuredProperty
+{
+ /**
+ * Get an instance of SecuredProperty
+ *
+ * @param securedModel
+ * the Secured Model to use.
+ * @param property
+ * The property to secure
+ * @return The SecuredProperty
+ */
+ public static SecuredProperty getInstance( final SecuredModel securedModel,
+ final Property property )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (property == null)
+ {
+ throw new IllegalArgumentException("Property may not be null");
+ }
+
+ // check that property has a securedModel.
+ Property goodProp = property;
+ if (goodProp.getModel() == null)
+ {
+ final Node n = property.asNode();
+ if (property.isAnon())
+ {
+ goodProp = securedModel.createProperty(n.getBlankNodeId()
+ .getLabelString());
+ }
+ else
+ {
+ goodProp = securedModel.createProperty(property.asNode()
+ .getURI());
+ }
+ }
+
+ final ItemHolder<Property, SecuredProperty> holder = new ItemHolder<Property, SecuredProperty>(
+ goodProp);
+ final SecuredPropertyImpl checker = new SecuredPropertyImpl(
+ securedModel, holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (goodProp instanceof SecuredProperty)
+ {
+ if (checker.isEquivalent((SecuredProperty) goodProp))
+ {
+ return (SecuredProperty) goodProp;
+ }
+ }
+ return holder.setSecuredItem(new SecuredItemInvoker(
+ property.getClass(), checker));
+ }
+
+ // the item holder that contains this SecuredProperty
+ private final ItemHolder<? extends Property, ? extends SecuredProperty> holder;
+
+ /**
+ * Constructor
+ *
+ * @param securityEvaluator
+ * The security evaluator to use.
+ * @param graphIRI
+ * the graph IRI to validate against.
+ * @param holder
+ * The item holder that will contain this SecuredProperty.
+ */
+ private SecuredPropertyImpl(
+ final SecuredModel securedModel,
+ final ItemHolder<? extends Property, ? extends SecuredProperty> holder )
+ {
+ super(securedModel, holder);
+ this.holder = holder;
+ }
+
+ @Override
+ public int getOrdinal()
+ {
+ checkRead();
+ return holder.getBaseItem().getOrdinal();
+ }
+
+ @Override
+ public Property inModel( final Model m )
+ {
+ return (Property) super.inModel(m);
+ }
+
+ @Override
+ public boolean isProperty()
+ {
+ return true;
+ }
+}
[24/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
Module jena-seurity becomes jena-permissions
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/b712fb28
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/b712fb28
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/b712fb28
Branch: refs/heads/jena3
Commit: b712fb2859a9f5950ec9236f9d04584e8dc39e68
Parents: 93570e5
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Apr 24 13:19:06 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Apr 24 13:19:06 2015 +0100
----------------------------------------------------------------------
jena-permissions/LICENSE | 202 ++
jena-permissions/NOTICE | 5 +
jena-permissions/license-header.txt | 15 +
jena-permissions/pom.xml | 203 ++
jena-permissions/readme.md | 32 +
.../jena/security/example/ExampleEvaluator.java | 147 +
.../jena/security/example/SecurityExample.java | 93 +
.../security/example/ShiroExampleEvaluator.java | 235 ++
.../apache/jena/security/example/example.ttl | 49 +
.../jena/security/example/fuseki/config.ttl | 98 +
.../jena/security/example/fuseki/shiro.ini | 47 +
.../jena/security/AccessDeniedException.java | 66 +
.../jena/security/AssemblerConstants.java | 62 +
.../java/org/apache/jena/security/Factory.java | 69 +
.../apache/jena/security/SecuredAssembler.java | 264 ++
.../apache/jena/security/SecurityEvaluator.java | 616 ++++
.../security/SecurityEvaluatorAssembler.java | 183 ++
.../graph/SecuredBulkUpdateHandler.java | 148 +
.../security/graph/SecuredCapabilities.java | 151 +
.../jena/security/graph/SecuredGraph.java | 176 ++
.../graph/SecuredGraphEventManager.java | 608 ++++
.../security/graph/SecuredPrefixMapping.java | 133 +
.../jena/security/graph/impl/Factory.java | 129 +
.../impl/SecuredBulkUpdateHandlerImpl.java | 242 ++
.../security/graph/impl/SecuredGraphImpl.java | 303 ++
.../graph/impl/SecuredPrefixMappingImpl.java | 167 ++
.../jena/security/graph/package-info.java | 50 +
.../security/impl/CachedSecurityEvaluator.java | 90 +
.../apache/jena/security/impl/ItemHolder.java | 117 +
.../apache/jena/security/impl/SecuredItem.java | 185 ++
.../jena/security/impl/SecuredItemImpl.java | 842 ++++++
.../jena/security/impl/SecuredItemInvoker.java | 146 +
.../apache/jena/security/model/SecuredAlt.java | 264 ++
.../apache/jena/security/model/SecuredBag.java | 29 +
.../jena/security/model/SecuredContainer.java | 218 ++
.../jena/security/model/SecuredLiteral.java | 165 ++
.../jena/security/model/SecuredModel.java | 1566 ++++++++++
.../jena/security/model/SecuredProperty.java | 38 +
.../jena/security/model/SecuredRDFList.java | 414 +++
.../jena/security/model/SecuredRDFNode.java | 59 +
.../security/model/SecuredReifiedStatement.java | 38 +
.../jena/security/model/SecuredResource.java | 333 +++
.../apache/jena/security/model/SecuredSeq.java | 385 +++
.../jena/security/model/SecuredStatement.java | 295 ++
...SecuredUnsupportedPolymorphismException.java | 36 +
.../security/model/impl/SecuredAltImpl.java | 339 +++
.../security/model/impl/SecuredBagImpl.java | 81 +
.../model/impl/SecuredContainerImpl.java | 576 ++++
.../security/model/impl/SecuredLiteralImpl.java | 277 ++
.../security/model/impl/SecuredModelImpl.java | 2739 ++++++++++++++++++
.../model/impl/SecuredNodeIterator.java | 143 +
.../model/impl/SecuredPropertyImpl.java | 129 +
.../security/model/impl/SecuredRDFListImpl.java | 1058 +++++++
.../security/model/impl/SecuredRDFNodeImpl.java | 253 ++
.../security/model/impl/SecuredRSIterator.java | 174 ++
.../model/impl/SecuredReifiedStatementImpl.java | 99 +
.../security/model/impl/SecuredResIterator.java | 133 +
.../model/impl/SecuredResourceImpl.java | 893 ++++++
.../security/model/impl/SecuredSelector.java | 94 +
.../security/model/impl/SecuredSeqImpl.java | 511 ++++
.../model/impl/SecuredStatementImpl.java | 560 ++++
.../model/impl/SecuredStatementIterator.java | 148 +
.../org/apache/jena/security/package-info.java | 48 +
.../jena/security/query/SecuredQueryEngine.java | 152 +
.../query/SecuredQueryEngineConfig.java | 29 +
.../query/SecuredQueryEngineFactory.java | 115 +
.../security/query/rewriter/OpRewriter.java | 592 ++++
.../query/rewriter/SecuredFunction.java | 138 +
.../jena/security/utils/ContainerFilter.java | 48 +
.../security/utils/PermStatementFilter.java | 164 ++
.../jena/security/utils/PermTripleFilter.java | 163 ++
.../jena/security/utils/RDFListIterator.java | 79 +
.../jena/security/utils/RDFListSecFilter.java | 58 +
jena-permissions/src/main/overview.html | 83 +
.../apache/jena/security/EqualityTester.java | 49 +
.../apache/jena/security/MockPrefixMapping.java | 105 +
.../jena/security/MockSecurityEvaluator.java | 228 ++
.../security/ModelBasedSecurityEvaluator.java | 76 +
.../jena/security/SecuredAssemblerTest.java | 84 +
.../security/SecurityEvaluatorParameters.java | 135 +
.../jena/security/StaticSecurityEvaluator.java | 78 +
.../graph/CachedSecurityEvaluatorTest.java | 45 +
.../graph/SecuredGraphContractTests.java | 51 +
.../graph/SecuredGraphListenerTest.java | 51 +
.../graph/SecuredTDBGraphContractTests.java | 51 +
.../security/contract/model/ModelTestSuite.java | 132 +
.../contract/model/SecTestLiterals.java | 29 +
.../security/contract/model/SecTestPackage.java | 120 +
.../contract/model/SecTestReaderEvents.java | 28 +
.../security/contract/model/SecTestReaders.java | 28 +
.../security/graph/BulkUpdateHandlerTest.java | 372 +++
.../graph/CrossIDGraphEventManagerTest.java | 77 +
.../security/graph/GraphEventManagerTest.java | 239 ++
.../jena/security/graph/MemGraphTest.java | 387 +++
.../security/graph/RecordingGraphListener.java | 124 +
.../graph/SecuredPrefixMappingTest.java | 440 +++
.../jena/security/graph/TDBGraphTest.java | 58 +
.../jena/security/model/SecuredAltTest.java | 657 +++++
.../jena/security/model/SecuredBagTest.java | 46 +
.../security/model/SecuredContainerTest.java | 480 +++
.../jena/security/model/SecuredLiteralTest.java | 468 +++
.../security/model/SecuredModelDetailTest.java | 335 +++
.../jena/security/model/SecuredModelTest.java | 2034 +++++++++++++
.../security/model/SecuredPropertyTest.java | 79 +
.../jena/security/model/SecuredRDFListTest.java | 970 +++++++
.../jena/security/model/SecuredRDFNodeTest.java | 209 ++
.../model/SecuredReifiedStatementTest.java | 84 +
.../security/model/SecuredResourceTest.java | 827 ++++++
.../jena/security/model/SecuredSeqTest.java | 1013 +++++++
.../security/model/SecuredStatementTest.java | 707 +++++
.../apache/jena/security/query/DataSetTest.java | 244 ++
.../jena/security/query/QueryEngineTest.java | 259 ++
.../security/query/rewriter/OpRewriterTest.java | 111 +
.../src/test/resources/log4j.properties | 15 +
.../jena/security/SecuredAssemblerTest.ttl | 56 +
.../org/apache/jena/security/model/detail.ttl | 33 +
.../org/apache/jena/security/model/test.ttl | 2 +
.../org/apache/jena/security/model/test.xml | 7 +
jena-security/LICENSE | 202 --
jena-security/NOTICE | 5 -
jena-security/license-header.txt | 15 -
jena-security/pom.xml | 203 --
jena-security/readme.md | 32 -
.../jena/security/example/ExampleEvaluator.java | 147 -
.../jena/security/example/SecurityExample.java | 93 -
.../security/example/ShiroExampleEvaluator.java | 235 --
.../apache/jena/security/example/example.ttl | 49 -
.../jena/security/example/fuseki/config.ttl | 98 -
.../jena/security/example/fuseki/shiro.ini | 47 -
.../jena/security/AccessDeniedException.java | 66 -
.../jena/security/AssemblerConstants.java | 62 -
.../java/org/apache/jena/security/Factory.java | 69 -
.../apache/jena/security/SecuredAssembler.java | 264 --
.../apache/jena/security/SecurityEvaluator.java | 616 ----
.../security/SecurityEvaluatorAssembler.java | 183 --
.../graph/SecuredBulkUpdateHandler.java | 148 -
.../security/graph/SecuredCapabilities.java | 151 -
.../jena/security/graph/SecuredGraph.java | 176 --
.../graph/SecuredGraphEventManager.java | 608 ----
.../security/graph/SecuredPrefixMapping.java | 133 -
.../jena/security/graph/impl/Factory.java | 129 -
.../impl/SecuredBulkUpdateHandlerImpl.java | 242 --
.../security/graph/impl/SecuredGraphImpl.java | 303 --
.../graph/impl/SecuredPrefixMappingImpl.java | 167 --
.../jena/security/graph/package-info.java | 50 -
.../security/impl/CachedSecurityEvaluator.java | 90 -
.../apache/jena/security/impl/ItemHolder.java | 117 -
.../apache/jena/security/impl/SecuredItem.java | 185 --
.../jena/security/impl/SecuredItemImpl.java | 842 ------
.../jena/security/impl/SecuredItemInvoker.java | 146 -
.../apache/jena/security/model/SecuredAlt.java | 264 --
.../apache/jena/security/model/SecuredBag.java | 29 -
.../jena/security/model/SecuredContainer.java | 218 --
.../jena/security/model/SecuredLiteral.java | 165 --
.../jena/security/model/SecuredModel.java | 1566 ----------
.../jena/security/model/SecuredProperty.java | 38 -
.../jena/security/model/SecuredRDFList.java | 414 ---
.../jena/security/model/SecuredRDFNode.java | 59 -
.../security/model/SecuredReifiedStatement.java | 38 -
.../jena/security/model/SecuredResource.java | 333 ---
.../apache/jena/security/model/SecuredSeq.java | 385 ---
.../jena/security/model/SecuredStatement.java | 295 --
...SecuredUnsupportedPolymorphismException.java | 36 -
.../security/model/impl/SecuredAltImpl.java | 339 ---
.../security/model/impl/SecuredBagImpl.java | 81 -
.../model/impl/SecuredContainerImpl.java | 576 ----
.../security/model/impl/SecuredLiteralImpl.java | 277 --
.../security/model/impl/SecuredModelImpl.java | 2739 ------------------
.../model/impl/SecuredNodeIterator.java | 143 -
.../model/impl/SecuredPropertyImpl.java | 129 -
.../security/model/impl/SecuredRDFListImpl.java | 1058 -------
.../security/model/impl/SecuredRDFNodeImpl.java | 253 --
.../security/model/impl/SecuredRSIterator.java | 174 --
.../model/impl/SecuredReifiedStatementImpl.java | 99 -
.../security/model/impl/SecuredResIterator.java | 133 -
.../model/impl/SecuredResourceImpl.java | 893 ------
.../security/model/impl/SecuredSelector.java | 94 -
.../security/model/impl/SecuredSeqImpl.java | 511 ----
.../model/impl/SecuredStatementImpl.java | 560 ----
.../model/impl/SecuredStatementIterator.java | 148 -
.../org/apache/jena/security/package-info.java | 48 -
.../jena/security/query/SecuredQueryEngine.java | 152 -
.../query/SecuredQueryEngineConfig.java | 29 -
.../query/SecuredQueryEngineFactory.java | 115 -
.../security/query/rewriter/OpRewriter.java | 592 ----
.../query/rewriter/SecuredFunction.java | 138 -
.../jena/security/utils/ContainerFilter.java | 48 -
.../security/utils/PermStatementFilter.java | 164 --
.../jena/security/utils/PermTripleFilter.java | 163 --
.../jena/security/utils/RDFListIterator.java | 79 -
.../jena/security/utils/RDFListSecFilter.java | 58 -
jena-security/src/main/overview.html | 83 -
.../apache/jena/security/EqualityTester.java | 49 -
.../apache/jena/security/MockPrefixMapping.java | 105 -
.../jena/security/MockSecurityEvaluator.java | 228 --
.../security/ModelBasedSecurityEvaluator.java | 76 -
.../jena/security/SecuredAssemblerTest.java | 84 -
.../security/SecurityEvaluatorParameters.java | 135 -
.../jena/security/StaticSecurityEvaluator.java | 78 -
.../graph/CachedSecurityEvaluatorTest.java | 45 -
.../graph/SecuredGraphContractTests.java | 51 -
.../graph/SecuredGraphListenerTest.java | 51 -
.../graph/SecuredTDBGraphContractTests.java | 51 -
.../security/contract/model/ModelTestSuite.java | 132 -
.../contract/model/SecTestLiterals.java | 29 -
.../security/contract/model/SecTestPackage.java | 120 -
.../contract/model/SecTestReaderEvents.java | 28 -
.../security/contract/model/SecTestReaders.java | 28 -
.../security/graph/BulkUpdateHandlerTest.java | 372 ---
.../graph/CrossIDGraphEventManagerTest.java | 77 -
.../security/graph/GraphEventManagerTest.java | 239 --
.../jena/security/graph/MemGraphTest.java | 387 ---
.../security/graph/RecordingGraphListener.java | 124 -
.../graph/SecuredPrefixMappingTest.java | 440 ---
.../jena/security/graph/TDBGraphTest.java | 58 -
.../jena/security/model/SecuredAltTest.java | 657 -----
.../jena/security/model/SecuredBagTest.java | 46 -
.../security/model/SecuredContainerTest.java | 480 ---
.../jena/security/model/SecuredLiteralTest.java | 468 ---
.../security/model/SecuredModelDetailTest.java | 335 ---
.../jena/security/model/SecuredModelTest.java | 2034 -------------
.../security/model/SecuredPropertyTest.java | 79 -
.../jena/security/model/SecuredRDFListTest.java | 970 -------
.../jena/security/model/SecuredRDFNodeTest.java | 209 --
.../model/SecuredReifiedStatementTest.java | 84 -
.../security/model/SecuredResourceTest.java | 827 ------
.../jena/security/model/SecuredSeqTest.java | 1013 -------
.../security/model/SecuredStatementTest.java | 707 -----
.../apache/jena/security/query/DataSetTest.java | 244 --
.../jena/security/query/QueryEngineTest.java | 259 --
.../security/query/rewriter/OpRewriterTest.java | 111 -
.../src/test/resources/log4j.properties | 15 -
.../jena/security/SecuredAssemblerTest.ttl | 56 -
.../org/apache/jena/security/model/detail.ttl | 33 -
.../org/apache/jena/security/model/test.ttl | 2 -
.../org/apache/jena/security/model/test.xml | 7 -
pom.xml | 4 +-
237 files changed, 31214 insertions(+), 31214 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/LICENSE
----------------------------------------------------------------------
diff --git a/jena-permissions/LICENSE b/jena-permissions/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/jena-permissions/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/NOTICE
----------------------------------------------------------------------
diff --git a/jena-permissions/NOTICE b/jena-permissions/NOTICE
new file mode 100644
index 0000000..d4e11ad
--- /dev/null
+++ b/jena-permissions/NOTICE
@@ -0,0 +1,5 @@
+Apache Jena - Security module
+Copyright 2011, 2012, 2013, 2014, 2015 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/license-header.txt
----------------------------------------------------------------------
diff --git a/jena-permissions/license-header.txt b/jena-permissions/license-header.txt
new file mode 100644
index 0000000..2114391
--- /dev/null
+++ b/jena-permissions/license-header.txt
@@ -0,0 +1,15 @@
+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.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/pom.xml
----------------------------------------------------------------------
diff --git a/jena-permissions/pom.xml b/jena-permissions/pom.xml
new file mode 100644
index 0000000..95fa648
--- /dev/null
+++ b/jena-permissions/pom.xml
@@ -0,0 +1,203 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-permissions</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ </properties>
+ <name>Apache Jena - Security Permissions</name>
+ <description>Security Permissions wrapper around Jena RDF implementation.</description>
+ <url>http://jena.apache.org/documentation/security</url>
+ <inceptionYear>2012</inceptionYear>
+
+ <parent>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-parent</artifactId>
+ <version>14-SNAPSHOT</version>
+ <relativePath>../jena-parent</relativePath>
+ </parent>
+ <organization>
+ <name>The Apache Software Foundation</name>
+ <url>http://www.apache.org/</url>
+ </organization>
+ <issueManagement>
+ <url>http://issues.apache.org/jira/browse/JENA</url>
+ <system>JIRA</system>
+ </issueManagement>
+ <repositories>
+ <repository>
+ <id>apache-snapshots-repo</id>
+ <url>https://repository.apache.org/content/repositories/snapshots/</url>
+ </repository>
+ <repository>
+ <id>apache-staging-repo</id>
+ <url>https://repository.apache.org/content/repositories/staging/</url>
+ </repository>
+ <repository>
+ <id>apache-releases-repo</id>
+ <url>https://repository.apache.org/content/repositories/releases/</url>
+ </repository>
+ </repositories>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.9.1</version>
+ <executions>
+ <execution>
+ <id>add-example-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/example/java</source>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>add-example-resource</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-resource</goal>
+ </goals>
+ <configuration>
+ <resources>
+ <resource>
+ <directory>src/example/resources</directory>
+ <targetPath>${project.build.outputDirectory}</targetPath>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <!-- <version>2.9</version> -->
+ <configuration>
+ <excludePackageNames>org.apache.jena.security.example:org.apache.jena.security.example.*</excludePackageNames>
+ <tags>
+ <tag>
+ <name>sec.graph</name>
+ <!-- tag for all places -->
+ <placement>a</placement>
+ <head>Required graph permissions:</head>
+ </tag>
+ <tag>
+ <name>sec.triple</name>
+ <!-- tag for all places -->
+ <placement>a</placement>
+ <head>Required triple permissions:</head>
+ </tag>
+ </tags>
+ <overview>${basedir}/src/main/overview.html</overview>
+
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>org/apache/jena/security/example/**</exclude>
+ </excludes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>create-test-jar</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>create-example-jar</id>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classedDirectory>target</classedDirectory>
+ <classifier>example</classifier>
+ <includes>
+ <include>../src/example/**</include>
+ <include>../src/example</include>
+ <include>META-INF/**</include>
+ <include>org/apache/jena/security/example/**</include>
+ </includes>
+ <excludes>
+ <exclude>META-INF/DEPENDENCIES</exclude>
+ </excludes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>apache-jena-libs</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-core</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-core</artifactId>
+ <version>1.2.2</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/readme.md
----------------------------------------------------------------------
diff --git a/jena-permissions/readme.md b/jena-permissions/readme.md
new file mode 100644
index 0000000..5feaa42
--- /dev/null
+++ b/jena-permissions/readme.md
@@ -0,0 +1,32 @@
+REQUIRES Jena 2.10.0
+
+JenaSecurity is a SecurityEvaluator interface and a set of dynamic proxies that apply that interface to Jena Graphs, Models, and associated methods and classes.
+
+The SecurityEvaluator class must be implemented. This class provides the interface to the authentication results (e.g. getPrincipal())) and the authorization system.
+
+Create a SecuredGraph by calling Factory.getInstance( SecurityEvaluator, String, Graph );
+Create a SecuredModel by calling Factory.getInstance( SecurityEvaluator, String, Model ) or ModelFactory.createModelForGraph( SecuredGraph );
+
+NOTE: when creating a model by wrapping a secured graph (e.g. ModelFactory.createModelForGraph( SecuredGraph );) the resulting Model does not
+have the same security requirements that the standard secured model does.
+
+For instance when creating a list on a secured model calling model.createList( RDFNode[] ); The standard secured model verifies that the user
+has the right to update the triples and allows or denies the entire operation accordingly. The wrapped secured graph does not have visibility
+to the createList() command and can only operate on the instructions issued by the model.createList() implementation. In the standard implementation
+the model requests the graph to delete one triple and then insert another. Thus the user must have delete and add permissions, not the update permission.
+
+There are several other cases where the difference in the layer can trip up the security system. In all known cases the result is a tighter
+security definition than was requested. For simplicity sake we recommend that the wrapped secured graph only be used in cases where access to the
+graph as a whole is granted/denied. In these cases the user either has all CRUD capabilities or none.
+
+[] a ja:Model ;
+ sec:baseModel jena:model ;
+ ja:modelName "modelName";
+ sec:evaluatorFactory "javaclass";
+ .
+
+jena:model A model defined in the assembler file.
+"modelName" The name of the model as identified in the security manager
+"javaclass" The name of a java class that implements a Evaluator Factory. The Factory must have static method getInstance() that
+returns a SecurityEvaluator.
+
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/example/java/org/apache/jena/security/example/ExampleEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/example/java/org/apache/jena/security/example/ExampleEvaluator.java b/jena-permissions/src/example/java/org/apache/jena/security/example/ExampleEvaluator.java
new file mode 100644
index 0000000..3ed244e
--- /dev/null
+++ b/jena-permissions/src/example/java/org/apache/jena/security/example/ExampleEvaluator.java
@@ -0,0 +1,147 @@
+/*
+ * 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.example;
+
+import java.security.Principal;
+import java.util.Set;
+
+import org.apache.http.auth.BasicUserPrincipal;
+import org.apache.jena.security.SecurityEvaluator;
+
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.rdf.model.AnonId;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.Property;
+import org.apache.jena.rdf.model.RDFNode;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.rdf.model.ResourceFactory;
+import org.apache.jena.vocabulary.RDF;
+
+/**
+ * An example evaluator that only provides access to messages in the graph that
+ * are from or to the principal.
+ *
+ */
+public class ExampleEvaluator implements SecurityEvaluator {
+
+ private Principal principal;
+ private Model model;
+ private RDFNode msgType = ResourceFactory.createResource( "http://example.com/msg" );
+ private Property pTo = ResourceFactory.createProperty( "http://example.com/to" );
+ private Property pFrom = ResourceFactory.createProperty( "http://example.com/from" );
+
+ /**
+ *
+ * @param model The graph we are going to evaluate against.
+ */
+ public ExampleEvaluator( Model model )
+ {
+ this.model = model;
+ }
+
+ @Override
+ public boolean evaluate(Object principal, Action action, SecNode graphIRI) {
+ // we allow any action on a graph.
+ return true;
+ }
+
+ private boolean evaluate( Object principalObj, Resource r )
+ {
+ Principal principal = (Principal)principalObj;
+ // a message is only available to sender or recipient
+ if (r.hasProperty( RDF.type, msgType ))
+ {
+ return r.hasProperty( pTo, principal.getName() ) ||
+ r.hasProperty( pFrom, principal.getName());
+ }
+ return true;
+ }
+
+ private boolean evaluate( Object principal, SecNode node )
+ {
+ if (node.equals( SecNode.ANY )) {
+ return false; // all wild cards are false
+ }
+
+ if (node.getType().equals( SecNode.Type.URI)) {
+ Resource r = model.createResource( node.getValue() );
+ return evaluate( principal, r );
+ }
+ else if (node.getType().equals( SecNode.Type.Anonymous)) {
+ Resource r = model.getRDFNode( NodeFactory.createAnon( new AnonId( node.getValue()) ) ).asResource();
+ return evaluate( principal, r );
+ }
+ else
+ {
+ return true;
+ }
+
+ }
+
+ private boolean evaluate( Object principal, SecTriple triple ) {
+ return evaluate( principal, triple.getSubject()) &&
+ evaluate( principal, triple.getObject()) &&
+ evaluate( principal, triple.getPredicate());
+ }
+
+ @Override
+ public boolean evaluate(Object principal, Action action, SecNode graphIRI, SecTriple triple) {
+ return evaluate( principal, triple );
+ }
+
+ @Override
+ public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI) {
+ return true;
+ }
+
+ @Override
+ public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI,
+ SecTriple triple) {
+ return evaluate( principal, triple );
+ }
+
+ @Override
+ public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI) {
+ return true;
+ }
+
+ @Override
+ public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI,
+ SecTriple triple) {
+ return evaluate( principal, triple );
+ }
+
+ @Override
+ public boolean evaluateUpdate(Object principal, SecNode graphIRI, SecTriple from, SecTriple to) {
+ return evaluate( principal, from ) && evaluate( principal, to );
+ }
+
+ public void setPrincipal( String userName )
+ {
+ if (userName == null)
+ {
+ principal = null;
+ }
+ principal = new BasicUserPrincipal( userName );
+ }
+ @Override
+ public Principal getPrincipal() {
+ return principal;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/example/java/org/apache/jena/security/example/SecurityExample.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/example/java/org/apache/jena/security/example/SecurityExample.java b/jena-permissions/src/example/java/org/apache/jena/security/example/SecurityExample.java
new file mode 100644
index 0000000..0b7e0d9
--- /dev/null
+++ b/jena-permissions/src/example/java/org/apache/jena/security/example/SecurityExample.java
@@ -0,0 +1,93 @@
+/**
+ * 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.example;
+
+import java.net.URL;
+
+import org.apache.jena.security.Factory;
+
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.ModelFactory;
+import org.apache.jena.rdf.model.Property;
+import org.apache.jena.rdf.model.RDFNode;
+import org.apache.jena.rdf.model.ResIterator;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.rdf.model.ResourceFactory;
+import org.apache.jena.rdf.model.Statement;
+import org.apache.jena.vocabulary.RDF;
+
+public class SecurityExample {
+
+ /**
+ * @param args
+ */
+
+ public static void main(String[] args) {
+ String[] names = { "alice", "bob", "chuck", "darla" };
+
+ RDFNode msgType = ResourceFactory
+ .createResource("http://example.com/msg");
+ Property pTo = ResourceFactory.createProperty("http://example.com/to");
+ Property pFrom = ResourceFactory
+ .createProperty("http://example.com/from");
+ Property pSubj = ResourceFactory
+ .createProperty("http://example.com/subj");
+
+ Model model = ModelFactory.createDefaultModel();
+ URL url = SecurityExample.class.getClassLoader().getResource(
+ "org/apache/jena/security/example/example.ttl");
+ model.read(url.toExternalForm());
+ ResIterator ri = model.listSubjectsWithProperty(RDF.type, msgType);
+ System.out.println("All the messages");
+ while (ri.hasNext()) {
+ Resource msg = ri.next();
+ Statement to = msg.getProperty(pTo);
+ Statement from = msg.getProperty(pFrom);
+ Statement subj = msg.getProperty(pSubj);
+ System.out.println(String.format("%s to: %s from: %s subj: %s",
+ msg, to.getObject(), from.getObject(), subj.getObject()));
+ }
+ System.out.println();
+
+ ExampleEvaluator evaluator = new ExampleEvaluator(model);
+ model = Factory.getInstance(evaluator,
+ "http://example.com/SecuredModel", model);
+ for (String userName : names) {
+ evaluator.setPrincipal(userName);
+
+ System.out.println("Messages " + userName + " can manipulate");
+ ri = model.listSubjectsWithProperty(RDF.type, msgType);
+ while (ri.hasNext()) {
+ Resource msg = ri.next();
+ Statement to = msg.getProperty(pTo);
+ Statement from = msg.getProperty(pFrom);
+ Statement subj = msg.getProperty(pSubj);
+ System.out.println(String.format(
+ "%s to: %s from: %s subj: %s", msg, to.getObject(),
+ from.getObject(), subj.getObject()));
+ }
+ ri.close();
+ for (String name : names)
+ {
+ System.out.println( String.format( "%s messages to %s", model.listSubjectsWithProperty( pTo, name ).toList().size(), name ) );
+ }
+ System.out.println();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/example/java/org/apache/jena/security/example/ShiroExampleEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/example/java/org/apache/jena/security/example/ShiroExampleEvaluator.java b/jena-permissions/src/example/java/org/apache/jena/security/example/ShiroExampleEvaluator.java
new file mode 100644
index 0000000..a1eedef
--- /dev/null
+++ b/jena-permissions/src/example/java/org/apache/jena/security/example/ShiroExampleEvaluator.java
@@ -0,0 +1,235 @@
+/**
+ * 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.example;
+
+import java.util.Set;
+
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.subject.Subject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.rdf.model.AnonId;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.Property;
+import org.apache.jena.rdf.model.RDFNode;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.rdf.model.ResourceFactory;
+import org.apache.jena.vocabulary.RDF;
+
+/**
+ * Class to use Shiro to provide credentials.
+ *
+ * An example evaluator that only provides access to messages in the graph that
+ * are from or to the principal.
+ *
+ */
+public class ShiroExampleEvaluator implements SecurityEvaluator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ShiroExampleEvaluator.class);
+ // the model that contains the messages.
+ private Model model;
+ private RDFNode msgType = ResourceFactory.createResource( "http://example.com/msg" );
+ private Property pTo = ResourceFactory.createProperty( "http://example.com/to" );
+ private Property pFrom = ResourceFactory.createProperty( "http://example.com/from" );
+
+ /**
+ *
+ * @param model The graph we are going to evaluate against.
+ */
+ public ShiroExampleEvaluator( Model model )
+ {
+ this.model = model;
+ }
+
+ /**
+ * We allow any action on the graph itself, so this is always true.
+ */
+ @Override
+ public boolean evaluate(Object principal, Action action, SecNode graphIRI) {
+ // we allow any action on a graph.
+ return true;
+ }
+
+ /**
+ * This is our internal check to see if the user may access the resource.
+ * This method is called from the evauate(Object,SecNode) method.
+ * A user may only access the resource if they are authenticated, and are either the
+ * sender or the recipient.
+ * Additionally the admin can always see the messages.
+ * @param principalObj
+ * @param r
+ * @return
+ */
+ private boolean evaluate( Object principalObj, Resource r )
+ {
+ // cast to the Subject because we know that it comes from Shiro and that
+ // our getPrincipal() method returns a Subject.
+ Subject subject = (Subject)principalObj;
+ if (! subject.isAuthenticated())
+ {
+ LOG.info( "User not authenticated");
+ return false;
+ }
+ // a message is only available to sender or recipient
+ LOG.debug( "checking {}", subject.getPrincipal());
+ Object principal = subject.getPrincipal();
+
+ // We put the admin check here but it could have been done much earlier.
+ if ("admin".equals(principal.toString()))
+ {
+ return true;
+ }
+ // if we are looking at a message object then check the restrictions.
+ if (r.hasProperty( RDF.type, msgType ))
+ {
+ return r.hasProperty( pTo, subject.getPrincipal().toString() ) ||
+ r.hasProperty( pFrom, subject.getPrincipal().toString());
+ }
+ // otherwise user can see the object.
+ return true;
+ }
+
+ /**
+ * Check that the user can see a specific node.
+ * @param principal
+ * @param node
+ * @return
+ */
+ private boolean evaluate( Object principal, SecNode node )
+ {
+ // Access to wild card is false -- this forces checks to the acutal nodes
+ // to be returned.
+ // we could have checked for admin access here and returned true since the admin
+ // can see any node.
+ if (node.equals( SecNode.ANY )) {
+ return false;
+ }
+
+ // URI nodes are retrieved from the model and evaluated
+ if (node.getType().equals( SecNode.Type.URI)) {
+ Resource r = model.createResource( node.getValue() );
+ return evaluate( principal, r );
+ }
+ // anonymous nodes have to be retrieved from the model as anonymous nodes.
+ else if (node.getType().equals( SecNode.Type.Anonymous)) {
+ Resource r = model.getRDFNode( NodeFactory.createAnon( new AnonId( node.getValue()) ) ).asResource();
+ return evaluate( principal, r );
+ }
+ // anything else (literals) can be seen.
+ else
+ {
+ return true;
+ }
+
+ }
+
+ /**
+ * Evaluate if the user can see the triple.
+ * @param principal
+ * @param triple
+ * @return
+ */
+ private boolean evaluate( Object principal, SecTriple triple ) {
+ // we could have checked here to see if the principal was the admin and
+ // just returned true since the admin can perform any operation on any triple.
+ return evaluate( principal, triple.getSubject()) &&
+ evaluate( principal, triple.getObject()) &&
+ evaluate( principal, triple.getPredicate());
+ }
+
+ /**
+ * As per our design, users can do anything with triples they have access to, so we just
+ * ignore the action parameter. If we were to implement rules restricted access based
+ * upon action this method would sort those out appropriately.
+ */
+ @Override
+ public boolean evaluate(Object principal, Action action, SecNode graphIRI, SecTriple triple) {
+ // we could have checked here to see if the principal was the admin and
+ // just returned true since the admin can perform any operation on any triple.
+ return evaluate( principal, triple );
+ }
+
+ /**
+ * As per our design, users can access any graph. If we were to implement rules that
+ * restricted user access to specific graphs, those checks would be here and we would
+ * return <code>false</code> if they were not allowed to access the graph. Note that this
+ * method is checking to see that the user may perform ALL the actions in the set on the
+ * graph.
+ */
+ @Override
+ public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI) {
+ return true;
+ }
+
+ /**
+ * As per our design, users can access any triple from a message that is from or to them.
+ * Since we don't have restrictions on actions this is no different then checking access
+ * for a single action.
+ */
+ @Override
+ public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI,
+ SecTriple triple) {
+ return evaluate( principal, triple );
+ }
+
+ /**
+ * As per our design, users can access any graph. If we were to implement rules that
+ * restricted user access to specific graphs, those checks would be here and we would
+ * return <code>false</code> if they were not allowed to access the graph. Note that this
+ * method is checking to see that the user may perform ANY of the actions in the set on the
+ * graph.
+ */
+ @Override
+ public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI) {
+ return true;
+ }
+
+ /**
+ * As per our design, users can access any triple from a message that is from or to them.
+ * Since we don't have restrictions on actions this is no different then checking access
+ * for a single action.
+ */
+ @Override
+ public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI,
+ SecTriple triple) {
+ return evaluate( principal, triple );
+ }
+
+ /**
+ * As per our design, users can access any triple from a message that is from or to them.
+ * So for an update they can only change triples they have access to into other triples
+ * they have access to. (e.g. they can not remvoe themself from the messsage).
+ */
+ @Override
+ public boolean evaluateUpdate(Object principal, SecNode graphIRI, SecTriple from, SecTriple to) {
+ return evaluate( principal, from ) && evaluate( principal, to );
+ }
+
+ /**
+ * Return the Shiro subject. This is the subject that Shiro currently has logged in.
+ */
+ @Override
+ public Object getPrincipal() {
+ return SecurityUtils.getSubject();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/example/resources/org/apache/jena/security/example/example.ttl
----------------------------------------------------------------------
diff --git a/jena-permissions/src/example/resources/org/apache/jena/security/example/example.ttl b/jena-permissions/src/example/resources/org/apache/jena/security/example/example.ttl
new file mode 100644
index 0000000..7047629
--- /dev/null
+++ b/jena-permissions/src/example/resources/org/apache/jena/security/example/example.ttl
@@ -0,0 +1,49 @@
+# 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.
+
+@prefix ex: <http://example.com/> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+
+ex:msg1 rdf:type ex:msg;
+ ex:to "bob";
+ ex:from "alice" ;
+ ex:subj "alice to bob 1";
+ .
+
+ex:msg2 rdf:type ex:msg;
+ ex:to "alice";
+ ex:from "bob";
+ ex:subj "bob to alice 1";
+ .
+
+ex:msg3 rdf:type ex:msg;
+ ex:to "chuck" ;
+ ex:from "alice";
+ ex:subj "alice to chuck 1";
+ .
+
+ex:msg4 rdf:type ex:msg;
+ ex:to "darla" ;
+ ex:from "bob" ;
+ ex:subj "bob to darla 1"
+ .
+
+ex:msg5 rdf:type ex:msg;
+ ex:to "alice";
+ ex:from "bob";
+ ex:subj "bob to alice 2";
+ .
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/example/resources/org/apache/jena/security/example/fuseki/config.ttl
----------------------------------------------------------------------
diff --git a/jena-permissions/src/example/resources/org/apache/jena/security/example/fuseki/config.ttl b/jena-permissions/src/example/resources/org/apache/jena/security/example/fuseki/config.ttl
new file mode 100644
index 0000000..a748f01
--- /dev/null
+++ b/jena-permissions/src/example/resources/org/apache/jena/security/example/fuseki/config.ttl
@@ -0,0 +1,98 @@
+# 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.
+
+##
+## Define all the prefixes
+##
+
+@prefix fuseki: <http://jena.apache.org/fuseki#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
+@prefix sec: <http://apache.org/jena/security/Assembler#> .
+@prefix my: <http://example.org/#> .
+
+##
+## Load the SecuredAssembler class from the security library and define
+## the sec:Model as a subclass of ja:NamedModel.
+##
+[] ja:loadClass "org.apache.jena.security.SecuredAssembler" .
+sec:Model rdfs:subClassOf ja:NamedModel .
+
+##
+## Define the base model that contains the unsecured data.
+##
+my:baseModel rdf:type ja:MemoryModel;
+ ja:content [ja:externalContent <file:./example.ttl>]
+ .
+
+##
+## Define the secured model. This is where permissions is applied to the
+## my:baseModel to create a model that has permission restrictions. Note
+## that it is using the security evaluator implementation (sec:evaluatorImpl)
+## called my:secEvaluator which we will define next.
+##
+my:securedModel rdf:type sec:Model ;
+ sec:baseModel my:baseModel ;
+ ja:modelName "https://example.org/securedModel" ;
+ sec:evaluatorImpl my:secEvaluator .
+
+##
+## Define the security evaluator. This is where we use the example
+## ShiroExampleEvaluator. For your production environment you will replace
+## "org.apache.jena.security.example.ShiroExampleEvaluator" with your
+## SecurityEvaluator implementation. Note that ShiroExampleEvaluator constructor
+## takes a Model argument. We pass in the unsecured baseModel so that the evaluator
+## can read it unencumbered. Your implementation of SecurityEvaluator may have different
+## parameters to meet your specific needs.
+##
+my:secEvaluator rdf:type sec:Evaluator ;
+ sec:args [
+ rdf:_1 my:baseModel ;
+ ] ;
+ sec:evaluatorClass "org.apache.jena.security.example.ShiroExampleEvaluator" .
+
+##
+## Define the dataset that we will use for in the server.
+##
+my:securedDataset rdf:type ja:RDFDataset ;
+ ja:defaultGraph my:securedModel .
+
+##
+## Define the fuseki:Server.
+##
+my:fuskei rdf:type fuseki:Server ;
+ fuseki:services (
+ my:service1
+ ) .
+
+##
+## Define the service for the fuseki:Service. Note that the fuseki:dataset served by
+## this server is the secured dataset defined above.
+##
+my:service1 rdf:type fuseki:Service ;
+ rdfs:label "My Secured Data Service" ;
+ fuseki:name "myAppFuseki" ; # http://host:port/myAppFuseki
+ fuseki:serviceQuery "query" ; # SPARQL query service
+ fuseki:serviceQuery "sparql" ; # SPARQL query service
+ fuseki:serviceUpdate "update" ; # SPARQL query service
+ fuseki:serviceUpload "upload" ; # Non-SPARQL upload service
+ fuseki:serviceReadWriteGraphStore "data" ; # SPARQL Graph store protocol (read and write)
+ # A separate ead-only graph store endpoint:
+ fuseki:serviceReadGraphStore "get" ; # SPARQL Graph store protocol (read only)
+ fuseki:dataset my:securedDataset ;
+ .
+
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/example/resources/org/apache/jena/security/example/fuseki/shiro.ini
----------------------------------------------------------------------
diff --git a/jena-permissions/src/example/resources/org/apache/jena/security/example/fuseki/shiro.ini b/jena-permissions/src/example/resources/org/apache/jena/security/example/fuseki/shiro.ini
new file mode 100644
index 0000000..a9fbf71
--- /dev/null
+++ b/jena-permissions/src/example/resources/org/apache/jena/security/example/fuseki/shiro.ini
@@ -0,0 +1,47 @@
+# 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.
+
+[main]
+# Development
+ssl.enabled = false
+
+plainMatcher=org.apache.shiro.authc.credential.SimpleCredentialsMatcher
+#iniRealm=org.apache.shiro.realm.text.IniRealm
+iniRealm.credentialsMatcher = $plainMatcher
+
+localhost=org.apache.jena.fuseki.authz.LocalhostFilter
+
+[users]
+# Implicitly adds "iniRealm = org.apache.shiro.realm.text.IniRealm"
+admin=admin
+alice=alice
+bob=bob
+chuck=chuck
+darla=darla
+
+[roles]
+
+[urls]
+## Control functions open to anyone
+/$/status = anon
+/$/ping = anon
+
+## restrict access. Must log in with above.
+/$/** = authcBasic,user
+
+
+# Everything else
+/**=anon
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/AccessDeniedException.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/AccessDeniedException.java b/jena-permissions/src/main/java/org/apache/jena/security/AccessDeniedException.java
new file mode 100644
index 0000000..3c0654d
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/AccessDeniedException.java
@@ -0,0 +1,66 @@
+/*
+ * 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.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+
+/**
+ * Exception thrown by the security system when an action is not allowed.
+ *
+ * Contains the graphIRI and the action that was not allowed.
+ */
+public class AccessDeniedException extends RuntimeException
+{
+ private static final long serialVersionUID = 2789332975364811725L;
+
+ private String triple;
+
+ /**
+ * Constructor.
+ * @param uri The SecNode that identifies graph with the security.
+ * @param action The action that was prohibited.
+ */
+ public AccessDeniedException( final SecNode uri, final Action action )
+ {
+ super(String.format("securedModel sec. %s: %s", uri, action));
+ }
+
+ /**
+ * Constructor.
+ * @param uri The SecNode that identifies graph with the security.
+ * @param triple The triple The triple on which the action was prohibited.
+ * @param action The action that was prohibited.
+ */
+ public AccessDeniedException( final SecNode uri, final String triple,
+ final Action action )
+ {
+ super(String.format("triple sec. %s: %s", uri, action));
+ this.triple = triple;
+ }
+
+ /**
+ * @return The triple on which the action was prohibited. May be null.
+ */
+ public String getTriple()
+ {
+ return triple;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/AssemblerConstants.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/AssemblerConstants.java b/jena-permissions/src/main/java/org/apache/jena/security/AssemblerConstants.java
new file mode 100644
index 0000000..700883e
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/AssemblerConstants.java
@@ -0,0 +1,62 @@
+/*
+ * 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.apache.jena.rdf.model.Property ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+
+public interface AssemblerConstants {
+ public static final String URI = "http://apache.org/jena/security/Assembler#";
+ /**
+ * Property named URI+"evaluatorFactory"
+ */
+ public static final Property EVALUATOR_FACTORY =
+ ResourceFactory.createProperty( URI + "evaluatorFactory" );
+ /**
+ * Property named URI+"Model"
+ */
+ public static final Property SECURED_MODEL = ResourceFactory.createProperty( URI + "Model" );
+ /**
+ * Property named URI+"baseModel"
+ */
+ public static final Property BASE_MODEL = ResourceFactory.createProperty( URI + "baseModel" );
+ /**
+ * Property named URI+"Evaluator"
+ */
+ public static final Property EVALUATOR_ASSEMBLER = ResourceFactory.createProperty( URI+"Evaluator" );
+ /**
+ * Property named URI+"evaluatorImpl"
+ */
+ public static final Property EVALUATOR_IMPL =
+ ResourceFactory.createProperty( URI + "evaluatorImpl" );
+
+ /**
+ * Property named URI+"evaluatorClass"
+ */
+ public static final Property EVALUATOR_CLASS =
+ ResourceFactory.createProperty( URI + "evaluatorClass" );
+ /**
+ * Property named URI+"evaluatorImpl"
+ */
+ public static final Property ARGUMENT_LIST =
+ ResourceFactory.createProperty( URI + "args" );
+
+ // message formats
+ public static final String NO_X_PROVIDED = "No %s provided for %s";
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/Factory.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/Factory.java b/jena-permissions/src/main/java/org/apache/jena/security/Factory.java
new file mode 100644
index 0000000..1ae3579
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/Factory.java
@@ -0,0 +1,69 @@
+/*
+ * 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.apache.jena.graph.Graph ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.security.graph.SecuredGraph;
+import org.apache.jena.security.model.SecuredModel;
+
+/**
+ * The factory that can be used to create an instance of a SecuredGraph or a SecuredModel.
+ */
+public class Factory
+{
+
+ /**
+ * 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 graph secured under the name graphIRI
+ */
+ public static SecuredGraph getInstance(
+ final SecurityEvaluator securityEvaluator, final String graphIRI,
+ final Graph graph )
+ {
+
+ return org.apache.jena.security.graph.impl.Factory.getInstance(
+ securityEvaluator, graphIRI, graph);
+ }
+
+ /**
+ * Get an instance of SecuredModel
+ *
+ * @param securityEvaluator
+ * The security evaluator to use
+ * @param modelIRI
+ * The securedModel IRI (graph IRI) to evaluate against.
+ * @param model
+ * The model to secure.
+ * @return the model secured under the name modelIRI
+ */
+ public static SecuredModel getInstance(
+ final SecurityEvaluator securityEvaluator, final String modelIRI,
+ final Model model )
+ {
+ return org.apache.jena.security.model.impl.SecuredModelImpl.getInstance(
+ securityEvaluator, modelIRI, model);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/SecuredAssembler.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/SecuredAssembler.java b/jena-permissions/src/main/java/org/apache/jena/security/SecuredAssembler.java
new file mode 100644
index 0000000..02b255d
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/SecuredAssembler.java
@@ -0,0 +1,264 @@
+/*
+ * 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.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.apache.jena.assembler.Assembler ;
+import org.apache.jena.assembler.JA ;
+import org.apache.jena.assembler.Mode ;
+import org.apache.jena.assembler.assemblers.AssemblerGroup ;
+import org.apache.jena.assembler.assemblers.ModelAssembler ;
+import org.apache.jena.assembler.exceptions.AssemblerException ;
+import org.apache.jena.rdf.model.Literal ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.sparql.util.MappingRegistry ;
+
+/**
+ * Assembler for a secured model.
+ *
+ * <p>
+ * The assembler file should include the following
+ * <code><pre>
+ * <>; ja:loadClass "org.apache.jena.security.SecuredAssembler" .
+ *
+ * sec:Model rdfs:subClassOf ja:NamedModel .
+ *
+ * sec:evaluator rdfs:domain sec:Model ;
+ * rdfs:range sec:Evaluator .
+ * </pre></code>
+ *
+ * The model definition should include something like.
+ *
+ * <code><pre>
+ * my:secModel a sec:Model ;
+ * sec:baseModel my:baseModel ;
+ * ja:modelName "http://example.com/securedModel" ;
+ * sec:evaluatorFactory "org.apache.jena.security.MockSecurityEvaluator" ;
+ * .
+ * </pre></code>
+ *
+ * Terms used in above example:
+ *
+ * <dl>
+ * <dt>my:secModel</dt>
+ * <dd>The secured model as referenced in the assembler file.</dd>
+ *
+ * <dt>sec:Model</dt>
+ * <dd>Identifes my:secModel as a secured model</dd>
+ *
+ * <dt>sec:baseModel</dt>
+ * <dd>Identifies my:baseModel as the base model we are applying security to</dd>
+ *
+ * <dt>my:baseModel</dt>
+ * <dd>a ja:Model (or subclass) defined elsewhere in the assembler file</dd>
+ *
+ * <dt>ja:modelName</dt>
+ * <dd>The name of the graph as it will be addressed in the security environment
+ * (see ja:NamedModel examples from Jena)</dd>
+ *
+ * <dt>sec:evaluatorFactory</dt>
+ * <dd>Identifies "org.apache.jena.security.MockSecurityEvaluator" as the java class
+ * that implements an Evaluator Factory. The Factory must have
+ * static method <code>getInstance()</code> that returns a SecurityEvaluator.</dd>
+ * </dl>
+ *
+ * or if using an evaluator assembler
+ *
+ * <code><pre>
+ * my:secModel a sec:Model ;
+ * sec:baseModel my:baseModel ;
+ * ja:modelName "http://example.com/securedModel" ;
+ * sec:evaluatorImpl ex:myEvaluator;
+ * .
+ *
+ * ex:myEvaluator a sec:Evaluator ;
+ * ex:arg1 "argument 1 for my evaluator constructor" ;
+ * ex:arg2 "argument 2 for my evaluator constructor" ;
+ * .
+ *
+ * </pre></code>
+ *
+ * Terms used in above example:
+ *
+ * <dl>
+ * <dt>my:secModel</dt>
+ * <dd>The secured model as referenced in the assembler file.</dd>
+ *
+ * <dt>sec:Model</dt>
+ * <dd>Identifes my:secModel as a secured model</dd>
+ *
+ * <dt>sec:baseModel</dt>
+ * <dd>Identifies my:baseModel as the base model we are applying security to</dd>
+ *
+ * <dt>my:baseModel</dt>
+ * <dd>a ja:Model (or subclass) defined elsewhere in the assembler file</dd>
+ *
+ * <dt>ja:modelName</dt>
+ * <dd>The name of the graph as it will be addressed in the security environment
+ * (see ja:NamedModel examples from Jena)</dd>
+ *
+ * <dt>sec:evaluatorImpl</dt>
+ * <dd>Identifies ex:myEvaluator as a SecurityEvaluator defined elsewhere in the assembler file.
+ * It must subclass as a sec:Evaluator.</dd>
+ * </dd>
+ *
+ * <dt>ex:arg1 and ex:arg2</dt>
+ * <dd>Arguments as defined by the user defined security evaluator assembler.</dd>
+ * </dl>
+
+ * </p>
+ *
+ */
+public class SecuredAssembler extends ModelAssembler implements AssemblerConstants {
+ private static boolean initialized;
+
+ // message formats
+ private static final String ERROR_FINDING_FACTORY = "Error finding factory class %s: %s";
+
+ static { init() ; }
+
+ /**
+ * Initialize the assembler.
+ * Registers the prefix "sec" with the uri http://apache.org/jena/security/Assembler#
+ * and registers this assembler with the uri http://apache.org/jena/security/Assembler#Model
+ */
+ static synchronized public void init()
+ {
+ if ( initialized )
+ return ;
+ MappingRegistry.addPrefixMapping("sec", URI) ;
+ registerWith(Assembler.general) ;
+ initialized = true ;
+ }
+
+ /**
+ * Register this assembler in the assembler group.
+ * @param group The assembler group to register with.
+ */
+ static void registerWith(AssemblerGroup group)
+ {
+ if ( group == null )
+ group = Assembler.general ;
+ group.implementWith( SECURED_MODEL, new SecuredAssembler()) ;
+ group.implementWith( EVALUATOR_ASSEMBLER, new SecurityEvaluatorAssembler());
+ }
+
+ @Override
+ public Model open(Assembler a, Resource root, Mode mode) {
+
+ Resource rootModel = getUniqueResource( root, BASE_MODEL );
+ if (rootModel == null)
+ {
+ throw new AssemblerException( root, String.format( NO_X_PROVIDED, BASE_MODEL, root ));
+ }
+ Model baseModel = a.openModel(rootModel, Mode.ANY);
+
+ Literal modelName = getUniqueLiteral( root, JA.modelName );
+ if (modelName == null)
+ {
+ throw new AssemblerException( root, String.format( NO_X_PROVIDED, JA.modelName, root ));
+ }
+
+ Literal factoryName = getUniqueLiteral( root, EVALUATOR_FACTORY );
+ Resource evaluatorImpl = getUniqueResource( root, EVALUATOR_IMPL );
+ if (factoryName == null && evaluatorImpl == null)
+ {
+ throw new AssemblerException( root,
+ String.format( "Either a %s or a %s must be provided for %s" ,
+ EVALUATOR_FACTORY, EVALUATOR_IMPL, root ));
+ }
+ if (factoryName != null && evaluatorImpl != null)
+ {
+ throw new AssemblerException( root,
+ String.format( "May not specify both a %s and a %s for %s" ,
+ EVALUATOR_FACTORY, EVALUATOR_IMPL, root ));
+ }
+ SecurityEvaluator securityEvaluator = null;
+ if (factoryName != null)
+ {
+ securityEvaluator = executeEvaluatorFactory( root, factoryName );
+ }
+ if (evaluatorImpl != null)
+ {
+ securityEvaluator = getEvaluatorImpl( a, evaluatorImpl );
+ }
+ return Factory.getInstance(securityEvaluator, modelName.asLiteral().getString(), baseModel);
+
+ }
+
+ @Override
+ protected Model openEmptyModel(Assembler a, Resource root, Mode mode) {
+ return open(a, root, mode);
+ }
+
+ private SecurityEvaluator executeEvaluatorFactory(Resource root, Literal factoryName ) {
+ try
+ {
+ Class<?> factoryClass = Class.forName( factoryName.getString() );
+ Method method = factoryClass.getMethod("getInstance" );
+ if ( ! SecurityEvaluator.class.isAssignableFrom(method.getReturnType()))
+ {
+ throw new AssemblerException( root, String.format( "%s (found at %s for %s) getInstance() must return an instance of SecurityEvaluator", factoryName, EVALUATOR_FACTORY, root ));
+ }
+ if ( ! Modifier.isStatic( method.getModifiers()))
+ {
+ throw new AssemblerException( root, String.format( "%s (found at %s for %s) getInstance() must be a static method", factoryName, EVALUATOR_FACTORY, root ));
+ }
+ return (SecurityEvaluator) method.invoke( null );
+ }
+ catch (SecurityException e)
+ {
+ throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new AssemblerException( root, String.format( "Class %s (found at %s for %s) could not be loaded", factoryName, EVALUATOR_FACTORY, root ));
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new AssemblerException( root, String.format( "%s (found at %s for %s) must implement a static getInstance() that returns an instance of SecurityEvaluator", factoryName, EVALUATOR_FACTORY, root ));
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e);
+ }
+ }
+
+ private SecurityEvaluator getEvaluatorImpl(Assembler a, Resource evaluatorImpl ) {
+ Object obj = a.open(a, evaluatorImpl, Mode.ANY);
+ if (obj instanceof SecurityEvaluator)
+ {
+ return (SecurityEvaluator) obj;
+ }
+ throw new AssemblerException( evaluatorImpl, String.format(
+ "%s does not specify a SecurityEvaluator instance", evaluatorImpl));
+ }
+
+}
[16/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/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
new file mode 100644
index 0000000..0efc9be
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/ModelBasedSecurityEvaluator.java
@@ -0,0 +1,76 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..697c5f6
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/SecuredAssemblerTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..d6de485
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/SecurityEvaluatorParameters.java
@@ -0,0 +1,135 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..d59b89c
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/StaticSecurityEvaluator.java
@@ -0,0 +1,78 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..6201b5c
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/CachedSecurityEvaluatorTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..e903d75
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphContractTests.java
@@ -0,0 +1,51 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..fb7f805
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredGraphListenerTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..6991ea8
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/contract/graph/SecuredTDBGraphContractTests.java
@@ -0,0 +1,51 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..e3d33e5
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/ModelTestSuite.java
@@ -0,0 +1,132 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..6247c68
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestLiterals.java
@@ -0,0 +1,29 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..4f0650d
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestPackage.java
@@ -0,0 +1,120 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..4a1d662
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaderEvents.java
@@ -0,0 +1,28 @@
+/*
+ * 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/b712fb28/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
new file mode 100644
index 0000000..7ee29fe
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/contract/model/SecTestReaders.java
@@ -0,0 +1,28 @@
+/*
+ * 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" );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java
new file mode 100644
index 0000000..46f8b0b
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java
@@ -0,0 +1,372 @@
+/*
+ * 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.graph;
+
+import java.util.Arrays;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.CollectionGraph ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.Factory;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.graph.SecuredBulkUpdateHandler;
+import org.apache.jena.security.graph.SecuredGraph;
+import org.apache.jena.sparql.graph.GraphFactory ;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class BulkUpdateHandlerTest
+{
+ protected SecuredBulkUpdateHandler handler;
+ private final SecurityEvaluator securityEvaluator;
+ private final Triple[] tripleArray;
+ private final Set<Action> deleteAndUpdate;
+ private final Set<Action> createAndUpdate;
+
+ public BulkUpdateHandlerTest( final SecurityEvaluator securityEvaluator )
+ {
+ this.securityEvaluator = securityEvaluator;
+
+ tripleArray = new Triple[] {
+ new Triple(NodeFactory.createURI("http://example.com/1"),
+ NodeFactory.createURI("http://example.com/v"),
+ NodeFactory.createAnon()),
+ new Triple(NodeFactory.createURI("http://example.com/2"),
+ NodeFactory.createURI("http://example.com/v"),
+ NodeFactory.createAnon()),
+ new Triple(NodeFactory.createURI("http://example.com/3"),
+ NodeFactory.createURI("http://example.com/v"),
+ NodeFactory.createAnon()) };
+ createAndUpdate = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Update });
+ deleteAndUpdate = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Delete, Action.Update });
+ }
+
+ @Before
+ public void setup()
+ {
+ final Graph g = GraphFactory.createDefaultGraph();
+
+ final SecuredGraph sg = Factory.getInstance(securityEvaluator,
+ "http://example.com/testGraph", g);
+ handler = sg.getBulkUpdateHandler();
+ }
+
+ @Test
+ public void testAdd()
+ {
+ Object principal = securityEvaluator.getPrincipal();
+ try
+ {
+ handler.add(tripleArray);
+ if (!securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ handler.add(Arrays.asList(tripleArray));
+ if (!securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ handler.add(Arrays.asList(tripleArray).iterator());
+ if (!securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ handler.add(new CollectionGraph(Arrays.asList(tripleArray)));
+ if (!securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ handler.add(new CollectionGraph(Arrays.asList(tripleArray)));
+ if (!securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ handler.add(new CollectionGraph(Arrays.asList(tripleArray)), true);
+ if (!securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, createAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testDelete()
+ {
+ Object principal = securityEvaluator.getPrincipal();
+ try
+ {
+ handler.delete(tripleArray);
+ if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ handler.delete(Arrays.asList(tripleArray));
+ if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ handler.delete(Arrays.asList(tripleArray).iterator());
+ if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ handler.delete(new CollectionGraph(Arrays.asList(tripleArray)));
+ if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ handler.delete(new CollectionGraph(Arrays.asList(tripleArray)),
+ true);
+ if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ public void testRemove()
+ {
+ Object principal = securityEvaluator.getPrincipal();
+ try
+ {
+ handler.remove(NodeFactory.createURI("http://example.com/1"),
+ NodeFactory.createURI("http://example.com/v"), NodeFactory.createAnon());
+ if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ public void testRemoveAll()
+ {
+ Object principal = securityEvaluator.getPrincipal();
+ try
+ {
+ handler.removeAll();
+ if (!securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, deleteAndUpdate,
+ handler.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java
new file mode 100644
index 0000000..b8da8e4
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.graph;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.GraphEventManager ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.security.Factory;
+import org.apache.jena.security.StaticSecurityEvaluator;
+import org.apache.jena.sparql.graph.GraphFactory ;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CrossIDGraphEventManagerTest {
+
+ private final GraphEventManager manager;
+ private final Graph g;
+ private final SecuredGraph sg;
+ private final StaticSecurityEvaluator securityEvaluator;
+
+ private final RecordingGraphListener annListener;
+ private final RecordingGraphListener bobListener;
+
+ public CrossIDGraphEventManagerTest() {
+ this.securityEvaluator = new StaticSecurityEvaluator("ann");
+
+ g = GraphFactory.createDefaultGraph();
+ g.add(new Triple(NodeFactory.createURI("urn:ann"), NodeFactory
+ .createURI("http://example.com/v"), NodeFactory.createAnon()));
+ g.add(new Triple(NodeFactory.createURI("urn:bob"), NodeFactory
+ .createURI("http://example.com/v"), NodeFactory.createAnon()));
+ g.add(new Triple(NodeFactory.createURI("urn:ann"), NodeFactory
+ .createURI("http://example.com/v2"), NodeFactory.createAnon()));
+
+ sg = Factory.getInstance(securityEvaluator,
+ "http://example.com/testGraph", g);
+ manager = sg.getEventManager();
+ annListener = new RecordingGraphListener();
+ manager.register(annListener);
+ this.securityEvaluator.setUser("bob");
+ bobListener = new RecordingGraphListener();
+ manager.register(bobListener);
+ }
+
+ @Test
+ public void notificationsTest() {
+ sg.add(new Triple(NodeFactory.createURI("urn:bob"), NodeFactory
+ .createURI("http://example.com/v2"), NodeFactory.createAnon()));
+
+ Assert.assertTrue("Should recorded add", bobListener.isAdd());
+ Assert.assertFalse("Should not have recorded add", annListener.isAdd());
+
+ sg.delete(new Triple(NodeFactory.createURI("urn:bob"), NodeFactory
+ .createURI("http://example.com/v2"), NodeFactory.createAnon()));
+
+ Assert.assertTrue("Should recorded delete", bobListener.isDelete());
+ Assert.assertFalse("Should not have recorded delete",
+ annListener.isDelete());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java
new file mode 100644
index 0000000..10ffd42
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java
@@ -0,0 +1,239 @@
+/*
+ * 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.graph;
+
+import java.util.Arrays;
+import java.util.Set;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.GraphEventManager ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.graph.impl.CollectionGraph ;
+import org.apache.jena.security.Factory;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.graph.SecuredGraph;
+import org.apache.jena.sparql.graph.GraphFactory ;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Verifies that messages are properly filtered when sent to listeners.
+ *
+ */
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class GraphEventManagerTest
+{
+ private final GraphEventManager manager;
+ private final Graph g;
+ private final SecuredGraph sg;
+ private final SecurityEvaluator securityEvaluator;
+ private Triple[] tripleArray;
+
+ private final RecordingGraphListener listener;
+
+ public GraphEventManagerTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ this.securityEvaluator = securityEvaluator;
+ g = GraphFactory.createDefaultGraph();
+
+ sg = Factory.getInstance(securityEvaluator,
+ "http://example.com/testGraph", g);
+ manager = sg.getEventManager();
+ listener = new RecordingGraphListener();
+ manager.register(listener);
+
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ public void notifyAddTest()
+ {
+ Object principal = securityEvaluator.getPrincipal();
+ final Set<Action> ADD = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Create, Action.Read });
+ g.add(tripleArray[0]);
+ if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should recorded add", listener.isAdd());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded add", listener.isAdd());
+ }
+ g.delete(Triple.ANY);
+ listener.reset();
+
+ g.getBulkUpdateHandler().add(tripleArray);
+ if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should recorded add", listener.isAdd());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded add", listener.isAdd());
+ }
+ g.delete(Triple.ANY);
+ listener.reset();
+
+ g.getBulkUpdateHandler().add(Arrays.asList(tripleArray));
+ if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should recorded add", listener.isAdd());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded add", listener.isAdd());
+ }
+ g.delete(Triple.ANY);
+ listener.reset();
+
+ g.getBulkUpdateHandler().add(Arrays.asList(tripleArray).iterator());
+ if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should recorded add", listener.isAdd());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded add", listener.isAdd());
+ }
+ g.delete(Triple.ANY);
+ listener.reset();
+
+ g.getBulkUpdateHandler().add(
+ new CollectionGraph(Arrays.asList(tripleArray)));
+ if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should recorded add", listener.isAdd());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded add", listener.isAdd());
+ }
+ g.delete(Triple.ANY);
+ listener.reset();
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void notifyDeleteTest()
+ {
+ Object principal = securityEvaluator.getPrincipal();
+ final Set<Action> DELETE = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Delete, Action.Read });
+ g.delete(tripleArray[0]);
+ if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should have recorded delete",
+ listener.isDelete());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded delete",
+ listener.isDelete());
+ }
+
+ listener.reset();
+
+ g.getBulkUpdateHandler().delete(tripleArray);
+ if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should recorded delete", listener.isDelete());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded delete",
+ listener.isDelete());
+ }
+ listener.reset();
+
+ g.getBulkUpdateHandler().delete(Arrays.asList(tripleArray));
+ if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should recorded delete", listener.isDelete());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded delete",
+ listener.isDelete());
+ }
+ listener.reset();
+
+ g.getBulkUpdateHandler().delete(Arrays.asList(tripleArray).iterator());
+ if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should recorded delete", listener.isDelete());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded delete",
+ listener.isDelete());
+ }
+ listener.reset();
+
+ g.getBulkUpdateHandler().delete(
+ new CollectionGraph(Arrays.asList(tripleArray)));
+ if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode()))
+ {
+ Assert.assertTrue("Should recorded delete", listener.isDelete());
+ }
+ else
+ {
+ Assert.assertFalse("Should not have recorded delete",
+ listener.isDelete());
+ }
+ listener.reset();
+ }
+
+ @Test
+ public void notifyEventTest()
+ {
+ g.getEventManager().notifyEvent(g, "Foo");
+ Assert.assertTrue("Should recorded delete", listener.isEvent());
+ listener.reset();
+ // final RecordingGraphListener listener2 = new
+ // RecordingGraphListener();
+ // g.getEventManager().register(listener2);
+ sg.getEventManager().notifyEvent(sg, "Foo");
+ Assert.assertTrue("Should recorded delete", listener.isEvent());
+ // Assert.assertTrue("Should recorded delete", listener2.isEvent());
+ listener.reset();
+
+ }
+
+ @Before
+ public void setup()
+ {
+ tripleArray = new Triple[] {
+ new Triple(NodeFactory.createURI("http://example.com/1"),
+ NodeFactory.createURI("http://example.com/v"),
+ NodeFactory.createAnon()),
+ new Triple(NodeFactory.createURI("http://example.com/2"),
+ NodeFactory.createURI("http://example.com/v"),
+ NodeFactory.createAnon()),
+ new Triple(NodeFactory.createURI("http://example.com/3"),
+ NodeFactory.createURI("http://example.com/v"),
+ NodeFactory.createAnon()) };
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/graph/MemGraphTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/MemGraphTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/MemGraphTest.java
new file mode 100644
index 0000000..3f4685a
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/graph/MemGraphTest.java
@@ -0,0 +1,387 @@
+/*
+ * 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.graph;
+
+import java.lang.reflect.Method;
+import java.util.Set;
+
+import org.apache.jena.graph.* ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.EqualityTester;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.graph.SecuredBulkUpdateHandler;
+import org.apache.jena.security.graph.SecuredGraph;
+import org.apache.jena.sparql.graph.GraphFactory ;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class MemGraphTest
+{
+ private SecuredGraph securedGraph;
+ private final MockSecurityEvaluator securityEvaluator;
+ private Node s;
+ private Node p;
+ private Node o;
+ private Triple t;
+
+ private Graph baseGraph;
+
+ public MemGraphTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ this.securityEvaluator = securityEvaluator;
+ }
+
+ protected Graph createGraph() throws Exception
+ {
+ return GraphFactory.createDefaultGraph();
+ }
+
+ @SuppressWarnings("deprecation")
+ @Before
+ public void setUp() throws Exception
+ {
+ baseGraph = createGraph();
+ baseGraph.getBulkUpdateHandler().removeAll();
+ securedGraph = org.apache.jena.security.Factory
+ .getInstance(securityEvaluator,
+ "http://example.com/securedGraph", baseGraph);
+ s = NodeFactory.createURI("http://example.com/securedGraph/s");
+ p = NodeFactory.createURI("http://example.com/securedGraph/p");
+ o = NodeFactory.createURI("http://example.com/securedGraph/o");
+ t = new Triple(s, p, o);
+ baseGraph.add(t);
+ }
+
+ @Test
+ public void testBulkUpdateHandler() throws Exception
+ {
+ final BulkUpdateHandler buh = securedGraph.getBulkUpdateHandler();
+ Assert.assertNotNull("BulkUpdateHandler may not be null", buh);
+ Assert.assertTrue("BulkUpdateHandler should be secured",
+ buh instanceof SecuredBulkUpdateHandler);
+ final BulkUpdateHandlerTest buhTest = new BulkUpdateHandlerTest(
+ securityEvaluator) {
+ @Override
+ public void setup()
+ {
+ this.handler = (SecuredBulkUpdateHandler) buh;
+ }
+ };
+ for (final Method m : buhTest.getClass().getMethods())
+ {
+ if (m.isAnnotationPresent(Test.class))
+ {
+ buhTest.setup();
+ m.invoke(buhTest);
+ }
+ }
+ }
+
+ @Test
+ public void testContainsNodes() throws Exception
+ {
+ try
+ {
+ Assert.assertTrue(securedGraph.contains(s, p, o));
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testContainsTriple() throws Exception
+ {
+ try
+ {
+ Assert.assertTrue(securedGraph.contains(t));
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testDelete() throws Exception
+ {
+ final Set<Action> UD = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Delete });
+ try
+ {
+ securedGraph.delete(t);
+
+ if (!securityEvaluator.evaluate(UD))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ Assert.assertEquals(0, baseGraph.size());
+
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(UD))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testDependsOn() throws Exception
+ {
+ try
+ {
+ Assert.assertFalse(securedGraph.dependsOn(GraphFactory
+ .createDefaultGraph()));
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ Assert.assertTrue(securedGraph.dependsOn(baseGraph));
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testFindNodes() throws Exception
+ {
+ try
+ {
+
+ Assert.assertFalse(securedGraph.find(Node.ANY, Node.ANY, Node.ANY)
+ .toList().isEmpty());
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testFindTriple() throws Exception
+ {
+ try
+ {
+ Assert.assertFalse(securedGraph.find(t).toList().isEmpty());
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetPrefixMapping() throws Exception
+ {
+ SecuredPrefixMappingTest.runTests(securityEvaluator,
+ securedGraph.getPrefixMapping());
+ }
+
+ @Test
+ public void testInequality()
+ {
+ EqualityTester
+ .testInequality("proxy and base", securedGraph, baseGraph);
+ final Graph g2 = org.apache.jena.security.graph.impl.Factory
+ .getInstance(securityEvaluator,
+ "http://example.com/securedGraph", baseGraph);
+ EqualityTester.testEquality("proxy and proxy2", securedGraph, g2);
+ EqualityTester.testInequality("base and proxy2", baseGraph, g2);
+ }
+
+ @Test
+ public void testIsIsomorphicWith() throws Exception
+ {
+ try
+ {
+ Assert.assertFalse(securedGraph.isIsomorphicWith(GraphFactory
+ .createDefaultGraph()));
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ try
+ {
+ Assert.assertTrue(securedGraph.isIsomorphicWith(baseGraph));
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testSize() throws Exception
+ {
+ try
+ {
+ Assert.assertEquals(1, securedGraph.size());
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testTripleMatch() throws Exception
+ {
+ try
+ {
+ Assert.assertFalse(securedGraph.find(new TripleMatch() {
+
+ @Override
+ public Triple asTriple()
+ {
+ return Triple.ANY;
+ }
+
+ @Override
+ public Node getMatchObject()
+ {
+ return Node.ANY;
+ }
+
+ @Override
+ public Node getMatchPredicate()
+ {
+ return Node.ANY;
+ }
+
+ @Override
+ public Node getMatchSubject()
+ {
+ return Node.ANY;
+ }
+ }).toList().isEmpty());
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java
new file mode 100644
index 0000000..d65d814
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java
@@ -0,0 +1,124 @@
+package org.apache.jena.security.graph;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.GraphListener ;
+import org.apache.jena.graph.Triple ;
+
+/*
+ * 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.
+ */
+
+public class RecordingGraphListener implements GraphListener
+{
+
+ private boolean add;
+ private boolean delete;
+ private boolean event;
+
+ public boolean isAdd()
+ {
+ return add;
+ }
+
+ public boolean isDelete()
+ {
+ return delete;
+ }
+
+ public boolean isEvent()
+ {
+ return event;
+ }
+
+ @Override
+ public void notifyAddArray( final Graph g, final Triple[] triples )
+ {
+ add = true;
+ }
+
+ @Override
+ public void notifyAddGraph( final Graph g, final Graph added )
+ {
+ add = true;
+ }
+
+ @Override
+ public void notifyAddIterator( final Graph g, final Iterator<Triple> it )
+ {
+ add = true;
+ }
+
+ @Override
+ public void notifyAddList( final Graph g, final List<Triple> triples )
+ {
+ add = true;
+ }
+
+ @Override
+ public void notifyAddTriple( final Graph g, final Triple t )
+ {
+ add = true;
+ }
+
+ @Override
+ public void notifyDeleteArray( final Graph g, final Triple[] triples )
+ {
+ delete = true;
+ }
+
+ @Override
+ public void notifyDeleteGraph( final Graph g, final Graph removed )
+ {
+ delete = true;
+ }
+
+ @Override
+ public void notifyDeleteIterator( final Graph g,
+ final Iterator<Triple> it )
+ {
+ delete = true;
+ }
+
+ @Override
+ public void notifyDeleteList( final Graph g, final List<Triple> L )
+ {
+ delete = true;
+ }
+
+ @Override
+ public void notifyDeleteTriple( final Graph g, final Triple t )
+ {
+ delete = true;
+ }
+
+ @Override
+ public void notifyEvent( final Graph source, final Object value )
+ {
+ event = true;
+ }
+
+ public void reset()
+ {
+ add = false;
+ delete = false;
+ event = false;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java
new file mode 100644
index 0000000..7ad4e84
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java
@@ -0,0 +1,440 @@
+/*
+ * 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.graph;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.Factory;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.graph.SecuredGraph;
+import org.apache.jena.security.graph.SecuredPrefixMapping;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.shared.impl.PrefixMappingImpl ;
+import org.apache.jena.sparql.graph.GraphFactory ;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredPrefixMappingTest
+{
+ public static void runTests( final SecurityEvaluator securityEvaluator,
+ final PrefixMapping prefixMapping ) throws Exception
+ {
+ final PrefixMapping pm = prefixMapping;
+ Assert.assertNotNull("PrefixMapping may not be null", pm);
+ Assert.assertTrue("PrefixMapping should be secured",
+ pm instanceof SecuredPrefixMapping);
+ final SecuredPrefixMappingTest pmTest = new SecuredPrefixMappingTest(
+ securityEvaluator) {
+ @Override
+ public void setup()
+ {
+ this.securedMapping = (SecuredPrefixMapping) pm;
+ }
+ };
+ Method lockTest = null;
+ for (final Method m : pmTest.getClass().getMethods())
+ {
+ if (m.isAnnotationPresent(Test.class))
+ {
+ // lock test must come last
+ if (m.getName().equals("testLock"))
+ {
+ lockTest = m;
+ }
+ else
+ {
+ pmTest.setup();
+ m.invoke(pmTest);
+ }
+
+ }
+ }
+ Assert.assertNotNull( "Did not find 'testLock' method", lockTest );
+ pmTest.setup();
+ lockTest.invoke(pmTest);
+
+ }
+
+ private final SecurityEvaluator securityEvaluator;
+ private final Object principal;
+
+ protected SecuredPrefixMapping securedMapping;
+
+ public SecuredPrefixMappingTest( final SecurityEvaluator securityEvaluator )
+ {
+ this.securityEvaluator = securityEvaluator;
+ this.principal = securityEvaluator.getPrincipal();
+ }
+
+ @Before
+ public void setup()
+ {
+ final Graph g = GraphFactory.createDefaultGraph();
+
+ final SecuredGraph sg = Factory.getInstance(securityEvaluator,
+ "http://example.com/testGraph", g);
+ this.securedMapping = sg.getPrefixMapping();
+ }
+
+ @Test
+ public void testExpandPrefix()
+ {
+ try
+ {
+ securedMapping.expandPrefix("foo");
+ if (!securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetNsPrefixMap()
+ {
+ try
+ {
+ securedMapping.getNsPrefixMap();
+ if (!securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetNsPrefixURI()
+ {
+ try
+ {
+ securedMapping.getNsPrefixURI("foo");
+ if (!securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetNsURIPrefix()
+ {
+ try
+ {
+ securedMapping.getNsURIPrefix("http://example.com/foo");
+ if (!securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testLock()
+ {
+ try
+ {
+ securedMapping.lock();
+ if (!securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testQnameFor()
+ {
+ try
+ {
+ securedMapping.qnameFor("http://example.com/foo/bar");
+ if (!securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testRemoveNsPrefix()
+ {
+ try
+ {
+ securedMapping.removeNsPrefix("foo");
+ if (!securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testSamePrefixMappingAs()
+ {
+ try
+ {
+ securedMapping.samePrefixMappingAs(GraphFactory
+ .createDefaultGraph().getPrefixMapping());
+ if (!securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testSetNsPrefix()
+ {
+ try
+ {
+ securedMapping.setNsPrefix("foo", "http://example.com/foo");
+ if (!securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedMapping.setNsPrefixes(GraphFactory.createDefaultGraph()
+ .getPrefixMapping());
+ if (!securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ securedMapping.setNsPrefixes(new HashMap<String, String>());
+ if (!securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testShortForm()
+ {
+ try
+ {
+ securedMapping.shortForm("http://example.com/foo/bar");
+ if (!securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Read,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testWithDefaultMappings()
+ {
+ PrefixMapping pm = new PrefixMappingImpl();
+ pm.setNsPrefix( "example", "http://example.com");
+ try
+ {
+ // make sure that it must update
+ securedMapping.withDefaultMappings(pm);
+ if (!securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testWithDefaultMappingsNoAdd()
+ {
+ PrefixMapping pm = new PrefixMappingImpl();
+ try
+ {
+ // make sure that it must update
+ securedMapping.withDefaultMappings(pm);
+// if (!securityEvaluator.evaluate(Action.Update,
+// securedMapping.getModelNode()))
+// {
+// Assert.fail("Should have thrown AccessDenied Exception");
+// }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(principal, Action.Update,
+ securedMapping.getModelNode()))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java
new file mode 100644
index 0000000..5fb7178
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.graph;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.tdb.TDB ;
+import org.apache.jena.tdb.TDBFactory ;
+import org.junit.After;
+
+public class TDBGraphTest extends MemGraphTest
+{
+
+ private DatasetGraph dsGraph;
+
+ private File f;
+
+ public TDBGraphTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ }
+
+ @Override
+ protected Graph createGraph() throws IOException
+ {
+ TDB.init();
+ dsGraph = TDBFactory.createDataset().asDatasetGraph();
+ return dsGraph.getDefaultGraph();
+ }
+
+ @After
+ public void tearDown()
+ {
+ TDB.sync(dsGraph);
+ dsGraph.close();
+ TDB.closedown();
+ }
+
+}
[15/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredAltTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredAltTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredAltTest.java
new file mode 100644
index 0000000..4a33885
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredAltTest.java
@@ -0,0 +1,657 @@
+/*
+ * 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.model;
+
+import java.util.Set;
+
+import org.apache.jena.rdf.model.Alt ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredAlt;
+import org.apache.jena.security.model.impl.SecuredAltImpl;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredAltTest extends SecuredContainerTest
+{
+ private Alt alt;
+
+ public SecuredAltTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ }
+
+ private SecuredAlt getSecuredAlt()
+ {
+ return (SecuredAlt) getSecuredRDFNode();
+ }
+
+ @Override
+ @Before
+ public void setup()
+ {
+ super.setup();
+ alt = baseModel.getAlt("http://example.com/testContainer");
+ setSecuredRDFNode(SecuredAltImpl.getInstance(securedModel, alt), alt);
+ }
+
+ /**
+ * @sec.graph Read
+ * @sec.triple Read SecTriple(this, RDF.li(1), o )
+ * @throws AccessDeniedException
+ */
+ @Test
+ public void testGetDefault()
+ {
+ alt.add("SomeDummyItem");
+ try
+ {
+ getSecuredAlt().getDefault();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredAlt().getDefaultAlt();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredAlt().getDefaultBag();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredAlt().getDefaultSeq();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDefaultBoolean()
+ {
+ alt.add(true);
+ try
+ {
+ getSecuredAlt().getDefaultBoolean();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDefaultByte()
+ {
+ alt.add(Byte.MAX_VALUE);
+ try
+ {
+ getSecuredAlt().getDefaultByte();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDefaultChar()
+ {
+ alt.add('c');
+ try
+ {
+ getSecuredAlt().getDefaultChar();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDefaultDouble()
+ {
+ alt.add(3.14d);
+ try
+ {
+ getSecuredAlt().getDefaultDouble();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDefaultFloat()
+ {
+ alt.add(3.14f);
+ try
+ {
+ getSecuredAlt().getDefaultFloat();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDefaultInt()
+ {
+ alt.add(2);
+ try
+ {
+ getSecuredAlt().getDefaultInt();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDefaultLanguage()
+ {
+ alt.add("SomeDummyItem");
+ try
+ {
+ getSecuredAlt().getDefaultLanguage();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredAlt().getDefaultLiteral();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetDefaultLong()
+ {
+ alt.add(3L);
+
+ try
+ {
+ getSecuredAlt().getDefaultLong();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDefaultResource()
+ {
+ alt.setDefault(ResourceFactory
+ .createResource("http://example.com/exampleResourec"));
+ try
+ {
+ getSecuredAlt().getDefaultResource();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ /*
+ * try
+ * {
+ * ResourceF f = ResourceFactory.getInstance();
+ * getSecuredAlt().getDefaultResource( f );
+ * if (!securityEvaluator.evaluate(Action.Read))
+ * {
+ * Assert.fail("Should have thrown AccessDenied Exception");
+ * }
+ * }
+ * catch (final AccessDeniedException e)
+ * {
+ * if (securityEvaluator.evaluate(Action.Read))
+ * {
+ * Assert.fail(String
+ * .format("Should not have thrown AccessDenied Exception: %s - %s",
+ * e, e.getTriple()));
+ * }
+ * }
+ */
+
+ @Test
+ public void testGetDefaultShort()
+ {
+ alt.setDefault(Short.MAX_VALUE);
+ try
+ {
+ getSecuredAlt().getDefaultShort();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDefaultString()
+ {
+ alt.setDefault("Hello World");
+ try
+ {
+ getSecuredAlt().getDefaultString();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ }
+
+ @Test
+ public void testSetDefaultBoolean()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredAlt().setDefault(true);
+ if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
+ {
+ 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 testSetDefaultChar()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredAlt().setDefault('c');
+ if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
+ {
+ 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 testSetDefaultDouble()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredAlt().setDefault(3.14d);
+ if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
+ {
+ 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 testSetDefaultFloat()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredAlt().setDefault(3.14f);
+ if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
+ {
+ 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 testSetDefaultLong()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredAlt().setDefault(2L);
+ if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
+ {
+ 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 testSetDefaultObject()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ final Object o = 2;
+ getSecuredAlt().setDefault(o);
+ if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
+ {
+ 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 testSetDefaultResource()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredAlt().setDefault(
+ ResourceFactory
+ .createResource("http://example.com/resource"));
+ if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
+ {
+ 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 testSetDefaultString()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredAlt().setDefault("test");
+ if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
+ {
+ 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 testSetDefaultStringAndLang()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredAlt().setDefault("dos", "es");
+ if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
+ {
+ 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()));
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredBagTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredBagTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredBagTest.java
new file mode 100644
index 0000000..6c3ac5c
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredBagTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.model;
+
+import org.apache.jena.rdf.model.Bag ;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.model.impl.SecuredBagImpl;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredBagTest extends SecuredContainerTest
+{
+
+ public SecuredBagTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ }
+
+ @Override
+ @Before
+ public void setup()
+ {
+ super.setup();
+ final Bag bag = baseModel.getBag("http://example.com/testContainer");
+ bag.add("SomeDummyItem");
+ setSecuredRDFNode(SecuredBagImpl.getInstance(securedModel, bag), bag);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java
new file mode 100644
index 0000000..9f00757
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java
@@ -0,0 +1,480 @@
+/*
+ * 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.model;
+
+import java.util.Set;
+
+import org.apache.jena.rdf.model.Container ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+import org.apache.jena.rdf.model.Statement ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.MockSecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluatorParameters;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.model.SecuredContainer;
+import org.apache.jena.security.model.impl.SecuredContainerImpl;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public abstract class SecuredContainerTest extends SecuredResourceTest
+{
+
+ public SecuredContainerTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ }
+
+ private SecuredContainer getSecuredContainer()
+ {
+ return (SecuredContainer) getSecuredRDFNode();
+ }
+
+ @Override
+ @Before
+ public void setup()
+ {
+ super.setup();
+ final Container container = baseModel
+ .getBag("http://example.com/testContainer");
+ container.add("SomeDummyItem");
+ setSecuredRDFNode(
+ SecuredContainerImpl.getInstance(securedModel, container),
+ container);
+ }
+
+ @Test
+ public void test()
+ {
+ try
+ {
+ getSecuredContainer().size();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ /**
+ * @sec.graph Update
+ * @sec.triple Create SecTriple( this, RDF.li, o );
+ * @throws AccessDeniedException
+ */
+ @Test
+ public void testAdd()
+ {
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Update, Action.Create });
+ try
+ {
+ getSecuredContainer().add(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
+ {
+ getSecuredContainer().add('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
+ {
+ getSecuredContainer().add(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
+ {
+ getSecuredContainer().add(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
+ {
+ getSecuredContainer().add(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()));
+ }
+ }
+
+ final Object o = Integer.valueOf("1234");
+ try
+ {
+ getSecuredContainer().add(o);
+ 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
+ {
+ getSecuredContainer().add(
+ ResourceFactory
+ .createResource("http://example.com/testResource"));
+ 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
+ {
+ getSecuredContainer().add("foo");
+ 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
+ {
+ getSecuredContainer().add("dos", "esp");
+ 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 testContains()
+ {
+ try
+ {
+ getSecuredContainer().contains(true);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredContainer().contains('c');
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredContainer().contains(3.14D);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredContainer().contains(3.14F);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredContainer().contains(2L);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ final Object o = Integer.valueOf("1234");
+ try
+ {
+ getSecuredContainer().contains(o);
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredContainer().contains(
+ ResourceFactory
+ .createResource("http://example.com/testResource"));
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredContainer().contains("foo");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+
+ try
+ {
+ getSecuredContainer().contains("dos", "esp");
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testIterator()
+ {
+ try
+ {
+ getSecuredContainer().iterator();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ 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 });
+ final Statement s = baseModel.listStatements().next();
+ try
+ {
+ getSecuredContainer().remove(s);
+ 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()));
+ }
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredLiteralTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredLiteralTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredLiteralTest.java
new file mode 100644
index 0000000..09ed40b
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredLiteralTest.java
@@ -0,0 +1,468 @@
+/*
+ * 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.model;
+
+import org.apache.jena.datatypes.DatatypeFormatException ;
+import org.apache.jena.rdf.model.Literal ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+import org.apache.jena.rdf.model.ResourceRequiredException ;
+import org.apache.jena.security.AccessDeniedException ;
+import org.apache.jena.security.MockSecurityEvaluator ;
+import org.apache.jena.security.SecurityEvaluator.Action ;
+import org.apache.jena.security.SecurityEvaluatorParameters ;
+import org.apache.jena.security.model.impl.SecuredLiteralImpl ;
+import org.apache.jena.shared.BadBooleanException ;
+import org.apache.jena.shared.BadCharLiteralException ;
+import org.junit.Assert ;
+import org.junit.Before ;
+import org.junit.Test ;
+import org.junit.runner.RunWith ;
+
+@RunWith( value = SecurityEvaluatorParameters.class )
+public class SecuredLiteralTest extends SecuredRDFNodeTest
+{
+
+ public SecuredLiteralTest( final MockSecurityEvaluator securityEvaluator )
+ {
+ super(securityEvaluator);
+ }
+
+ private SecuredLiteral getSecuredLiteral()
+ {
+ return (SecuredLiteral) getSecuredRDFNode();
+ }
+
+ @Test
+ public void sameValueAs()
+ {
+ try
+ {
+ getSecuredLiteral().sameValueAs(
+ ResourceFactory.createPlainLiteral("Junk"));
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Override
+ @Before
+ public void setup()
+ {
+ super.setup();
+ Literal l = ResourceFactory.createTypedLiteral("literal");
+ setSecuredRDFNode(SecuredLiteralImpl.getInstance(securedModel, l), l);
+ }
+
+ @Test
+ public void testAsLiteral()
+ {
+ getSecuredLiteral().asLiteral();
+ }
+
+ @Test
+ public void testAsResource()
+ {
+ try
+ {
+ getSecuredLiteral().asResource();
+ Assert.fail("Should have thrown ResoruceRequiredException");
+ }
+ catch (final ResourceRequiredException e)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetBoolean()
+ {
+ try
+ {
+ getSecuredLiteral().getBoolean();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final DatatypeFormatException | BadBooleanException e )
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetByte()
+ {
+ try
+ {
+ getSecuredLiteral().getByte();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final DatatypeFormatException | NumberFormatException e )
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetChar()
+ {
+ try
+ {
+ getSecuredLiteral().getChar();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final DatatypeFormatException | BadCharLiteralException e )
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetDatatype()
+ {
+ try
+ {
+ getSecuredLiteral().getDatatype();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDatatypeURI()
+ {
+ try
+ {
+ getSecuredLiteral().getDatatypeURI();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetDouble()
+ {
+ try
+ {
+ getSecuredLiteral().getDouble();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final DatatypeFormatException | NumberFormatException e )
+ {
+ // expected
+ }
+
+ }
+
+ @Test
+ public void testGetFloat()
+ {
+ try
+ {
+ getSecuredLiteral().getFloat();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final DatatypeFormatException | NumberFormatException e )
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetInt()
+ {
+ try
+ {
+ getSecuredLiteral().getInt();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final DatatypeFormatException | NumberFormatException e )
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetLanguage()
+ {
+ try
+ {
+ getSecuredLiteral().getLanguage();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetLexicalForm()
+ {
+ try
+ {
+ getSecuredLiteral().getLexicalForm();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetLong()
+ {
+ try
+ {
+ getSecuredLiteral().getLong();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final DatatypeFormatException | NumberFormatException e )
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetShort()
+ {
+ try
+ {
+ getSecuredLiteral().getShort();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final DatatypeFormatException | NumberFormatException e )
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetString()
+ {
+ try
+ {
+ getSecuredLiteral().getString();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ catch (final DatatypeFormatException | NumberFormatException e )
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetValue()
+ {
+ try
+ {
+ getSecuredLiteral().getValue();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testIsWellFormedXML()
+ {
+ try
+ {
+ getSecuredLiteral().isWellFormedXML();
+ if (!securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail("Should have thrown AccessDenied Exception");
+ }
+ }
+ catch (final AccessDeniedException e)
+ {
+ if (securityEvaluator.evaluate(Action.Read))
+ {
+ Assert.fail(String
+ .format("Should not have thrown AccessDenied Exception: %s - %s",
+ e, e.getTriple()));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredModelDetailTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredModelDetailTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredModelDetailTest.java
new file mode 100644
index 0000000..e96786f
--- /dev/null
+++ b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredModelDetailTest.java
@@ -0,0 +1,335 @@
+/*
+ * 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.model;
+
+import java.net.URL;
+import java.security.Principal;
+import java.util.Set;
+
+import org.apache.http.auth.BasicUserPrincipal;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.Factory;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.vocabulary.RDF ;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests secured model functions against graph where only partial data is
+ * available to the user.
+ *
+ */
+public class SecuredModelDetailTest {
+
+ private static String NS_FMT = "http://example.com/%s";
+ private Model baseModel;
+ private SecuredModel securedModel;
+ private DetailEvaluator secEval;
+ private Property pTo = ResourceFactory.createProperty("http://example.com/to");
+ private Property pFrom = ResourceFactory
+ .createProperty( "http://example.com/from");
+
+ @Before
+ public void setup()
+ {
+ baseModel = ModelFactory.createDefaultModel();
+ baseModel.removeAll();
+ URL url = SecuredModelDetailTest.class.getClassLoader().getResource( "org/apache/jena/security/model/detail.ttl");
+ baseModel.read( url.toExternalForm() );
+ secEval = new DetailEvaluator( baseModel );
+ securedModel = Factory.getInstance(secEval,
+ "http://example.com/detailModelTest", baseModel);
+ }
+
+
+ @Test
+ public void testContains()
+ {
+ secEval.setPrincipal("darla");
+ /* darla can only add values to msg4
+ ex:msg4 rdf:type ex:msg;
+ ex:to "darla" ;
+ ex:from "bob" ;
+ ex:subj "bob to darla 1"
+ */
+
+ Resource s = ResourceFactory.createResource( String.format( NS_FMT, "msg3") );
+ Assert.assertTrue( "should contain msg3", baseModel.contains( s, null ));
+ Assert.assertFalse( "should not see msg3", securedModel.contains( s, null ));
+ Assert.assertTrue( "Sould contain a resource msg3", baseModel.containsResource( s));
+ Assert.assertFalse( "Should not contain a resource msg3'", securedModel.containsResource( s) );
+
+ s = ResourceFactory.createResource( String.format( NS_FMT, "msg4") );
+ Assert.assertTrue( "should contain msg4", baseModel.contains( s, null ));
+ Assert.assertTrue( "should see msg4", securedModel.contains( s, null ));
+ Assert.assertTrue( "Sould contain a resource msg4", baseModel.containsResource( s));
+ Assert.assertTrue( "Should contain a resource msg4'", securedModel.containsResource( s) );
+
+ Assert.assertTrue( "Sould contain a to 'bob'", baseModel.contains( null, pTo, "bob"));
+ Assert.assertFalse( "Should not see to 'bob'", securedModel.contains( null, pTo, "bob") );
+
+ Assert.assertTrue( "Sould contain a from 'bob'", baseModel.contains( null, pFrom, "bob"));
+ Assert.assertTrue( "Should see from 'bob'", securedModel.contains( null, pFrom, "bob") );
+
+ }
+
+ @Test
+ public void testListObjects()
+ {
+ secEval.setPrincipal("darla");
+ /* darla can only add values to msg4
+ ex:msg4 rdf:type ex:msg;
+ ex:to "darla" ;
+ ex:from "bob" ;
+ ex:subj "bob to darla 1"
+ */
+
+ Assert.assertTrue( baseModel.listObjects().toList().size() > 4);
+ Assert.assertEquals( 4, securedModel.listObjects().toList().size());
+
+ Assert.assertTrue( baseModel.listObjectsOfProperty( pFrom ).toList().size() > 1);
+ Assert.assertEquals( 1, securedModel.listObjectsOfProperty( pFrom ).toList().size());
+
+ Resource s = ResourceFactory.createResource( String.format( NS_FMT, "msg3"));
+ Assert.assertEquals( 1, baseModel.listObjectsOfProperty( s, pFrom).toList().size());
+ Assert.assertEquals( 0, securedModel.listObjectsOfProperty( s, pFrom ).toList().size());
+
+ s = ResourceFactory.createResource( String.format( NS_FMT, "msg4"));
+ Assert.assertEquals( 1, baseModel.listObjectsOfProperty( s, pFrom).toList().size());
+ Assert.assertEquals( 1, securedModel.listObjectsOfProperty( s, pFrom ).toList().size());
+ }
+
+ @Test
+ public void testListResources() {
+ secEval.setPrincipal("darla");
+ /* darla can only add values to msg4
+ ex:msg4 rdf:type ex:msg;
+ ex:to "darla" ;
+ ex:from "bob" ;
+ ex:subj "bob to darla 1"
+ */
+ Assert.assertEquals( 5, baseModel.listResourcesWithProperty( pFrom ).toList().size());
+ Assert.assertEquals( 1, securedModel.listResourcesWithProperty( pFrom ).toList().size());
+
+ RDFNode o = ResourceFactory.createPlainLiteral("bob");
+ Assert.assertEquals( 3, baseModel.listResourcesWithProperty( pFrom, o ).toList().size());
+ Assert.assertEquals( 1, securedModel.listResourcesWithProperty( pFrom, o ).toList().size());
+ Assert.assertEquals( 1, baseModel.listResourcesWithProperty( pTo, o ).toList().size());
+ Assert.assertEquals( 0, securedModel.listResourcesWithProperty( pTo, o ).toList().size());
+
+ Assert.assertEquals( 4, baseModel.listResourcesWithProperty( null, o ).toList().size());
+ Assert.assertEquals( 1, securedModel.listResourcesWithProperty( null, o ).toList().size());
+
+ o = ResourceFactory.createPlainLiteral("alice");
+ Assert.assertEquals( 4, baseModel.listResourcesWithProperty( null, o ).toList().size());
+ Assert.assertEquals( 0, securedModel.listResourcesWithProperty( null, o ).toList().size());
+ }
+
+ @Test
+ public void testListStatements()
+ {
+ secEval.setPrincipal("darla");
+ /* darla can only add values to msg4
+ ex:msg4 rdf:type ex:msg;
+ ex:to "darla" ;
+ ex:from "bob" ;
+ ex:subj "bob to darla 1"
+ */
+ Assert.assertEquals( 20, baseModel.listStatements().toList().size());
+ Assert.assertEquals( 4, securedModel.listStatements().toList().size());
+
+ RDFNode o = ResourceFactory.createPlainLiteral("bob");
+ Assert.assertEquals( 1, baseModel.listStatements( null, pTo, o).toList().size());
+ Assert.assertEquals( 0, securedModel.listStatements( null, pTo, o).toList().size());
+ Assert.assertEquals( 3, baseModel.listStatements( null, pFrom, o).toList().size());
+ Assert.assertEquals( 1, securedModel.listStatements( null, pFrom, o).toList().size());
+
+ Resource s = ResourceFactory.createResource( String.format( NS_FMT, "msg3"));
+ Assert.assertEquals( 4, baseModel.listStatements( s, null, (RDFNode)null).toList().size());
+ Assert.assertEquals( 0, securedModel.listStatements( s, null, (RDFNode)null).toList().size());
+
+ Assert.assertEquals( 1, baseModel.listStatements( s, pTo, (RDFNode)null).toList().size());
+ Assert.assertEquals( 0, securedModel.listStatements( s, pTo, (RDFNode)null).toList().size());
+
+ Assert.assertEquals( 0, baseModel.listStatements( s, pTo, o).toList().size());
+ Assert.assertEquals( 0, securedModel.listStatements( s, pTo, o).toList().size());
+ o = ResourceFactory.createPlainLiteral("chuck");
+ Assert.assertEquals( 1, baseModel.listStatements( s, pTo, o).toList().size());
+ Assert.assertEquals( 0, securedModel.listStatements( s, pTo, o).toList().size());
+
+
+ s = ResourceFactory.createResource( String.format( NS_FMT, "msg4"));
+ Assert.assertEquals( 4, baseModel.listStatements( s, null, (RDFNode)null).toList().size());
+ Assert.assertEquals( 4, securedModel.listStatements( s, null, (RDFNode)null).toList().size());
+
+ Assert.assertEquals( 1, baseModel.listStatements( s, pTo, (RDFNode)null).toList().size());
+ Assert.assertEquals( 1, securedModel.listStatements( s, pTo, (RDFNode)null).toList().size());
+
+ Assert.assertEquals( 0, baseModel.listStatements( s, pTo, o).toList().size());
+ Assert.assertEquals( 0, securedModel.listStatements( s, pTo, o).toList().size());
+ o = ResourceFactory.createPlainLiteral("darla");
+ Assert.assertEquals( 1, baseModel.listStatements( s, pTo, o).toList().size());
+ Assert.assertEquals( 1, securedModel.listStatements( s, pTo, o).toList().size());
+ }
+
+ @Test
+ public void testListSubjects()
+ {
+ secEval.setPrincipal("darla");
+ /* darla can only add values to msg4
+ ex:msg4 rdf:type ex:msg;
+ ex:to "darla" ;
+ ex:from "bob" ;
+ ex:subj "bob to darla 1"
+ */
+ Assert.assertEquals( 5, baseModel.listSubjects().toList().size());
+ Assert.assertEquals( 1, securedModel.listSubjects().toList().size());
+
+ Assert.assertEquals( 5, baseModel.listSubjectsWithProperty( pTo ).toList().size());
+ Assert.assertEquals( 1, securedModel.listSubjectsWithProperty( pTo ).toList().size());
+
+ RDFNode o = ResourceFactory.createPlainLiteral("darla");
+ Assert.assertEquals( 1, baseModel.listSubjectsWithProperty( pTo, o ).toList().size());
+ Assert.assertEquals( 1, securedModel.listSubjectsWithProperty( pTo, o ).toList().size());
+
+ o = ResourceFactory.createPlainLiteral("bob");
+ Assert.assertEquals( 1, baseModel.listSubjectsWithProperty( pTo, o ).toList().size());
+ Assert.assertEquals( 0, securedModel.listSubjectsWithProperty( pTo, o ).toList().size());
+
+ Assert.assertEquals( 4, baseModel.listSubjectsWithProperty( null, o ).toList().size());
+ Assert.assertEquals( 1, securedModel.listSubjectsWithProperty( null, o ).toList().size());
+
+ }
+
+ /**
+ * An example evaluator that only provides access ot messages in the graph that
+ * are from or to the principal.
+ *
+ */
+ private class DetailEvaluator implements SecurityEvaluator {
+
+ private Principal principal;
+ private Model model;
+ private RDFNode msgType = ResourceFactory.createResource( "http://example.com/msg" );
+ private Property pTo = ResourceFactory.createProperty( "http://example.com/to" );
+ private Property pFrom = ResourceFactory.createProperty( "http://example.com/from" );
+
+ /**
+ *
+ * @param model The graph we are going to evaluate against.
+ */
+ public DetailEvaluator( Model model )
+ {
+ this.model = model;
+ }
+
+ @Override
+ public boolean evaluate(Object principal, Action action, SecNode graphIRI) {
+ // we allow any action on a graph.
+ return true;
+ }
+
+ private boolean evaluate( Resource r )
+ {
+ // a message is only available to sender or recipient
+ if (r.hasProperty( RDF.type, msgType ))
+ {
+ return r.hasProperty( pTo, ((Principal)principal).getName() ) ||
+ r.hasProperty( pFrom, ((Principal)principal).getName());
+ }
+ return true;
+ }
+
+ private boolean evaluate( SecNode node )
+ {
+ if (node.equals( SecNode.ANY )) {
+ return false; // all wild cards are false
+ }
+
+ if (node.getType().equals( SecNode.Type.URI)) {
+ Resource r = model.createResource( node.getValue() );
+ return evaluate( r );
+ }
+ else if (node.getType().equals( SecNode.Type.Anonymous)) {
+ Resource r = model.getRDFNode( NodeFactory.createAnon( new AnonId( node.getValue()) ) ).asResource();
+ return evaluate( r );
+ }
+ else
+ {
+ return true;
+ }
+
+ }
+
+ private boolean evaluate( SecTriple triple ) {
+ return evaluate( triple.getSubject()) &&
+ evaluate( triple.getObject()) &&
+ evaluate( triple.getPredicate());
+ }
+
+ @Override
+ public boolean evaluate(Object principal, Action action, SecNode graphIRI, SecTriple triple) {
+ return evaluate( triple );
+ }
+
+ @Override
+ public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI) {
+ return true;
+ }
+
+ @Override
+ public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI,
+ SecTriple triple) {
+ return evaluate( triple );
+ }
+
+ @Override
+ public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI) {
+ return true;
+ }
+
+ @Override
+ public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI,
+ SecTriple triple) {
+ return evaluate( triple );
+ }
+
+ @Override
+ public boolean evaluateUpdate(Object principal, SecNode graphIRI, SecTriple from, SecTriple to) {
+ return evaluate( from ) && evaluate( to );
+ }
+
+ public void setPrincipal( String userName )
+ {
+ if (userName == null)
+ {
+ principal = null;
+ }
+ principal = new BasicUserPrincipal( userName );
+ }
+ @Override
+ public Principal getPrincipal() {
+ return principal;
+ }
+
+ }
+
+}
[08/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredModelImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredModelImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredModelImpl.java
deleted file mode 100644
index d0a21c5..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredModelImpl.java
+++ /dev/null
@@ -1,2739 +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.model.impl;
-
-import java.io.* ;
-import java.net.URL ;
-import java.util.* ;
-
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.graph.impl.CollectionGraph ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.rdf.model.impl.RDFReaderFImpl ;
-import org.apache.jena.security.AccessDeniedException ;
-import org.apache.jena.security.SecurityEvaluator ;
-import org.apache.jena.security.SecurityEvaluator.SecTriple ;
-import org.apache.jena.security.graph.SecuredGraph ;
-import org.apache.jena.security.graph.SecuredPrefixMapping ;
-import org.apache.jena.security.impl.ItemHolder ;
-import org.apache.jena.security.impl.SecuredItem ;
-import org.apache.jena.security.impl.SecuredItemImpl ;
-import org.apache.jena.security.impl.SecuredItemInvoker ;
-import org.apache.jena.security.model.* ;
-import org.apache.jena.shared.* ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.Filter ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-import org.apache.jena.vocabulary.RDF ;
-
-/**
- * Implementation of SecuredModel to be used by a SecuredItemInvoker proxy.
- */
-public class SecuredModelImpl extends SecuredItemImpl implements SecuredModel
-{
-
- // a class that implements ModelChangedListener
- private class SecuredModelChangedListener implements ModelChangedListener
- {
- private final ModelChangedListener wrapped;
-
- private SecuredModelChangedListener( final ModelChangedListener wrapped )
- {
- this.wrapped = wrapped;
- }
-
- @Override
- public void addedStatement( final Statement s )
- {
- if (canRead(s.asTriple()))
- {
- wrapped.addedStatement(s);
- }
- }
-
- @Override
- public void addedStatements( final List<Statement> statements )
- {
- if (canRead(Triple.ANY))
- {
- wrapped.addedStatements(statements);
- }
- else
- {
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(),
- WrappedIterator.create(statements.iterator()));
- try
- {
- wrapped.addedStatements(iter.toList());
- }
- finally
- {
- iter.close();
- }
- }
- }
-
- @Override
- public void addedStatements( final Model m )
- {
- if (canRead(Triple.ANY))
- {
- wrapped.addedStatements(m);
- }
- else
- {
- wrapped.addedStatements(SecuredModelImpl.getInstance(
- holder.getSecuredItem(), m));
- }
- }
-
- @Override
- public void addedStatements( final Statement[] statements )
- {
- if (canRead(Triple.ANY))
- {
- wrapped.addedStatements(statements);
- }
- else
- {
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(), WrappedIterator.create(Arrays
- .asList(statements).iterator()));
- try
- {
- final List<Statement> stmts = iter.toList();
- wrapped.addedStatements(stmts.toArray(new Statement[stmts
- .size()]));
- }
- finally
- {
- iter.close();
- }
- }
- }
-
- @Override
- public void addedStatements( final StmtIterator statements )
- {
- if (canRead(Triple.ANY))
- {
- wrapped.addedStatements(statements);
- }
- else
- {
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(), statements);
- try
- {
- wrapped.addedStatements(iter);
- }
- finally
- {
- iter.close();
- }
- }
- }
-
- @Override
- public void notifyEvent( final Model m, final Object event )
- {
- wrapped.notifyEvent(m, event);
- }
-
- @Override
- public void removedStatement( final Statement s )
- {
- if (canRead(s.asTriple()))
- {
- wrapped.removedStatement(s);
- }
- }
-
- @Override
- public void removedStatements( final List<Statement> statements )
- {
-
- if (canRead(Triple.ANY))
- {
- wrapped.removedStatements(statements);
- }
- else
- {
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(),
- WrappedIterator.create(statements.iterator()));
- try
- {
- wrapped.removedStatements(iter.toList());
- }
- finally
- {
- iter.close();
- }
- }
- }
-
- @Override
- public void removedStatements( final Model m )
- {
- if (canRead(Triple.ANY))
- {
- wrapped.removedStatements(m);
- }
- else
- {
- wrapped.removedStatements(SecuredModelImpl.getInstance(
- holder.getSecuredItem(), m));
- }
- }
-
- @Override
- public void removedStatements( final Statement[] statements )
- {
- if (canRead(Triple.ANY))
- {
- wrapped.removedStatements(statements);
- }
- else
- {
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(), WrappedIterator.create(Arrays
- .asList(statements).iterator()));
- try
- {
- final List<Statement> stmts = iter.toList();
- wrapped.removedStatements(stmts.toArray(new Statement[stmts
- .size()]));
- }
- finally
- {
- iter.close();
- }
- }
- }
-
- @Override
- public void removedStatements( final StmtIterator statements )
- {
- if (canRead(Triple.ANY))
- {
- wrapped.removedStatements(statements);
- }
- else
- {
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(), statements);
- try
- {
- wrapped.removedStatements(iter);
- }
- finally
- {
- iter.close();
- }
- }
- }
- }
-
- /*private class ReadFilter extends Filter<Resource> {
- private SecuredItem si;
- private SecuredResource r;
- private Property p;
- ReadFilter( SecuredItem si, SecuredResource r, Property p )
- {
- this.si = si;
- this.r = r;
- this.p = p;
- }
- @Override
- public boolean accept(Resource o) {
- Triple t = new Triple( r.asNode(), p.asNode(), o.asNode());
- return si.canRead( SecuredItemImpl.convert( t ) );
- }};
-*/
- private static final RDFReaderF readerFactory = new RDFReaderFImpl();
- //private static final RDFWriterF writerFactory = new RDFWriterFImpl();
-
- /**
- * Get an instance of SecuredModel
- *
- * @param securedItem
- * the item providing the security context.
- * @param model
- * the Model to secure.
- * @return The SecuredModel
- */
- public static SecuredModel getInstance( final SecuredItem securedItem,
- final Model model )
- {
- return org.apache.jena.security.Factory.getInstance(
- securedItem.getSecurityEvaluator(), securedItem.getModelIRI(),
- model);
- }
-
- /**
- * Get an instance of SecuredModel
- *
- * @param securityEvaluator
- * The security evaluator to use
- * @param modelIRI
- * The IRI (graph IRI) to name this model.
- * @param model
- * The Model to secure.
- * @return the SecuredModel
- */
- public static SecuredModel getInstance(
- final SecurityEvaluator securityEvaluator, final String modelIRI,
- final Model model )
- {
- final ItemHolder<Model, SecuredModel> holder = new ItemHolder<Model, SecuredModel>(
- model);
-
- final SecuredModelImpl checker = new SecuredModelImpl(
- securityEvaluator, modelIRI, holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (model instanceof SecuredModel)
- {
- if (checker.isEquivalent((SecuredModel) model))
- {
- return (SecuredModel) model;
- }
- }
- return holder.setSecuredItem(new SecuredItemInvoker(model.getClass(),
- checker));
- }
-
- // the item holder that contains this SecuredModel.
- private final ItemHolder<Model, SecuredModel> holder;
-
- // The secured graph that this securedModel contains.
- private final SecuredGraph graph;
-
- //
- Map<ModelChangedListener, SecuredModelChangedListener> listeners = new HashMap<ModelChangedListener, SecuredModelChangedListener>();
-
- /**
- * Constructor.
- *
- * @param securityEvaluator
- * The security evaluator to use
- * @param modelURI
- * The securedModel IRI to verify against.
- * @param holder
- * The item holder that will contain this SecuredModel.
- */
- private SecuredModelImpl( final SecurityEvaluator securityEvaluator,
- final String modelURI, final ItemHolder<Model, SecuredModel> holder )
- {
- super(securityEvaluator, modelURI, holder);
- this.graph = org.apache.jena.security.Factory.getInstance(securityEvaluator, modelURI, holder
- .getBaseItem().getGraph());
- this.holder = holder; // FIXME -- this should just access the super holder.
- }
-
- private RDFNode asObject( Object o )
- {
- return o instanceof RDFNode ? (RDFNode) o : ResourceFactory.createTypedLiteral( o );
- }
-
- @Override
- public SecuredModel abort()
- {
- holder.getBaseItem().abort();
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel add( final List<Statement> statements )
- {
- checkUpdate();
- checkCreateStatement(WrappedIterator.create(statements.iterator()));
- holder.getBaseItem().add(statements);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel add( final Model m )
- {
- checkUpdate();
- if (!canCreate(Triple.ANY))
- {
- checkCreateStatement(m.listStatements());
- }
- holder.getBaseItem().add(m);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel add( final Resource s, final Property p, final RDFNode o )
- {
- checkUpdate();
- checkCreate(new Triple(s.asNode(), p.asNode(), o.asNode()));
- holder.getBaseItem().add(s, p, o);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel add( final Resource s, final Property p, final String o )
- {
- return add( s, p, o, false );
- }
-
- @Override
- public SecuredModel add( final Resource s, final Property p,
- final String o, final boolean wellFormed )
- {
- checkUpdate();
- checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(o,
- "", wellFormed)));
- holder.getBaseItem().add(s, p, o, wellFormed);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel add( final Resource s, final Property p,
- final String lex, final RDFDatatype datatype )
- {
- checkUpdate();
- checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(lex,
- datatype)));
- holder.getBaseItem().add(s, p, lex, datatype);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel add( final Resource s, final Property p,
- final String o, final String l )
- {
- checkUpdate();
- checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(o, l,
- false)));
- holder.getBaseItem().add(s, p, o, l);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel add( final Statement s )
- {
- checkUpdate();
- checkCreate(s.asTriple());
- holder.getBaseItem().add(s);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel add( final Statement[] statements )
- {
- checkUpdate();
- if (!canCreate(Triple.ANY))
- {
- for (final Statement s : statements)
- {
- checkCreate(s.asTriple());
- }
- }
- holder.getBaseItem().add(statements);
- return holder.getSecuredItem();
-
- }
-
- @Override
- public SecuredModel add( final StmtIterator iter )
- {
- checkUpdate();
- if (!canCreate(Triple.ANY))
- {
- final List<Triple> lst = new ArrayList<Triple>();
- try
- {
- while (iter.hasNext())
- {
- final Statement s = iter.next();
- checkCreate(s.asTriple());
- lst.add(s.asTriple());
- }
- final Model m = ModelFactory
- .createModelForGraph(new CollectionGraph(lst));
- holder.getBaseItem().add(m.listStatements());
- }
- finally
- {
- iter.close();
- }
- }
- else
- {
- holder.getBaseItem().add(iter);
- }
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final boolean o )
- {
- final Literal l = ResourceFactory.createTypedLiteral(o);
- if (l == null)
- {
- throw new IllegalArgumentException( "HOw did we get a null");
- }
- return add(s, p, l);
- }
-
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final char o )
- {
- final Literal l = ResourceFactory.createTypedLiteral(o);
- return add(s, p, l);
- }
-
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final double o )
- {
- final Literal l = ResourceFactory.createTypedLiteral(o);
- return add(s, p, l);
- }
-
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final float o )
- {
- final Literal l = ResourceFactory.createTypedLiteral(o);
- return add(s, p, l);
- }
-
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final int o )
- {
- final Literal l = ResourceFactory.createTypedLiteral(o);
- return add(s, p, l);
- }
-
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final Literal o )
- {
- return add(s, p, o);
- }
-
- @Override
- public SecuredModel addLiteral( final Resource s, final Property p,
- final long o )
- {
- final Literal l = ResourceFactory.createTypedLiteral(o);
- return add(s, p, l);
- }
-
- @Override
- @Deprecated
- public SecuredModel addLiteral( final Resource s, final Property p,
- final Object o )
- {
- return add(s, p, asObject(o));
- }
-
- @Override
- public SecuredRDFNode asRDFNode( final Node n )
- {
- return SecuredRDFNodeImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .asRDFNode(n));
- }
-
- @Override
- public SecuredStatement asStatement( final Triple t )
- {
- final ExtendedIterator<Triple> iter = holder.getBaseItem().getGraph()
- .find(t);
- final boolean exists = iter.hasNext();
- iter.close();
- if (exists)
- {
- checkRead();
- checkRead(t);
- }
- else
- {
- checkUpdate();
- checkCreate(t);
- }
- return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .asStatement(t));
- }
-
- @Override
- public SecuredModel begin()
- {
- holder.getBaseItem().begin();
- return holder.getSecuredItem();
- }
-
- private void checkCreate( final SecurityEvaluator.SecNode n, final Triple t )
- {
- checkRead(t);
- checkCreate(new SecurityEvaluator.SecTriple(n,
- SecuredItemImpl.convert(RDF.subject.asNode()),
- SecuredItemImpl.convert(t.getSubject())));
- checkCreate(new SecurityEvaluator.SecTriple(n,
- SecuredItemImpl.convert(RDF.predicate.asNode()),
- SecuredItemImpl.convert(t.getPredicate())));
- checkCreate(new SecurityEvaluator.SecTriple(n,
- SecuredItemImpl.convert(RDF.object.asNode()),
- SecuredItemImpl.convert(t.getObject())));
- }
-
- /*
- * private void checkCreateAnonymousResource( final
- * SecurityEvaluator.SecNode n )
- * {
- * checkUpdate();
- * final SecurityEvaluator.SecTriple t = new SecurityEvaluator.SecTriple(n,
- * SecurityEvaluator.SecNode.IGNORE, SecurityEvaluator.SecNode.IGNORE);
- * checkCreate(t);
- * }
- */
- @Override
- public void close()
- {
- holder.getBaseItem().close();
- }
-
- @Override
- public SecuredModel commit()
- {
- holder.getBaseItem().commit();
- return holder.getSecuredItem();
- }
-
- @Override
- public boolean contains( final Resource s, final Property p )
- {
- checkRead();
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(), holder.getBaseItem().listStatements(s, p, (RDFNode) null));
- try
- {
- return iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public boolean contains( final Resource s, final Property p, final RDFNode o )
- {
- checkRead();
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(), holder.getBaseItem().listStatements(s, p, o));
- try
- {
- return iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public boolean contains( final Resource s, final Property p, final String o )
- {
- checkRead();
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(), holder.getBaseItem().listStatements(s, p, o));
- try
- {
- return iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public boolean contains( final Resource s, final Property p,
- final String o, final String l )
- {
- checkRead();
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- holder.getSecuredItem(), holder.getBaseItem().listStatements(s, p, o, l));
- try
- {
- return iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public boolean contains( final Statement s )
- {
- checkRead();
- checkRead(s);
- return holder.getBaseItem().contains(s);
- }
-
- @Override
- public boolean containsAll( final Model model )
- {
- return containsAll(model.listStatements());
- }
-
- @Override
- public boolean containsAll( final StmtIterator iter )
- {
- checkRead();
- final boolean doCheck = canRead(Triple.ANY);
- try
- {
- while (iter.hasNext())
- {
- final Statement stmt = iter.next();
- if (doCheck)
- {
- checkRead(stmt);
- }
- if (!holder.getBaseItem().contains(stmt))
- {
- return false;
- }
- }
- return true;
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public boolean containsAny( final Model model )
- {
- return containsAny(model.listStatements());
-
- }
-
- @Override
- public boolean containsAny( final StmtIterator iter )
- {
- checkRead();
- final boolean skipCheck = canRead(Triple.ANY);
- try
- {
- while (iter.hasNext())
- {
- final Statement stmt = iter.next();
- if (skipCheck || canRead(stmt))
- {
- if (holder.getBaseItem().contains(stmt))
- {
- return true;
- }
- }
- }
- return false;
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final boolean o )
- {
- return contains(s, p, ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final char o )
- {
- return contains(s, p, ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final double o )
- {
- return contains(s, p, ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final float o )
- {
- return contains(s, p, ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final int o )
- {
- return contains(s, p, ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final long o )
- {
- return contains(s, p, ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public boolean containsLiteral( final Resource s, final Property p,
- final Object o )
- {
- return contains(s, p, asObject(o));
- }
-
- @Override
- public boolean containsResource( final RDFNode r )
- {
- checkRead();
- if (canRead(new Triple(Node.ANY, Node.ANY, Node.ANY)))
- {
- return holder.getBaseItem().containsResource(r);
- }
- else
- {
- ExtendedIterator<Statement> iter = listStatements(null, null, r);
- if (r.isResource())
- {
-
- if (r.isURIResource())
- {
- iter = iter
- .andThen(listStatements(null, ResourceFactory
- .createProperty(r.asNode().getURI()),
- (RDFNode) null));
- }
- else
- {
- iter = iter.andThen(listStatements(null, ResourceFactory
- .createProperty(r.asNode().getBlankNodeLabel()),
- (RDFNode) null));
- }
- iter = iter.andThen(listStatements(r.asResource(), null,
- (RDFNode) null));
- }
- try
- {
- return iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
- }
-
- @Override
- public SecuredAlt createAlt()
- {
- checkUpdate();
- checkCreate(new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(RDF.type.asNode()),
- SecuredItemImpl.convert(RDF.Alt.asNode())));
- return SecuredAltImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createAlt());
- }
-
- @Override
- public SecuredAlt createAlt( final String uri )
- {
- checkUpdate();
- checkCreate(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
- RDF.Alt.asNode()));
- return SecuredAltImpl.getInstance(holder.getSecuredItem(),
- holder.getBaseItem().createAlt(uri));
- }
-
- @Override
- public SecuredBag createBag()
- {
- checkUpdate();
- checkCreate(new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(RDF.type.asNode()),
- SecuredItemImpl.convert(RDF.Bag.asNode())));
- return SecuredBagImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createBag());
- }
-
- @Override
- public SecuredBag createBag( final String uri )
- {
- checkUpdate();
- checkCreate(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
- RDF.Bag.asNode()));
- return SecuredBagImpl.getInstance(holder.getSecuredItem(),
- holder.getBaseItem().createBag(uri));
- }
-
- private Model createCopy()
- {
- return ModelFactory.createDefaultModel().add(holder.getSecuredItem());
- }
-
- @Override
- public SecuredRDFList createList()
- {
- checkUpdate();
- return SecuredRDFListImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createList());
- }
-
- @Override
- public SecuredRDFList createList( final Iterator<? extends RDFNode> members )
- {
- checkUpdate();
- checkCreate(new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(RDF.rest.asNode()),
- SecurityEvaluator.SecNode.FUTURE));
- if (!(canCreate(new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(RDF.first.asNode()),
- SecuredItemImpl.convert(Node.ANY)))))
- {
- final List<RDFNode> nodes = new ArrayList<RDFNode>();
- while (members.hasNext())
- {
-
- final RDFNode n = members.next();
- checkCreate(new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(RDF.first.asNode()),
- SecuredItemImpl.convert(n.asNode())));
- nodes.add(n);
- }
- return SecuredRDFListImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createList(nodes.iterator()));
-
- }
- else
- {
- return SecuredRDFListImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createList(members));
- }
- }
-
- @Override
- public SecuredRDFList createList( final RDFNode[] members )
- {
- return createList(Arrays.asList(members).iterator());
- }
-
- @Override
- public SecuredLiteral createLiteral( final String v )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createLiteral(v));
- }
-
- @Override
- public SecuredLiteral createLiteral( final String v,
- final boolean wellFormed )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createLiteral(v, wellFormed));
-
- }
-
- @Override
- public SecuredLiteral createLiteral( final String v, final String language )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createLiteral(v, language));
- }
-
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final boolean o )
- {
- return createStatement(s, p,
- ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final char o )
- {
- return createStatement(s, p,
- ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final double o )
- {
- return createStatement(s, p,
- ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final float o )
- {
- return createStatement(s, p,
- ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final int o )
- {
- return createStatement(s, p,
- ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final long o )
- {
- return createStatement(s, p,
- ResourceFactory.createTypedLiteral(o));
- }
-
- @Override
- public SecuredStatement createLiteralStatement( final Resource s,
- final Property p, final Object o )
- {
- return createStatement(s, p, asObject(o));
- }
-
- @Override
- public SecuredProperty createProperty( final String uri )
- {
- return SecuredPropertyImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createProperty(uri));
- }
-
- @Override
- public SecuredProperty createProperty( final String nameSpace,
- final String localName )
- {
- checkUpdate();
- return SecuredPropertyImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createProperty(nameSpace, localName));
- }
-
- @Override
- public ReifiedStatement createReifiedStatement( final Statement s )
- {
- checkUpdate();
- checkCreate(SecurityEvaluator.SecNode.FUTURE, s.asTriple());
- return SecuredReifiedStatementImpl.getInstance(holder.getSecuredItem(), holder
- .getBaseItem().createReifiedStatement(s));
- }
-
- @Override
- public ReifiedStatement createReifiedStatement( final String uri,
- final Statement s )
- {
- checkUpdate();
- checkCreate(new SecurityEvaluator.SecNode(
- SecurityEvaluator.SecNode.Type.URI, uri), s.asTriple());
- return SecuredReifiedStatementImpl.getInstance(holder.getSecuredItem(), holder
- .getBaseItem().createReifiedStatement(uri, s));
- }
-
- @Override
- public SecuredResource createResource()
- {
- // checkCreateAnonymousResource(SecurityEvaluator.SecNode.FUTURE);
- return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createResource());
- }
-
- @Override
- public SecuredResource createResource( final AnonId id )
- {
- // checkCreateAnonymousResource(new SecurityEvaluator.SecNode(
- // SecurityEvaluator.SecNode.Type.Anonymous, id.getLabelString()));
- return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createResource(id));
- }
-
- @Override
- public SecuredResource createResource( final Resource type )
- {
- checkUpdate();
- final SecurityEvaluator.SecTriple t = new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(RDF.type.asNode()),
- SecuredItemImpl.convert(type.asNode()));
- checkCreate(t);
-
- return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createResource(type));
- }
-
- @Override
- @Deprecated
- public SecuredResource createResource( final ResourceF f )
- {
- return createResource(null, f);
- }
-
- @Override
- public SecuredResource createResource( final String uri )
- {
- return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createResource(uri));
-
- }
-
- @Override
- public SecuredResource createResource( final String uri, final Resource type )
- {
- final Resource r = ResourceFactory.createResource(uri);
- final SecurityEvaluator.SecTriple t = new SecurityEvaluator.SecTriple(
- SecuredItemImpl.convert(r.asNode()),
- SecuredItemImpl.convert(RDF.type.asNode()),
- SecuredItemImpl.convert(type.asNode()));
- if (holder.getBaseItem().contains(r, RDF.type, type))
- {
- checkRead();
- checkRead(t);
- }
- else
- {
- checkUpdate();
- checkCreate(t);
- }
- return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createResource(uri, type));
-
- }
-
- @Override
- @Deprecated
- public SecuredResource createResource( final String uri, final ResourceF f )
- {
- // Resource resource = f.createResource( ResourceFactory.createResource( uri )
- // );
- // checkCreateResource( resource );
- return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createResource(uri, f));
- }
-
- @Override
- public SecuredSeq createSeq()
- {
- checkUpdate();
- checkCreate(new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(RDF.type.asNode()),
- SecuredItemImpl.convert(RDF.Alt.asNode())));
- return SecuredSeqImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createSeq());
- }
-
- @Override
- public SecuredSeq createSeq( final String uri )
- {
- checkUpdate();
- checkCreate(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
- RDF.Alt.asNode()));
- return SecuredSeqImpl.getInstance(holder.getSecuredItem(),
- holder.getBaseItem().createSeq(uri));
- }
-
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final RDFNode o )
- {
- checkUpdate();
- checkCreate(new Triple(s.asNode(), p.asNode(), o.asNode()));
- return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createStatement(s, p, o));
- }
-
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final String o )
- {
- checkUpdate();
- checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createURI(o)));
- return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createStatement(s, p, o));
- }
-
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final String o, final boolean wellFormed )
- {
- return createStatement(s, p, o, "", wellFormed);
- }
-
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final String o, final String l )
- {
- return createStatement(s, p, o, l, false);
- }
-
- @Override
- public SecuredStatement createStatement( final Resource s,
- final Property p, final String o, final String l,
- final boolean wellFormed )
- {
- checkUpdate();
- checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(o, l,
- wellFormed)));
- return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createStatement(s, p, o, l, wellFormed));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final boolean v )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(v));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final Calendar d )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(d));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final char v )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(v));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final double v )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(v));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final float v )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(v));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final int v )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(v));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final long v )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(v));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final Object value )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(value));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final Object value,
- final RDFDatatype dtype )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(value, dtype));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final Object value,
- final String typeURI )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(value, typeURI));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final String v )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(v));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final String lex,
- final RDFDatatype dtype )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(lex, dtype));
- }
-
- @Override
- public SecuredLiteral createTypedLiteral( final String lex,
- final String typeURI )
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .createTypedLiteral(lex, typeURI));
- }
-
- @Override
- public Model difference( final Model model )
- {
- checkRead();
- if (canRead(Triple.ANY))
- {
- return holder.getBaseItem().difference(model);
- }
- else
- {
- return createCopy().difference(model);
- }
- }
-
- @Override
- public void enterCriticalSection( final boolean readLockRequested )
- {
- if (readLockRequested)
- {
- checkRead();
- }
- else
- {
- checkUpdate();
- }
- holder.getBaseItem().enterCriticalSection(readLockRequested);
- }
-
- @Override
- public Object executeInTransaction( final Command cmd )
- {
- return holder.getBaseItem().executeInTransaction(cmd);
- }
-
- @Override
- public String expandPrefix( final String prefixed )
- {
- checkRead();
- return holder.getBaseItem().expandPrefix(prefixed);
- }
-
- @Override
- public SecuredAlt getAlt( final Resource r )
- {
- checkRead();
- checkRead(new Triple(r.asNode(), RDF.type.asNode(), RDF.Alt.asNode()));
- return SecuredAltImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().getAlt(r));
- }
-
- @Override
- public SecuredAlt getAlt( final String uri )
- {
- checkRead();
- checkRead(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
- RDF.Alt.asNode()));
- return SecuredAltImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .getAlt(uri));
- }
-
- @Override
- public SecuredResource getAnyReifiedStatement( final Statement s )
- {
- final RSIterator it = listReifiedStatements(s);
- if (it.hasNext())
- {
- try
- {
- return SecuredReifiedStatementImpl.getInstance(holder.getSecuredItem(),
- it.nextRS());
- }
- finally
- {
- it.close();
- }
- }
- else
- {
- return SecuredReifiedStatementImpl.getInstance(holder.getSecuredItem(),
- createReifiedStatement(s));
- }
- }
-
- @Override
- public SecuredBag getBag( final Resource r )
- {
- checkRead();
- checkRead(new Triple(r.asNode(), RDF.type.asNode(), RDF.Bag.asNode()));
- return SecuredBagImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().getBag(r));
- }
-
- @Override
- public SecuredBag getBag( final String uri )
- {
- checkRead();
- checkRead(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
- RDF.Bag.asNode()));
- return SecuredBagImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .getBag(uri));
- }
-
- @Override
- public SecuredGraph getGraph()
- {
- return graph;
- }
-
- @Override
- public Lock getLock()
- {
- return holder.getBaseItem().getLock();
- }
-
- @Override
- public Map<String, String> getNsPrefixMap()
- {
- checkRead();
- return holder.getBaseItem().getNsPrefixMap();
- }
-
- @Override
- public String getNsPrefixURI( final String prefix )
- {
- checkRead();
- return holder.getBaseItem().getNsPrefixURI(prefix);
- }
-
- @Override
- public String getNsURIPrefix( final String uri )
- {
- checkRead();
- return holder.getBaseItem().getNsURIPrefix(uri);
- }
-
- @Override
- public SecuredStatement getProperty( final Resource s, final Property p )
- {
- final StmtIterator stmt = listStatements(s, p, (RDFNode) null);
- try
- {
- if (stmt.hasNext())
- {
- return SecuredStatementImpl.getInstance(holder.getSecuredItem(), stmt.next());
- }
- return null;
- }
- finally
- {
- if (stmt != null)
- {
- stmt.close();
- }
- }
- }
-
- @Override
- public SecuredProperty getProperty( final String uri )
- {
- checkRead();
- return SecuredPropertyImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .getProperty(uri));
- }
-
- @Override
- public SecuredProperty getProperty( final String nameSpace,
- final String localName )
- {
- checkRead();
- return SecuredPropertyImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .getProperty(nameSpace, localName));
- }
-
- @Override
- public SecuredRDFNode getRDFNode( final Node n )
- {
- RDFNode rdfNode = null;
- if (n.isLiteral())
- {
- rdfNode = ResourceFactory.createTypedLiteral(
- n.getLiteralLexicalForm(), n.getLiteralDatatype());
- }
- else if (n.isURI())
- {
- rdfNode = ResourceFactory.createProperty(n.getURI());
- }
- else if (n.isBlank())
- {
- rdfNode = ResourceFactory.createResource(n.getBlankNodeId()
- .toString());
- }
- else
- {
- throw new IllegalArgumentException("Illegal SecNode type: " + n);
- }
-
- if (holder.getBaseItem().containsResource(rdfNode))
- {
- checkRead();
- }
- else
- {
- checkUpdate();
- }
- if (n.isLiteral())
- {
- return SecuredLiteralImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .getRDFNode(n).asLiteral());
- }
- else
- {
- return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .getRDFNode(n).asResource());
- }
- }
-
- @Override
- public RDFReader getReader()
- {
- return holder.getBaseItem().getReader();
- }
-
- @Override
- public RDFReader getReader( final String lang )
- {
- return holder.getBaseItem().getReader(lang);
- }
-
- @Override
- public void resetRDFReaderF() {
- holder.getBaseItem().resetRDFReaderF();
- }
-
- @Override
- public String removeReader(String lang) throws IllegalArgumentException {
- return holder.getBaseItem().removeReader(lang);
- }
-
- @Override
- public SecuredStatement getRequiredProperty( final Resource s,
- final Property p )
- {
- checkRead();
- if (canRead(Triple.ANY))
- {
- return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .getRequiredProperty(s, p));
- }
- else
- {
- final SecuredStatementIterator si = listStatements(s, p,
- (RDFNode) null);
- try
- {
- if (si.hasNext())
- {
- return (SecuredStatement) si.next();
- }
- else
- {
- throw new PropertyNotFoundException(p);
- }
- }
- finally
- {
- si.close();
- }
- }
- }
-
- @Override
- public SecuredResource getResource( final String uri )
- {
- return createResource(uri);
- }
-
- @Override
- @Deprecated
- public SecuredResource getResource( final String uri, final ResourceF f )
- {
- return createResource(uri, f);
- }
-
- @Override
- public SecuredSeq getSeq( final Resource r )
- {
- checkRead();
- checkRead(new Triple(r.asNode(), RDF.type.asNode(), RDF.Seq.asNode()));
- return SecuredSeqImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().getSeq(r));
- }
-
- @Override
- public SecuredSeq getSeq( final String uri )
- {
- checkRead();
- checkRead(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(),
- RDF.Seq.asNode()));
- return SecuredSeqImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .getSeq(uri));
- }
-
- @Override
- public RDFWriter getWriter()
- {
- return holder.getBaseItem().getWriter();
- }
-
- @Override
- public RDFWriter getWriter( final String lang )
- {
- return holder.getBaseItem().getWriter(lang);
- }
-
- @Override
- public void resetRDFWriterF() {
- holder.getBaseItem().resetRDFWriterF();
- }
-
- @Override
- public String removeWriter(String lang) throws IllegalArgumentException {
- return holder.getBaseItem().removeWriter(lang);
- }
-
- @Override
- public boolean independent()
- {
- return false;
- }
-
- @Override
- public Model intersection( final Model model )
- {
- checkRead();
- if (!canRead(Triple.ANY))
- {
- return holder.getBaseItem().intersection(model);
- }
- else
- {
- return createCopy().intersection(model);
- }
- }
-
- @Override
- public boolean isClosed()
- {
- return holder.getBaseItem().isClosed();
- }
-
- @Override
- public boolean isEmpty()
- {
- checkRead();
- return holder.getBaseItem().isEmpty();
- }
-
- @Override
- public boolean isIsomorphicWith( final Model g )
- {
- checkRead();
- final boolean retval = holder.getBaseItem().isIsomorphicWith(g);
- if (retval && !canRead(Triple.ANY))
- {
- // in this case we have to check all the items in the graph to see
- // if the user can read
- // them all.
- final ExtendedIterator<Statement> stmtIter = holder.getBaseItem()
- .listStatements();
- try
- {
- while (stmtIter.hasNext())
- {
- if (!canRead(stmtIter.next().asTriple()))
- {
- return false;
- }
- }
- }
- finally
- {
- if (stmtIter != null)
- {
- stmtIter.close();
- }
- }
- }
- return retval;
- }
-
- @Override
- public boolean isReified( final Statement s )
- {
- checkRead();
- checkRead(s.asTriple());
-
- final RSIterator it = listReifiedStatements(s);
- try
- {
- return it.hasNext();
- }
- finally
- {
- it.close();
- }
- }
-
- @Override
- public void leaveCriticalSection()
- {
- holder.getBaseItem().leaveCriticalSection();
- }
-
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate,
- final boolean object )
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listLiteralStatements(subject, predicate, object));
- }
-
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate, final char object )
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listLiteralStatements(subject, predicate, object));
- }
-
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate,
- final double object )
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listLiteralStatements(subject, predicate, object));
- }
-
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate, final float object )
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listLiteralStatements(subject, predicate, object));
- }
-
- @Override
- public SecuredStatementIterator listLiteralStatements(
- final Resource subject, final Property predicate, final long object )
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listLiteralStatements(subject, predicate, object));
- }
-
- @Override
- public NsIterator listNameSpaces()
- {
- checkRead();
- return holder.getBaseItem().listNameSpaces();
- }
-
- @Override
- public SecuredNodeIterator<RDFNode> listObjects()
- {
- checkRead();
- ExtendedIterator<RDFNode> nIter = holder.getBaseItem().listObjects();
- if (!canRead(SecTriple.ANY))
- {
- nIter = nIter.filterKeep( new ObjectFilter());
- }
- return new SecuredNodeIterator<RDFNode>(holder.getSecuredItem(), nIter);
- }
-
- @Override
- public SecuredNodeIterator<RDFNode> listObjectsOfProperty( final Property p )
- {
- checkRead();
- ExtendedIterator<RDFNode> nIter = holder.getBaseItem().listObjectsOfProperty(p);
- if (!canRead(SecTriple.ANY))
- {
- nIter = nIter.filterKeep( new ObjectFilter(p));
- }
- return new SecuredNodeIterator<RDFNode>(holder.getSecuredItem(), nIter);
- }
-
- @Override
- public SecuredNodeIterator<RDFNode> listObjectsOfProperty( final Resource s,
- final Property p )
- {
- checkRead();
- ExtendedIterator<RDFNode> nIter = holder.getBaseItem().listObjectsOfProperty(s, p);
- if (!canRead(SecTriple.ANY))
- {
- nIter = nIter.filterKeep( new ObjectFilter(p));
- }
- return new SecuredNodeIterator<RDFNode>(holder.getSecuredItem(), nIter);
- }
-
- @Override
- public SecuredRSIterator listReifiedStatements()
- {
- checkRead();
- return new SecuredRSIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listReifiedStatements());
- }
-
- @Override
- public SecuredRSIterator listReifiedStatements( final Statement st )
- {
- checkRead();
- checkRead(st);
- return new SecuredRSIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listReifiedStatements(st));
- }
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p));
- }
- return new SecuredResIterator( holder.getSecuredItem(), rIter );
-
- }
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final boolean o )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
- }
- return new SecuredResIterator( holder.getSecuredItem(), rIter );
- }
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final char o )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
- }
- return new SecuredResIterator( holder.getSecuredItem(), rIter );
- }
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final double o )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
- }
- return new SecuredResIterator( holder.getSecuredItem(), rIter );
- }
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final float o )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
- }
- return new SecuredResIterator( holder.getSecuredItem(), rIter );
- }
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final long o )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
- }
- return new SecuredResIterator( holder.getSecuredItem(), rIter );
- }
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final Object o )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createTypedLiteral(o)));
- }
- return new SecuredResIterator( holder.getSecuredItem(), rIter );
- }
-
- @Override
- public SecuredResIterator listResourcesWithProperty( final Property p,
- final RDFNode o )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listResourcesWithProperty(p, o);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, o));
- }
- return new SecuredResIterator( holder.getSecuredItem(), rIter );
- }
-
- @Override
- public SecuredStatementIterator listStatements()
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listStatements());
- }
-
- @Override
- public SecuredStatementIterator listStatements( final Resource s,
- final Property p, final RDFNode o )
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listStatements(s, p, o));
- }
-
- @Override
- public SecuredStatementIterator listStatements( final Resource subject,
- final Property predicate, final String object )
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listStatements(subject, predicate, object));
- }
-
- @Override
- public SecuredStatementIterator listStatements( final Resource subject,
- final Property predicate, final String object, final String lang )
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listStatements(subject, predicate, object, lang));
- }
-
- @Override
- public SecuredStatementIterator listStatements( final Selector s )
- {
- checkRead();
- return new SecuredStatementIterator(holder.getSecuredItem(), holder.getBaseItem()
- .listStatements(s));
- }
-
- @Override
- public SecuredResIterator listSubjects()
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjects();
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter());
- }
- return new SecuredResIterator(holder.getSecuredItem(),rIter);
- }
-
- @Override
- public SecuredResIterator listSubjectsWithProperty( final Property p )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjectsWithProperty(p);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p));
- }
- return new SecuredResIterator(holder.getSecuredItem(),rIter);
- }
-
- @Override
- public SecuredResIterator listSubjectsWithProperty( final Property p,
- final RDFNode o )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjectsWithProperty(p, o);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, o));
- }
- return new SecuredResIterator(holder.getSecuredItem(),rIter);
- }
-
- @Override
- public SecuredResIterator listSubjectsWithProperty( final Property p,
- final String o )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjectsWithProperty(p, o);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createPlainLiteral(o)));
- }
- return new SecuredResIterator(holder.getSecuredItem(),rIter);
- }
-
- @Override
- public SecuredResIterator listSubjectsWithProperty( final Property p,
- final String o, final String l )
- {
- checkRead();
- ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjectsWithProperty(p, o, l);
- if (!canRead( SecTriple.ANY))
- {
- rIter=rIter.filterKeep( new ResourceFilter(p, ResourceFactory.createLangLiteral(o, l)));
- }
- return new SecuredResIterator(holder.getSecuredItem(),rIter);
- }
-
- @Override
- public SecuredPrefixMapping lock()
- {
- checkUpdate();
- holder.getBaseItem().lock();
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel notifyEvent( final Object e )
- {
- holder.getBaseItem().notifyEvent(e);
- return holder.getSecuredItem();
- }
-
- @Override
- public String qnameFor( final String uri )
- {
- checkRead();
- return holder.getBaseItem().qnameFor(uri);
- }
-
- @Override
- public SecuredModel query( final Selector s )
- {
- checkRead();
- return SecuredModelImpl.getInstance(holder.getSecuredItem(),
- holder.getBaseItem().query(new SecuredSelector(holder.getSecuredItem(), s)));
- }
-
- @Override
- public SecuredModel read( final InputStream in, final String base )
- {
- checkUpdate();
- try
- {
- SecuredModelImpl.readerFactory.getReader().read(holder.getSecuredItem(), in, base);
- return holder.getSecuredItem();
- }
- catch (final JenaException e)
- {
- if ((e.getCause() != null)
- && (e.getCause() instanceof AccessDeniedException))
- {
- throw (AccessDeniedException) e.getCause();
- }
- throw e;
- }
- }
-
- @Override
- public SecuredModel read( final InputStream in, final String base,
- final String lang )
- {
- checkUpdate();
- try
- {
- SecuredModelImpl.readerFactory.getReader(lang).read(holder.getSecuredItem(), in, base);
- return holder.getSecuredItem();
- }
- catch (final JenaException e)
- {
- if ((e.getCause() != null)
- && (e.getCause() instanceof AccessDeniedException))
- {
- throw (AccessDeniedException) e.getCause();
- }
- throw e;
- }
- }
-
- @Override
- public SecuredModel read( final Reader reader, final String base )
- {
- checkUpdate();
- try
- {
- SecuredModelImpl.readerFactory.getReader().read(holder.getSecuredItem(), reader, base);
- return holder.getSecuredItem();
- }
- catch (final JenaException e)
- {
- if ((e.getCause() != null)
- && (e.getCause() instanceof AccessDeniedException))
- {
- throw (AccessDeniedException) e.getCause();
- }
- throw e;
- }
- }
-
- @Override
- public SecuredModel read( final Reader reader, final String base,
- final String lang )
- {
- checkUpdate();
- try
- {
- SecuredModelImpl.readerFactory.getReader(lang).read(holder.getSecuredItem(), reader,
- base);
- return holder.getSecuredItem();
- }
- catch (final JenaException e)
- {
- if ((e.getCause() != null)
- && (e.getCause() instanceof AccessDeniedException))
- {
- throw (AccessDeniedException) e.getCause();
- }
- throw e;
- }
- }
-
- @Override
- public SecuredModel read( final String url )
- {
- checkUpdate();
- try
- {
- SecuredModelImpl.readerFactory.getReader().read(holder.getSecuredItem(), url);
- return holder.getSecuredItem();
- }
- catch (final JenaException e)
- {
- if ((e.getCause() != null)
- && (e.getCause() instanceof AccessDeniedException))
- {
- throw (AccessDeniedException) e.getCause();
- }
- throw e;
- }
- }
-
- @Override
- public SecuredModel read( final String url, final String lang )
- {
- checkUpdate();
- try
- {
- SecuredModelImpl.readerFactory.getReader(lang).read(holder.getSecuredItem(), url);
- return holder.getSecuredItem();
- }
- catch (final JenaException e)
- {
- if ((e.getCause() != null)
- && (e.getCause() instanceof AccessDeniedException))
- {
- throw (AccessDeniedException) e.getCause();
- }
- throw e;
- }
- }
-
- @Override
- public SecuredModel read( final String url, final String base,
- final String lang )
- {
- try
- {
- final InputStream is = new URL(url).openStream();
- try
- {
- read(is, base, lang);
- }
- finally
- {
- if (null != is)
- {
- is.close();
- }
- }
- }
- catch (final IOException e)
- {
- throw new WrappedIOException(e);
- }
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel register( final ModelChangedListener listener )
- {
- checkRead();
- if (!listeners.containsKey(listener))
- {
- final SecuredModelChangedListener secL = new SecuredModelChangedListener(
- listener);
- listeners.put(listener, secL);
- holder.getBaseItem().register(secL);
- }
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel remove( final List<Statement> statements )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- for (final Statement s : statements)
- {
- checkDelete(s.asTriple());
- }
- }
- holder.getBaseItem().remove(statements);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel remove( final Model m )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- final StmtIterator iter = m.listStatements();
- try
- {
- while (iter.hasNext())
- {
- final Statement stmt = iter.next();
- checkDelete(stmt);
- }
- }
- finally
- {
- iter.close();
- }
- }
- holder.getBaseItem().remove(m);
-
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel remove( final Resource s, final Property p, final RDFNode o )
- {
- checkUpdate();
- checkDelete(new Triple(s.asNode(), p.asNode(), o.asNode()));
- holder.getBaseItem().remove(s, p, o);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel remove( final Statement s )
- {
- checkUpdate();
- checkDelete(wildCardTriple(s));
- holder.getBaseItem().remove(s);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel remove( final Statement[] statements )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- for (final Statement s : statements)
- {
- checkDelete(s.asTriple());
- }
- }
- holder.getBaseItem().remove(statements);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel remove( final StmtIterator iter )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- final List<Triple> lst = new ArrayList<Triple>();
- try
- {
- while (iter.hasNext())
- {
- final Statement s = iter.next();
- checkDelete(s.asTriple());
- lst.add(s.asTriple());
- }
- final Model m = ModelFactory
- .createModelForGraph(new CollectionGraph(lst));
- holder.getBaseItem().remove(m.listStatements());
- }
- finally
- {
- iter.close();
- }
- }
- else
- {
- holder.getBaseItem().remove(iter);
- }
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel removeAll()
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- final StmtIterator iter = holder.getBaseItem().listStatements();
- try
- {
- while (iter.hasNext())
- {
- checkDelete(iter.next());
- }
- }
- finally
- {
- iter.close();
- }
- }
- holder.getBaseItem().removeAll();
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel removeAll( final Resource s, final Property p,
- final RDFNode r )
- {
- checkUpdate();
- if (!canDelete(new Triple(wildCardNode(s), wildCardNode(p),
- wildCardNode(r))))
- {
- final StmtIterator iter = holder.getBaseItem().listStatements(s, p,
- r);
- try
- {
- while (iter.hasNext())
- {
- checkDelete(iter.next());
- }
- }
- finally
- {
- iter.close();
- }
- }
- holder.getBaseItem().removeAll(s, p, r);
- return holder.getSecuredItem();
- }
-
- @Override
- public void removeAllReifications( final Statement s )
- {
- checkUpdate();
- if (canDelete(new Triple(Node.ANY, RDF.subject.asNode(),
- wildCardNode(s.getSubject())))
- && canDelete(new Triple(Node.ANY, RDF.predicate.asNode(),
- wildCardNode(s.getPredicate())))
- && canDelete(new Triple(Node.ANY, RDF.object.asNode(),
- wildCardNode(s.getObject()))))
- {
- holder.getBaseItem().removeAllReifications(s);
- }
- else
- {
- final RSIterator iter = holder.getBaseItem().listReifiedStatements(
- s);
- try
- {
- while (iter.hasNext())
- {
- final ReifiedStatement rs = iter.next();
- checkDelete(new Triple(rs.asNode(), RDF.subject.asNode(),
- wildCardNode(s.getSubject())));
- checkDelete(new Triple(rs.asNode(), RDF.predicate.asNode(),
- wildCardNode(s.getPredicate())));
- checkDelete(new Triple(rs.asNode(), RDF.object.asNode(),
- wildCardNode(s.getObject())));
- }
- holder.getBaseItem().removeAllReifications(s);
- }
- finally
- {
- iter.close();
- }
-
- }
- }
-
- @Override
- public SecuredPrefixMapping removeNsPrefix( final String prefix )
- {
- checkUpdate();
- holder.getBaseItem().removeNsPrefix(prefix);
- return holder.getSecuredItem();
- }
-
- @Override
- public void removeReification( final ReifiedStatement rs )
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- final StmtIterator stmtIter = rs.listProperties();
- try
- {
- while (stmtIter.hasNext())
- {
- checkDelete(stmtIter.next().asTriple());
- }
- }
- finally
- {
- stmtIter.close();
- }
- }
- holder.getBaseItem().removeReification(rs);
- }
-
- @Override
- public boolean samePrefixMappingAs( final PrefixMapping other )
- {
- checkRead();
- return holder.getBaseItem().samePrefixMappingAs(other);
- }
-
- @Override
- public SecuredPrefixMapping setNsPrefix( final String prefix,
- final String uri )
- {
- checkUpdate();
- holder.getBaseItem().setNsPrefix(prefix, uri);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredPrefixMapping setNsPrefixes( final Map<String, String> map )
- {
- checkUpdate();
- holder.getBaseItem().setNsPrefixes(map);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredPrefixMapping setNsPrefixes( final PrefixMapping other )
- {
- checkUpdate();
- holder.getBaseItem().setNsPrefixes(other);
- return holder.getSecuredItem();
- }
-
- @Override
- public String setReaderClassName( final String lang, final String className )
- {
- checkUpdate();
- return holder.getBaseItem().setReaderClassName(lang, className);
- }
-
- @Override
- public String setWriterClassName( final String lang, final String className )
- {
- checkUpdate();
- return holder.getBaseItem().setWriterClassName(lang, className);
- }
-
- @Override
- public String shortForm( final String uri )
- {
- checkRead();
- return holder.getBaseItem().shortForm(uri);
- }
-
- @Override
- public long size()
- {
- checkRead();
- return holder.getBaseItem().size();
- }
-
- @Override
- public boolean supportsSetOperations()
- {
- return holder.getBaseItem().supportsTransactions();
- }
-
- @Override
- public boolean supportsTransactions()
- {
- return holder.getBaseItem().supportsTransactions();
- }
-
- @Override
- public Model union( final Model model )
- {
- checkRead();
- if (canRead(Triple.ANY))
- {
- return holder.getBaseItem().union(model);
- }
- else
- {
- return createCopy().union(model);
- }
- }
-
- @Override
- public SecuredModel unregister( final ModelChangedListener listener )
- {
- if (listeners.containsKey(listener))
- {
- final SecuredModelChangedListener secL = listeners.get(listener);
- holder.getBaseItem().unregister(secL);
- listeners.remove(listener);
- }
- return holder.getSecuredItem();
- }
-
- private Node wildCardNode( final RDFNode node )
- {
- return node == null ? Node.ANY : node.asNode();
- }
-
- private Triple wildCardTriple( final Statement s )
- {
- return new Triple(wildCardNode(s.getSubject()),
- wildCardNode(s.getPredicate()), wildCardNode(s.getObject()));
- }
-
- @Override
- public SecuredPrefixMapping withDefaultMappings( final PrefixMapping map )
- {
- checkUpdate();
- holder.getBaseItem().withDefaultMappings(map);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredResource wrapAsResource( final Node n )
- {
- return SecuredResourceImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem()
- .wrapAsResource(n));
- }
-
- @Override
- public SecuredModel write( final OutputStream out )
- {
- checkRead();
- if (canRead(Triple.ANY))
- {
- holder.getBaseItem().write(out);
- }
- else
- {
- getWriter().write(holder.getSecuredItem(), out, "");
- }
- return holder.getSecuredItem();
-
- }
-
- @Override
- public SecuredModel write( final OutputStream out, final String lang )
- {
- checkRead();
- if (canRead(Triple.ANY))
- {
- holder.getBaseItem().write(out, lang);
- }
- else
- {
- getWriter(lang).write(holder.getSecuredItem(), out, "");
- }
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel write( final OutputStream out, final String lang,
- final String base )
- {
- checkRead();
- if (canRead(Triple.ANY))
- {
- holder.getBaseItem().write(out, lang, base);
- }
- else
- {
- getWriter(lang).write(holder.getSecuredItem(), out, base);
- }
- return holder.getSecuredItem();
-
- }
-
- @Override
- public SecuredModel write( final Writer writer )
- {
- checkRead();
- if (canRead(Triple.ANY))
- {
- holder.getBaseItem().write(writer);
- }
- else
- {
- getWriter().write(holder.getSecuredItem(), writer, "");
- }
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel write( final Writer writer, final String lang )
- {
- checkRead();
- if (canRead(Triple.ANY))
- {
- holder.getBaseItem().write(writer, lang);
- }
- else
- {
- getWriter(lang).write(holder.getSecuredItem(), writer, "");
- }
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredModel write( final Writer writer, final String lang,
- final String base )
- {
- checkRead();
- if (canRead(Triple.ANY))
- {
- holder.getBaseItem().write(writer, lang, base);
- }
- else
- {
- getWriter(lang).write(holder.getSecuredItem(), writer, base);
- }
- return holder.getSecuredItem();
-
- }
-
- private class ResourceFilter extends Filter<Resource> {
- Property p;
- RDFNode o;
-
- ResourceFilter() {
- this(null, null);
- }
-
- ResourceFilter( Property p)
- {
- this(p,null);
- }
-
- ResourceFilter( Property p, RDFNode o)
- {
- this.p = p;
- this.o = o;
- }
-
- @Override
- public boolean accept(Resource s) {
- StmtIterator iter = listStatements(s, p, o);
- try {
- return iter.hasNext();
- }
- finally {
- iter.close();
- }
- }
-
- }
-
- private class ObjectFilter extends Filter<RDFNode> {
- Resource s;
- Property p;
-
- ObjectFilter( ) {
- this(null,null);
- }
-
- ObjectFilter( Property p )
- {
- this(null, p );
- }
-
- ObjectFilter( Resource s, Property p)
- {
- this.s = s;
- this.p = p;
- }
-
- @Override
- public boolean accept(RDFNode o) {
- StmtIterator iter = listStatements(s, p, o);
- try {
- return iter.hasNext();
- }
- finally {
- iter.close();
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredNodeIterator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredNodeIterator.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredNodeIterator.java
deleted file mode 100644
index 2fd93ce..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredNodeIterator.java
+++ /dev/null
@@ -1,143 +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.model.impl;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import org.apache.jena.rdf.model.NodeIterator ;
-import org.apache.jena.rdf.model.RDFNode ;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredRDFNode;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.Filter ;
-import org.apache.jena.util.iterator.Map1 ;
-
-/**
- * A secured RDFNode iterator implementation
- */
-public class SecuredNodeIterator<T extends RDFNode> implements NodeIterator
-{
- private class PermNodeMap<N extends RDFNode> implements Map1<N, RDFNode>
- {
- private final SecuredModel securedModel;
-
- public PermNodeMap( final SecuredModel securedModel )
- {
- this.securedModel = securedModel;
- }
-
- @Override
- public SecuredRDFNode map1( final RDFNode o )
- {
- return SecuredRDFNodeImpl.getInstance(securedModel, o);
- }
- }
-
- private final ExtendedIterator<RDFNode> iter;
-
- /**
- * Constructor
- *
- * @param securedItem
- * the item defining the security context
- * @param wrapped
- * the iterator to be wrapped.
- */
- SecuredNodeIterator( final SecuredModel securedModel,
- final ExtendedIterator<T> wrapped )
- {
- final PermNodeMap<T> map1 = new PermNodeMap<T>(securedModel);
- iter = wrapped.mapWith(map1);
- }
-
- @Override
- public <X extends RDFNode> ExtendedIterator<RDFNode> andThen(
- final Iterator<X> other )
- {
- return iter.andThen(other);
- }
-
- @Override
- public void close()
- {
- iter.close();
- }
-
- @Override
- public ExtendedIterator<RDFNode> filterDrop( final Filter<RDFNode> f )
- {
- return iter.filterDrop(f);
- }
-
- @Override
- public ExtendedIterator<RDFNode> filterKeep( final Filter<RDFNode> f )
- {
- return iter.filterKeep(f);
- }
-
- @Override
- public boolean hasNext()
- {
- return iter.hasNext();
- }
-
- @Override
- public <U> ExtendedIterator<U> mapWith( final Map1<RDFNode, U> map1 )
- {
- return iter.mapWith(map1);
- }
-
- @Override
- public RDFNode next()
- {
- return iter.next();
- }
-
- @Override
- public RDFNode nextNode() throws NoSuchElementException
- {
- return next();
- }
-
- @Override
- public void remove()
- {
- iter.remove();
- }
-
- @Override
- public RDFNode removeNext()
- {
- return iter.removeNext();
- }
-
- @Override
- public List<RDFNode> toList()
- {
- return iter.toList();
- }
-
- @Override
- public Set<RDFNode> toSet()
- {
- return iter.toSet();
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredPropertyImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredPropertyImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredPropertyImpl.java
deleted file mode 100644
index c0ee426..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredPropertyImpl.java
+++ /dev/null
@@ -1,129 +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.model.impl;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.Property ;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemInvoker;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredProperty;
-
-/**
- * Implementation of SecuredProperty to be used by a SecuredItemInvoker proxy.
- */
-public class SecuredPropertyImpl extends SecuredResourceImpl implements
- SecuredProperty
-{
- /**
- * Get an instance of SecuredProperty
- *
- * @param securedModel
- * the Secured Model to use.
- * @param property
- * The property to secure
- * @return The SecuredProperty
- */
- public static SecuredProperty getInstance( final SecuredModel securedModel,
- final Property property )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (property == null)
- {
- throw new IllegalArgumentException("Property may not be null");
- }
-
- // check that property has a securedModel.
- Property goodProp = property;
- if (goodProp.getModel() == null)
- {
- final Node n = property.asNode();
- if (property.isAnon())
- {
- goodProp = securedModel.createProperty(n.getBlankNodeId()
- .getLabelString());
- }
- else
- {
- goodProp = securedModel.createProperty(property.asNode()
- .getURI());
- }
- }
-
- final ItemHolder<Property, SecuredProperty> holder = new ItemHolder<Property, SecuredProperty>(
- goodProp);
- final SecuredPropertyImpl checker = new SecuredPropertyImpl(
- securedModel, holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (goodProp instanceof SecuredProperty)
- {
- if (checker.isEquivalent((SecuredProperty) goodProp))
- {
- return (SecuredProperty) goodProp;
- }
- }
- return holder.setSecuredItem(new SecuredItemInvoker(
- property.getClass(), checker));
- }
-
- // the item holder that contains this SecuredProperty
- private final ItemHolder<? extends Property, ? extends SecuredProperty> holder;
-
- /**
- * Constructor
- *
- * @param securityEvaluator
- * The security evaluator to use.
- * @param graphIRI
- * the graph IRI to validate against.
- * @param holder
- * The item holder that will contain this SecuredProperty.
- */
- private SecuredPropertyImpl(
- final SecuredModel securedModel,
- final ItemHolder<? extends Property, ? extends SecuredProperty> holder )
- {
- super(securedModel, holder);
- this.holder = holder;
- }
-
- @Override
- public int getOrdinal()
- {
- checkRead();
- return holder.getBaseItem().getOrdinal();
- }
-
- @Override
- public Property inModel( final Model m )
- {
- return (Property) super.inModel(m);
- }
-
- @Override
- public boolean isProperty()
- {
- return true;
- }
-}
[06/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredStatementImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredStatementImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredStatementImpl.java
deleted file mode 100644
index 9981b00..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredStatementImpl.java
+++ /dev/null
@@ -1,560 +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.model.impl;
-
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.impl.ItemHolder ;
-import org.apache.jena.security.impl.SecuredItemImpl ;
-import org.apache.jena.security.impl.SecuredItemInvoker ;
-import org.apache.jena.security.model.* ;
-import org.apache.jena.shared.PropertyNotFoundException ;
-
-/**
- * Implementation of SecuredStatement to be used by a SecuredItemInvoker proxy.
- */
-public class SecuredStatementImpl extends SecuredItemImpl implements
- SecuredStatement
-{
- /**
- * get a SecuredStatement
- *
- * @param securedModel
- * The secured model that provides the security context
- * @param stmt
- * The statement to secure.
- * @return the SecuredStatement
- */
- public static SecuredStatement getInstance(
- final SecuredModel securedModel, final Statement stmt )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (stmt == null)
- {
- throw new IllegalArgumentException("Statement may not be null");
- }
-
- final ItemHolder<Statement, SecuredStatement> holder = new ItemHolder<Statement, SecuredStatement>(
- stmt);
-
- final SecuredStatementImpl checker = new SecuredStatementImpl(
- securedModel, holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (stmt instanceof SecuredStatement)
- {
- if (checker.isEquivalent((SecuredStatement) stmt))
- {
- return (SecuredStatement) stmt;
- }
- }
- return holder.setSecuredItem(new SecuredItemInvoker(holder
- .getBaseItem().getClass(), checker));
- }
-
- // the item holder that contains this SecuredStatement.
- private final ItemHolder<Statement, SecuredStatement> holder;
-
- private final SecuredModel securedModel;
-
- /**
- * Constructor.
- *
- * @param securityEvaluator
- * The security evaluator to use.
- * @param graphIRI
- * the graph IRI to verify against.
- * @param holder
- * The item holder that will contain this SecuredStatement.
- */
- private SecuredStatementImpl( final SecuredModel securedModel,
- final ItemHolder<Statement, SecuredStatement> holder )
- {
- super(securedModel, holder);
- this.holder = holder;
- this.securedModel = securedModel;
- }
-
- @Override
- public Triple asTriple()
- {
- checkRead();
- final Triple retval = holder.getBaseItem().asTriple();
- checkRead(retval);
- return retval;
- }
-
- @Override
- public boolean canCreate()
- {
- return super.canCreate() ? canCreate(holder.getBaseItem()) : false;
- }
-
- @Override
- public boolean canDelete()
- {
- return super.canDelete() ? canDelete(holder.getBaseItem()) : false;
- }
-
- @Override
- public boolean canRead()
- {
- return super.canRead() ? canRead(holder.getBaseItem()) : false;
- }
-
- @Override
- public SecuredStatement changeLiteralObject( final boolean o )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = getNewTriple(base, o);
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeLiteralObject(o));
- }
-
- @Override
- public SecuredStatement changeLiteralObject( final char o )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = getNewTriple(base, o);
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeLiteralObject(o));
- }
-
- @Override
- public SecuredStatement changeLiteralObject( final double o )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = getNewTriple(base, o);
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeLiteralObject(o));
- }
-
- @Override
- public SecuredStatement changeLiteralObject( final float o )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = getNewTriple(base, o);
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeLiteralObject(o));
- }
-
- @Override
- public SecuredStatement changeLiteralObject( final int o )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = getNewTriple(base, o);
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeLiteralObject(o));
- }
-
- @Override
- public SecuredStatement changeLiteralObject( final long o )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = getNewTriple(base, o);
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeLiteralObject(o));
- }
-
- @Override
- public SecuredStatement changeObject( final RDFNode o )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = new Triple(base.getSubject(),
- base.getPredicate(), o.asNode());
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeObject(o));
- }
-
- @Override
- public SecuredStatement changeObject( final String o )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = getNewTriple(base, o);
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeObject(o));
- }
-
- @Override
- public SecuredStatement changeObject( final String o,
- final boolean wellFormed )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = new Triple(base.getSubject(),
- base.getPredicate(), NodeFactory.createLiteral(o, "", wellFormed));
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeObject(o));
- }
-
- @Override
- public SecuredStatement changeObject( final String o, final String l )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = new Triple(base.getSubject(),
- base.getPredicate(), NodeFactory.createLiteral(o, l, false));
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeObject(o, l));
- }
-
- @Override
- public SecuredStatement changeObject( final String o, final String l,
- final boolean wellFormed )
- {
- checkUpdate();
- final Triple base = holder.getBaseItem().asTriple();
- final Triple newBase = new Triple(base.getSubject(),
- base.getPredicate(), NodeFactory.createLiteral(o, l, wellFormed));
- checkUpdate(base, newBase);
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().changeObject(o, l, wellFormed));
- }
-
- @Override
- public SecuredReifiedStatement createReifiedStatement()
- {
- checkUpdate();
- checkCreateReified(null,
- SecuredItemImpl.convert(holder.getBaseItem().asTriple()));
- return SecuredReifiedStatementImpl.getInstance(getModel(), holder
- .getBaseItem().createReifiedStatement());
- }
-
- @Override
- public SecuredReifiedStatement createReifiedStatement( final String uri )
- {
- checkUpdate();
- checkCreateReified(uri,
- SecuredItemImpl.convert(holder.getBaseItem().asTriple()));
- return SecuredReifiedStatementImpl.getInstance(getModel(), holder
- .getBaseItem().createReifiedStatement(uri));
- }
-
- @Override
- public SecuredAlt getAlt()
- {
- return SecuredAltImpl.getInstance(getModel(), holder.getBaseItem()
- .getAlt());
- }
-
- @Override
- public SecuredBag getBag()
- {
- return SecuredBagImpl.getInstance(getModel(), holder.getBaseItem()
- .getBag());
- }
-
- @Override
- public boolean getBoolean()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getBoolean();
- }
-
- @Override
- public byte getByte()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getByte();
- }
-
- @Override
- public char getChar()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getChar();
-
- }
-
- @Override
- public double getDouble()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getDouble();
- }
-
- @Override
- public float getFloat()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getFloat();
- }
-
- @Override
- public int getInt()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getInt();
- }
-
- @Override
- public String getLanguage()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getLiteral().getLanguage();
- }
-
- @Override
- public SecuredLiteral getLiteral()
- {
- return SecuredLiteralImpl.getInstance(getModel(), holder.getBaseItem()
- .getLiteral());
- }
-
- @Override
- public long getLong()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getLong();
- }
-
- @Override
- public SecuredModel getModel()
- {
- return securedModel;
- }
-
- private Triple getNewTriple( final Triple t, final Object o )
- {
- return new Triple(t.getSubject(), t.getPredicate(),
- NodeFactory.createLiteral(String.valueOf(o), "", false));
- }
-
- @Override
- public SecuredRDFNode getObject()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- final RDFNode rdfNode = holder.getBaseItem().getObject();
- return SecuredRDFNodeImpl.getInstance(getModel(), rdfNode);
-
- }
-
- @Override
- public SecuredProperty getPredicate()
- {
- return SecuredPropertyImpl.getInstance(getModel(), holder.getBaseItem()
- .getPredicate());
- }
-
- @Override
- public SecuredStatement getProperty( final Property p )
- {
- final StmtIterator s = holder
- .getBaseItem()
- .getModel()
- .listStatements(holder.getBaseItem().getObject().asResource(),
- p, (RDFNode) null);
- final SecuredStatementIterator iter = new SecuredStatementIterator(
- getModel(), s);
- try
- {
- if (iter.hasNext())
- {
- return SecuredStatementImpl
- .getInstance(getModel(), iter.next());
- }
- else
- {
- throw new PropertyNotFoundException(p);
- }
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public SecuredResource getResource()
- {
- return SecuredResourceImpl.getInstance(getModel(), holder.getBaseItem()
- .getResource());
- }
-
- @Override
- @Deprecated
- public SecuredResource getResource( final ResourceF f )
- {
- return SecuredResourceImpl.getInstance(getModel(), holder.getBaseItem()
- .getResource(f));
- }
-
- @Override
- public SecuredSeq getSeq()
- {
- return SecuredSeqImpl.getInstance(getModel(), holder.getBaseItem()
- .getSeq());
- }
-
- @Override
- public short getShort()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getShort();
- }
-
- @Override
- public SecuredStatement getStatementProperty( final Property p )
- {
- final RSIterator rsIter = holder.getBaseItem().listReifiedStatements();
- try
- {
- while (rsIter.hasNext())
- {
- final ReifiedStatement s = rsIter.next();
- if (s.hasProperty(p))
- {
- return SecuredStatementImpl.getInstance(getModel(),
- s.getProperty(p));
- }
- }
- throw new PropertyNotFoundException(p);
- }
- finally
- {
- rsIter.close();
- }
- }
-
- @Override
- public String toString()
- {
- if (canRead() && canRead(holder.getBaseItem().asTriple()))
- {
- return holder.getBaseItem().toString();
- }
- else
- {
- return super.toString();
- }
- }
-
- @Override
- public String getString()
- { return getLiteral().getLexicalForm(); }
-
- @Override
- public SecuredResource getSubject()
- {
- return SecuredResourceImpl.getInstance(getModel(), holder.getBaseItem()
- .getSubject());
- }
-
- @Override
- public boolean hasWellFormedXML()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().getLiteral().isWellFormedXML();
- }
-
- @Override
- public boolean isReified()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return holder.getBaseItem().isReified();
- }
-
- @Override
- public RSIterator listReifiedStatements()
- {
- checkRead();
- checkRead(holder.getBaseItem().asTriple());
- return new SecuredRSIterator(getModel(), holder.getBaseItem()
- .listReifiedStatements());
- }
-
- @Override
- public SecuredStatement remove()
- {
- checkUpdate();
- checkDelete(holder.getBaseItem());
- holder.getBaseItem().remove();
- return holder.getSecuredItem();
- }
-
- @Override
- public void removeReification()
- {
- checkUpdate();
- if (!canDelete(Triple.ANY))
- {
- StmtIterator iter = null;
- final RSIterator rsIter = holder.getBaseItem()
- .listReifiedStatements();
- try
- {
- while (rsIter.hasNext())
- {
- final ReifiedStatement stmt = rsIter.next();
- iter = stmt.listProperties();
- while (iter.hasNext())
- {
- final Statement s = iter.next();
- checkDelete(s);
- }
- }
- }
- finally
- {
- rsIter.close();
- if (iter != null)
- {
- iter.close();
- }
- }
- }
- holder.getBaseItem().removeReification();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredStatementIterator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredStatementIterator.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredStatementIterator.java
deleted file mode 100644
index 6066da7..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredStatementIterator.java
+++ /dev/null
@@ -1,148 +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.model.impl;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import org.apache.jena.rdf.model.Statement ;
-import org.apache.jena.rdf.model.StmtIterator ;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredStatement;
-import org.apache.jena.security.utils.PermStatementFilter;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.Filter ;
-import org.apache.jena.util.iterator.Map1 ;
-
-/**
- * A secured StatementIterator implementation
- */
-public class SecuredStatementIterator implements StmtIterator
-{
-
- private class PermStatementMap implements Map1<Statement, Statement>
- {
- private final SecuredModel securedModel;
-
- public PermStatementMap( final SecuredModel securedModel )
- {
- this.securedModel = securedModel;
- }
-
- @Override
- public SecuredStatement map1( final Statement o )
- {
- return SecuredStatementImpl.getInstance(securedModel, o);
- }
- }
-
- private final ExtendedIterator<Statement> iter;
-
- /**
- * Constructor.
- *
- * @param securedModel
- * The item providing the security context.
- * @param wrapped
- * The iterator to wrap.
- */
- public SecuredStatementIterator( final SecuredModel securedModel,
- final ExtendedIterator<Statement> wrapped )
- {
- final PermStatementFilter filter = new PermStatementFilter(
- new Action[] { Action.Read }, securedModel);
- final PermStatementMap map1 = new PermStatementMap(securedModel);
- iter = wrapped.filterKeep(filter).mapWith(map1);
- }
-
- @Override
- public <X extends Statement> ExtendedIterator<Statement> andThen(
- final Iterator<X> other )
- {
- return iter.andThen(other);
- }
-
- @Override
- public void close()
- {
- iter.close();
- }
-
- @Override
- public ExtendedIterator<Statement> filterDrop( final Filter<Statement> f )
- {
- return iter.filterDrop(f);
- }
-
- @Override
- public ExtendedIterator<Statement> filterKeep( final Filter<Statement> f )
- {
- return iter.filterKeep(f);
- }
-
- @Override
- public boolean hasNext()
- {
- return iter.hasNext();
- }
-
- @Override
- public <U> ExtendedIterator<U> mapWith( final Map1<Statement, U> map1 )
- {
- return iter.mapWith(map1);
- }
-
- @Override
- public Statement next()
- {
- return iter.next();
- }
-
- @Override
- public Statement nextStatement() throws NoSuchElementException
- {
- return next();
- }
-
- @Override
- public void remove()
- {
- iter.remove();
- }
-
- @Override
- public Statement removeNext()
- {
- return iter.removeNext();
- }
-
- @Override
- public List<Statement> toList()
- {
- return iter.toList();
- }
-
- @Override
- public Set<Statement> toSet()
- {
- return iter.toSet();
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/package-info.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/package-info.java b/jena-security/src/main/java/org/apache/jena/security/package-info.java
deleted file mode 100644
index 359dc3b..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/package-info.java
+++ /dev/null
@@ -1,48 +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.
- */
-/**
- * JenaSecurity is a SecurityEvaluator interface and a set of dynamic proxies that apply that
- * interface to Jena Graphs, Models, and associated methods and classes.
- * <p>
- * The SecurityEvaluator class must be implemented. This class provides the interface to the
- * authentication results (e.g. <code>getPrincipal()</code>) and the authorization system.
- * </p><p>
- * <ul>
- * <li>
- * Create a SecuredGraph by calling <code>Factory.getInstance( SecurityEvaluator, String, Graph );</code>
- * </li><li>
- * Create a SecuredModel by calling <code>Factory.getInstance( SecurityEvaluator, String, Model )</code>
- * </li><li>
- * It is not recommended that you create a model by calling the Jena <code>ModelFactory.createModelForGraph( SecuredGraph )</code>
- * See Overview for discussion.
- * </li>
- * </ul>
- * </p><p>
- * <em>NOTES:</em>
- * <ul>
- * <li>See SecurityEvaluator documentation for description of cascading security checks</li>
- * <li>Secured methods are annotated with:
- * @sec.graph for permissions required on the graph to execute the method.
- * @sec.triple for permissions required on the associated triples (if any) to execute the method.
- * </li>
- * <li>It is possible to implement a SecurityEvaluator that does not enforce security at the triple
- * level. See SecurityEvaluator documentation for details</li>
- * </ul>
- * </p>
- */
-package org.apache.jena.security;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngine.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngine.java b/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngine.java
deleted file mode 100644
index 1afec86..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngine.java
+++ /dev/null
@@ -1,152 +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.query;
-
-import java.security.Principal;
-import java.util.Set;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.query.Query ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.SecurityEvaluator.SecNode.Type;
-import org.apache.jena.security.graph.SecuredGraph;
-import org.apache.jena.security.query.rewriter.OpRewriter;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.main.QueryEngineMain ;
-import org.apache.jena.sparql.util.Context ;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SecuredQueryEngine extends QueryEngineMain
-{
- private static Logger LOG = LoggerFactory
- .getLogger(SecuredQueryEngine.class);
-
- private SecurityEvaluator securityEvaluator;
- private SecNode graphIRI;
-
- /*
- * public SecuredQueryEngine( Op op, DatasetGraph dataset, Binding input,
- * Context context )
- * {
- * super(op, dataset, input, context);
- * setGraphIRI( dataset );
- * }
- */
- public SecuredQueryEngine( final Query query, final DatasetGraph dataset,
- final Binding input, final Context context )
- {
- super(query, dataset, input, context);
- setGraphIRI(dataset);
- }
-
- public SecurityEvaluator getSecurityEvaluator()
- {
- return securityEvaluator;
- }
-
- @Override
- protected Op modifyOp( final Op op )
- {
- final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
- SecuredQueryEngine.LOG.debug("Before: {}", op);
- op.visit(rewriter);
- Op result = rewriter.getResult();
- result = result == null ? op : result;
- SecuredQueryEngine.LOG.debug("After: {}", result);
- result = super.modifyOp(result);
- SecuredQueryEngine.LOG.debug("After Optimize: {}", result);
- return result;
- }
-
- 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 = new SecNode(Type.URI, "urn:x-arq:DefaultGraph");
- this.securityEvaluator = new SecurityEvaluator() {
-
- @Override
- public boolean evaluate( final Object principal, final Action action,
- final SecNode graphIRI )
- {
- return true;
- }
-
- @Override
- public boolean evaluate( final Object principal, final Action action,
- final SecNode graphIRI, final SecTriple triple )
- {
- return true;
- }
-
- @Override
- public boolean evaluate( final Object principal, final Set<Action> action,
- final SecNode graphIRI )
- {
- return true;
- }
-
- @Override
- public boolean evaluate( final Object principal, final Set<Action> action,
- final SecNode graphIRI, final SecTriple triple )
- {
- return true;
- }
-
- @Override
- public boolean evaluateAny( final Object principal, final Set<Action> action,
- final SecNode graphIRI )
- {
- return true;
- }
-
- @Override
- public boolean evaluateAny( final Object principal, final Set<Action> action,
- final SecNode graphIRI, final SecTriple triple )
- {
- return true;
- }
-
- @Override
- public boolean evaluateUpdate( final Object principal, final SecNode graphIRI,
- final SecTriple from, final SecTriple to )
- {
- return true;
- }
-
- @Override
- public Principal getPrincipal()
- {
- return null;
- }
- };
-
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngineConfig.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngineConfig.java b/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngineConfig.java
deleted file mode 100644
index 479814b..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngineConfig.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.query;
-
-import org.apache.jena.sparql.util.Context ;
-
-public class SecuredQueryEngineConfig
-{
-
- public void initializeContext(Context context)
- {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngineFactory.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngineFactory.java b/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngineFactory.java
deleted file mode 100644
index 41988b2..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/query/SecuredQueryEngineFactory.java
+++ /dev/null
@@ -1,115 +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.query;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.query.Query ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.graph.SecuredGraph;
-import org.apache.jena.sparql.ARQInternalErrorException ;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.engine.Plan ;
-import org.apache.jena.sparql.engine.QueryEngineFactory ;
-import org.apache.jena.sparql.engine.QueryEngineRegistry ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.util.Context ;
-
-public class SecuredQueryEngineFactory implements QueryEngineFactory
-{
- private boolean silentService = true;
- private SecuredQueryEngineConfig cfgResource;
- private SecurityEvaluator securityEvaluator;
-
- private static SecuredQueryEngineFactory factory = new SecuredQueryEngineFactory();
-
- static public SecuredQueryEngineFactory getFactory() {
- return factory;
- }
-
- static public void register() {
- QueryEngineRegistry.addFactory(factory);
- }
-
- static public void unregister() {
- QueryEngineRegistry.removeFactory(factory);
- }
-
- public SecurityEvaluator getSecurityEvaluator() {
- return securityEvaluator;
- }
-
- public void setSecurityEvaluator(SecurityEvaluator securityEvaluator) {
- this.securityEvaluator = securityEvaluator;
- }
-
- public boolean isSilentService() {
- return silentService;
- }
-
- public void setSilentService(boolean silentService) {
- this.silentService = silentService;
- }
-
- public void setSecuredQueryEngineConfig(SecuredQueryEngineConfig cfgResource) {
- this.cfgResource = cfgResource;
-
- }
-
- /**
- * Only accept a secured dataset
- */
- @Override
- public boolean accept(Query query, DatasetGraph dataset, Context context) {
- Graph g = dataset.getDefaultGraph();
- return g instanceof SecuredGraph;
- }
-
- @Override
- public Plan create(Query query, DatasetGraph dataset, Binding initial,
- Context context) {
- // set up the context
- if (cfgResource != null) {
- cfgResource.initializeContext( context );
- }
-
- // Create a query engine instance.
- SecuredQueryEngine engine = new SecuredQueryEngine(query, dataset,
- initial, context);
- return engine.getPlan();
- }
-
- @Override
- public boolean accept(Op op, DatasetGraph dataset, Context context) { // Refuse
- // to
- // accept
- // algebra
- // expressions
- // directly.
- return false;
- }
-
- @Override
- public Plan create(Op op, DatasetGraph dataset, Binding inputBinding,
- Context context) { // Should not be called because acceept/Op is
- // false
- throw new ARQInternalErrorException(this.getClass().getSimpleName()
- + ": factory called directly with an algebra expression");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/query/rewriter/OpRewriter.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/query/rewriter/OpRewriter.java b/jena-security/src/main/java/org/apache/jena/security/query/rewriter/OpRewriter.java
deleted file mode 100644
index 1cd59c1..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/query/rewriter/OpRewriter.java
+++ /dev/null
@@ -1,592 +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.query.rewriter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.SecurityEvaluator.SecTriple;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.algebra.OpVisitor ;
-import org.apache.jena.sparql.algebra.op.* ;
-import org.apache.jena.sparql.core.BasicPattern ;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class rewrites the query by examining each operation in the algebra
- * returned by the Jena SPARQL parser.
- * <p>
- * This implementation inserts security evaluator checks where necessary.
- * </p>
- */
-public class OpRewriter implements OpVisitor
-{
- private static Logger LOG = LoggerFactory.getLogger(OpRewriter.class);
- private OpSequence result;
- private final SecNode graphIRI;
- private final SecurityEvaluator securityEvaluator;
- // if true the restricted data are silently ignored.
- // default false
- private final boolean silentFail;
-
- /**
- * Constructor
- * @param securityEvaluator The security evaluator to use
- * @param graphIRI The IRI for the default graph.
- */
- public OpRewriter( final SecurityEvaluator securityEvaluator,
- final SecNode graphIRI )
- {
- this.securityEvaluator = securityEvaluator;
- this.graphIRI = graphIRI;
- this.silentFail = false;
- reset();
- }
-
- /**
- * Constructor
- * @param securityEvaluator The security evaluator to use
- * @param graphIRI The IRI for the default graph.
- */
- public OpRewriter( final SecurityEvaluator securityEvaluator,
- final String graphIRI )
- {
- this(securityEvaluator, new SecNode(SecNode.Type.URI, graphIRI));
- }
-
- /**
- * Add the operation to the result.
- * @param op the operation to add.
- */
- private void addOp( final Op op )
- {
- result.add(op);
- }
-
- /**
- * Get the result of the rewrite.
- * @return the resulting operator
- */
- public Op getResult()
- {
- if (result.size() == 0)
- {
- return OpNull.create();
- }
- if (result.size() == 1)
- {
- return result.get(0);
- }
- return result;
-
- }
-
- /**
- * Register variables.
- *
- * Registers n as a variable if it is one.
- *
- * @param n the node to check
- * @param variables the list of variable nodes
- * @Return n for chaining.
- */
- private Node registerVariables( final Node n, final List<Node> variables )
- {
- if (n.isVariable() && !variables.contains(n))
- {
- variables.add(n);
- }
- return n;
- }
-
- /**
- * Reset the rewriter to the initial state.
- * @return this rewriter for chaining.
- */
- public OpRewriter reset()
- {
- result = OpSequence.create();
- return this;
- }
-
- /**
- * Register all the variables in the triple.
- * @param t the triple to register.
- * @param variables The list of variables.
- * @return t for chaining
- */
- private Triple registerBGPTriple( final Triple t,
- final List<Node> variables )
- {
- registerVariables(t.getSubject(), variables);
- registerVariables(t.getPredicate(), variables);
- registerVariables(t.getObject(), variables);
- return t;
- }
-
- /**
- * Rewrites the subop of op1 and returns the result.
- *
- * @param op1
- * @return the rewritten op.
- */
- private Op rewriteOp1( final Op1 op1 )
- {
- final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
- op1.getSubOp().visit(rewriter);
- return rewriter.getResult();
- }
-
- /**
- * rewrites the left and right parts of the op2 the left part is
- * returned the right part is placed in the rewriter
- *
- * @param op2
- * @param rewriter
- * @return the rewritten op.
- */
- private Op rewriteOp2( final Op2 op2, final OpRewriter rewriter )
- {
- op2.getLeft().visit(rewriter.reset());
- final Op left = rewriter.getResult();
- op2.getRight().visit(rewriter.reset());
- return left;
- }
-
- /**
- * rewrite source to dest and returns dest
- *
- * @param source
- * @param dest
- * @return the rewritten op.
- */
- private OpN rewriteOpN( final OpN source, final OpN dest )
- {
- final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
- for (final Op o : source.getElements())
- {
- o.visit(rewriter.reset());
- dest.add(rewriter.getResult());
- }
- return dest;
- }
-
- /**
- * rewrites the subop of assign.
- */
- @Override
- public void visit( final OpAssign opAssign )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpAssign"); }
- addOp(OpAssign.assign(rewriteOp1(opAssign), opAssign.getVarExprList()));
- }
-
- @Override
- public void visit( final OpBGP opBGP )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpBGP"); }
- Object principal = securityEvaluator.getPrincipal();
- if (!securityEvaluator.evaluate(principal, Action.Read, graphIRI))
- {
- if (silentFail)
- {
- return;
- }
- else
- {
- throw new AccessDeniedException(graphIRI, Action.Read);
- }
- }
-
- // if the user can read any triple just add the opBGP
- if (securityEvaluator.evaluate(principal, Action.Read, graphIRI, SecTriple.ANY))
- {
- addOp(opBGP);
- }
- else
- {
- // add security filtering to the resulting triples
- final List<Triple> newBGP = new ArrayList<Triple>();
- final List<Node> variables = new ArrayList<Node>();
- // register all variables
- for (final Triple t : opBGP.getPattern().getList())
- {
- newBGP.add(registerBGPTriple(t, variables));
- }
- // create the security function.
- final SecuredFunction secFunc = new SecuredFunction(graphIRI,
- securityEvaluator, variables, newBGP);
- // create the filter
- Op filter = OpFilter.filter(secFunc, new OpBGP(BasicPattern.wrap(newBGP)));
- // add the filter
- addOp(filter);
- }
- }
-
- /**
- * Rewrite left and right
- */
- @Override
- public void visit( final OpConditional opCondition )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpConditional"); }
- final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
- addOp(new OpConditional(rewriteOp2(opCondition, rewriter),
- rewriter.getResult()));
- }
-
- /**
- * returns the dsNames
- */
- @Override
- public void visit( final OpDatasetNames dsNames )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpDatasetName"); }
- addOp(dsNames);
- }
-
- /**
- * Rewrite left and right
- */
- @Override
- public void visit( final OpDiff opDiff )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpDiff"); }
- final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
- addOp(OpDiff.create(rewriteOp2(opDiff, rewriter), rewriter.getResult()));
- }
-
- /**
- * Rewrite sequence elements
- */
- @Override
- public void visit( final OpDisjunction opDisjunction )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpDisjunction"); }
- addOp(rewriteOpN(opDisjunction, OpDisjunction.create()));
- }
-
- /**
- * rewrites the subop of distinct
- */
- @Override
- public void visit( final OpDistinct opDistinct )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpDistinct"); }
- addOp(new OpDistinct(rewriteOp1(opDistinct)));
- }
-
- /**
- * Returns the Ext
- */
- @Override
- public void visit( final OpExt opExt )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpExt"); }
- addOp(opExt);
- }
-
- /**
- * rewrites the subop of extend.
- */
- @Override
- public void visit( final OpExtend opExtend )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpExtend"); }
- addOp(OpExtend.extend(rewriteOp1(opExtend), opExtend.getVarExprList()));
- }
-
- /**
- * rewrites the subop of filter.
- */
- @Override
- public void visit( final OpFilter opFilter )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpFilter"); }
- addOp(OpFilter.filter(opFilter.getExprs(), rewriteOp1(opFilter)));
- }
-
- /**
- * rewrites the subop of graph.
- */
- @Override
- public void visit( final OpGraph opGraph )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpGraph"); }
- final OpRewriter rewriter = new OpRewriter(securityEvaluator,
- SecuredItemImpl.convert(opGraph.getNode()));
- opGraph.getSubOp().visit(rewriter);
- addOp(new OpGraph(opGraph.getNode(), rewriter.getResult()));
- }
-
- /**
- * rewrites the subop of group.
- */
- @Override
- public void visit( final OpGroup opGroup )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpGroup"); }
- addOp(new OpGroup(rewriteOp1(opGroup), opGroup.getGroupVars(),
- opGroup.getAggregators()));
- }
-
- /**
- * Parses the joins and recursively calls the left and right parts
- */
- @Override
- public void visit( final OpJoin opJoin )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpJoin"); }
- final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
- addOp(OpJoin.create(rewriteOp2(opJoin, rewriter), rewriter.getResult()));
- }
-
- /**
- * returns the label
- */
- @Override
- public void visit( final OpLabel opLabel )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpLabel"); }
- addOp(opLabel);
- }
-
- /**
- * Parses the joins and recursively calls the left and right parts
- */
- @Override
- public void visit( final OpLeftJoin opLeftJoin )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpLeftJoin"); }
- final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
- addOp(OpLeftJoin.create(rewriteOp2(opLeftJoin, rewriter),
- rewriter.getResult(), opLeftJoin.getExprs()));
- }
-
- /**
- * rewrites the subop of list.
- */
- @Override
- public void visit( final OpList opList )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpList"); }
- addOp(new OpList(rewriteOp1(opList)));
- }
-
- /**
- * Rewrite left and right
- */
- @Override
- public void visit( final OpMinus opMinus )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpMinus"); }
- final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
- addOp(OpMinus.create(rewriteOp2(opMinus, rewriter),
- rewriter.getResult()));
- }
-
- /**
- * returns the null
- */
- @Override
- public void visit( final OpNull opNull )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpNull"); }
- addOp(opNull);
- }
-
- /**
- * rewrites the subop of order.
- */
- @Override
- public void visit( final OpOrder opOrder )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpOrder"); }
- addOp(new OpOrder(rewriteOp1(opOrder), opOrder.getConditions()));
- }
-
- /**
- * Returns the path
- */
- @Override
- public void visit( final OpPath opPath )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpPath"); }
- addOp(opPath);
- }
-
- /**
- * rewrites the subop of proc.
- */
- @Override
- public void visit( final OpProcedure opProc )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpProc"); }
- if (opProc.getProcId() != null)
- {
- addOp(new OpProcedure(opProc.getProcId(), opProc.getArgs(),
- rewriteOp1(opProc)));
- }
- else
- {
- addOp(new OpProcedure(opProc.getURI(), opProc.getArgs(),
- rewriteOp1(opProc)));
- }
- }
-
- /**
- * rewrites the subop of project.
- */
- @Override
- public void visit( final OpProject opProject )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpProject"); }
- addOp(new OpProject(rewriteOp1(opProject), opProject.getVars()));
- }
-
- /**
- * rewrites the subop of propFunc.
- */
- @Override
- public void visit( final OpPropFunc opPropFunc )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpPropFunc"); }
- addOp(new OpPropFunc(opPropFunc.getProperty(),
- opPropFunc.getSubjectArgs(), opPropFunc.getObjectArgs(),
- rewriteOp1(opPropFunc)));
- }
-
- /**
- * Returns the quad
- */
- @Override
- public void visit( final OpQuad opQuad )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpQuad"); }
- addOp(opQuad);
- }
-
- /**
- * Returns the quadpattern
- */
- @Override
- public void visit( final OpQuadPattern quadPattern )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpQuadPattern"); }
- addOp(quadPattern);
- }
-
- /**
- * rewrites the subop of reduced.
- */
- @Override
- public void visit( final OpReduced opReduced )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpReduced"); }
- addOp(OpReduced.create(rewriteOp1(opReduced)));
- }
-
- /**
- * Rewrite sequence elements
- */
- @Override
- public void visit( final OpSequence opSequence )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpSequence"); }
- addOp(rewriteOpN(opSequence, OpSequence.create()));
- }
-
- /**
- * returns the service
- */
- @Override
- public void visit( final OpService opService )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting opService"); }
- addOp(opService);
- }
-
- /**
- * rewrites the subop of slice
- *
- * This also handles the limit case
- */
- @Override
- public void visit( final OpSlice opSlice )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpSlice"); }
- addOp(opSlice);
- }
-
- /**
- * returns the table
- */
- @Override
- public void visit( final OpTable opTable )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpTable"); }
- addOp(opTable);
- }
-
- /**
- * rewrites the subop of top.
- */
- @Override
- public void visit( final OpTopN opTop )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpTop"); }
- addOp(new OpTopN(rewriteOp1(opTop), opTop.getLimit(),
- opTop.getConditions()));
- }
-
- /**
- * Converts to BGP
- */
- @Override
- public void visit( final OpTriple opTriple )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpTriple"); }
- visit(opTriple.asBGP());
- }
-
- /**
- * Rewrite left and right
- */
- @Override
- public void visit( final OpUnion opUnion )
- {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpUnion"); }
- final OpRewriter rewriter = new OpRewriter(securityEvaluator, graphIRI);
- addOp(OpUnion.create(rewriteOp2(opUnion, rewriter),
- rewriter.getResult()));
- }
-
- @Override
- public void visit(OpQuadBlock quadBlock) {
- if (LOG.isDebugEnabled()) { LOG.debug( "Starting visiting OpQuadBlock"); }
- addOp(quadBlock);
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/query/rewriter/SecuredFunction.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/query/rewriter/SecuredFunction.java b/jena-security/src/main/java/org/apache/jena/security/query/rewriter/SecuredFunction.java
deleted file mode 100644
index b765061..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/query/rewriter/SecuredFunction.java
+++ /dev/null
@@ -1,138 +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.query.rewriter;
-
-import java.util.List;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.SecurityEvaluator.SecTriple;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.sparql.core.Var ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.expr.* ;
-import org.apache.jena.sparql.function.FunctionEnv ;
-import org.apache.jena.sparql.graph.NodeTransform ;
-
-public class SecuredFunction extends ExprFunctionN
-{
- private final SecurityEvaluator securityEvaluator;
- private final List<Node> variables;
- private final List<Triple> bgp;
- private final SecNode graphIRI;
-
- private static ExprList createArgs( List<Node> variables )
- {
- ExprList retval = new ExprList();
- for (Node n : variables )
- {
- retval.add( new ExprVar( n ));
- }
- return retval;
- }
-
- public SecuredFunction( final SecNode graphIRI,
- final SecurityEvaluator securityEvaluator,
- final List<Node> variables, final List<Triple> bgp )
- {
- super(String.format("<java:%s>", SecuredFunction.class.getName() ), createArgs( variables));
- //,
- // new ElementTriplesBlock( BasicPattern.wrap(bgp) ),
- // new OpBGP( BasicPattern.wrap(bgp) )
- // );
- this.securityEvaluator = securityEvaluator;
- this.variables = variables;
- this.bgp = bgp;
- this.graphIRI = graphIRI;
- }
-
- private boolean checkAccess( Binding values )
- {
- Object principal = securityEvaluator.getPrincipal();
- for (final Triple t : bgp)
- {
- final SecTriple secT = createSecTriple(t, values);
- if (!securityEvaluator.evaluate(principal, Action.Read, graphIRI, secT))
- {
- return false;
- }
- }
- return true;
- }
-
- private SecTriple createSecTriple( final Triple t, final Binding values )
- {
- int idx = variables.indexOf(t.getSubject());
-
- final SecNode s = SecuredItemImpl.convert(idx ==-1 ? t.getSubject()
- : values.get(Var.alloc( variables.get(idx))));
-
- idx = variables.indexOf(t.getPredicate());
- final SecNode p = SecuredItemImpl.convert(idx == -1 ? t
- .getPredicate()
- : values.get(Var.alloc( variables.get(idx))));
- idx = variables.indexOf(t.getObject());
- final SecNode o = SecuredItemImpl.convert(idx == -1 ? t.getObject()
- : values.get(Var.alloc( variables.get(idx))));
- return new SecTriple(s, p, o);
- }
-
-
- @Override
- public Expr copySubstitute( Binding binding )
- {
- return this;
- }
-
- @Override
- public Expr applyNodeTransform( NodeTransform transform )
- {
- return this;
- }
-
- @Override
- public void visit( ExprVisitor visitor )
- {
- visitor.visit( this );
- }
-
- @Override
- public NodeValue eval( List<NodeValue> args )
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Expr copy( ExprList newArgs )
- {
- return this;
- }
-
- @Override
- protected NodeValue evalSpecial( Binding binding, FunctionEnv env )
- {
- return NodeValue.booleanReturn( checkAccess( binding ));
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/utils/ContainerFilter.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/utils/ContainerFilter.java b/jena-security/src/main/java/org/apache/jena/security/utils/ContainerFilter.java
deleted file mode 100644
index d49792f..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/utils/ContainerFilter.java
+++ /dev/null
@@ -1,48 +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.utils;
-
-import org.apache.jena.rdf.model.Property ;
-import org.apache.jena.rdf.model.Statement ;
-import org.apache.jena.util.iterator.Filter ;
-import org.apache.jena.vocabulary.RDF ;
-
-public class ContainerFilter extends Filter<Statement>
-{
-
- @Override
- public boolean accept( final Statement o )
- {
- final Property p = o.getPredicate();
- if (p.getNameSpace().equals(RDF.getURI())
- && p.getLocalName().startsWith("_"))
- {
- try
- {
- Integer.parseInt(p.getLocalName().substring(1));
- return true;
- }
- catch (final NumberFormatException e)
- {
- // acceptable;
- }
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/utils/PermStatementFilter.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/utils/PermStatementFilter.java b/jena-security/src/main/java/org/apache/jena/security/utils/PermStatementFilter.java
deleted file mode 100644
index b2217a1..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/utils/PermStatementFilter.java
+++ /dev/null
@@ -1,164 +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.utils;
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.apache.jena.rdf.model.Statement ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.impl.SecuredItem;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.util.iterator.Filter ;
-
-/**
- * A filter for to filter ExtendedIterators on Statements.
- * This filter removes any triple that the user can not perform all
- * the actions on.
- */
-public class PermStatementFilter extends Filter<Statement>
-{
- private final SecurityEvaluator evaluator;
- private final SecNode modelNode;
- private final Set<Action> actions;
- private final Object principal;
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param action
- * The action the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- */
- public PermStatementFilter( final Action action,
- final SecuredItem securedItem )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(new Action[] { action });
- this.evaluator = securedItem.getSecurityEvaluator();
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param action
- * The action the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- * @param evaluator
- * The security evaluator to evaluate the security queries.
- */
- public PermStatementFilter( final Action action,
- final SecuredItem securedItem, final SecurityEvaluator evaluator )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(new Action[] { action });
- this.evaluator = evaluator;
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param actions
- * The actions the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- */
- public PermStatementFilter( final Action[] actions,
- final SecuredItem securedItem )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(actions);
- this.evaluator = securedItem.getSecurityEvaluator();
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param actions
- * The actions the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- * @param evaluator
- * The security evaluator to evaluate the security queries.
- */
- public PermStatementFilter( final Action[] actions,
- final SecuredItem securedItem, final SecurityEvaluator evaluator )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(actions);
- this.evaluator = evaluator;
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param actions
- * The actions the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- */
- public PermStatementFilter( final Collection<Action> actions,
- final SecuredItem securedItem )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(actions);
- this.evaluator = securedItem.getSecurityEvaluator();
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param actions
- * The actions the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- * @param evaluator
- * The security evaluator to evaluate the security queries.
- */
- public PermStatementFilter( final Collection<Action> actions,
- final SecuredItem securedItem, final SecurityEvaluator evaluator )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(actions);
- this.evaluator = evaluator;
- this.principal = evaluator.getPrincipal();
- }
-
- @Override
- public boolean accept( final Statement s )
- {
- return evaluator.evaluateAny(principal, actions, modelNode,
- SecuredItemImpl.convert(s.asTriple()));
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/utils/PermTripleFilter.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/utils/PermTripleFilter.java b/jena-security/src/main/java/org/apache/jena/security/utils/PermTripleFilter.java
deleted file mode 100644
index 5f6cfa1..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/utils/PermTripleFilter.java
+++ /dev/null
@@ -1,163 +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.utils;
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.impl.SecuredItem;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.util.iterator.Filter ;
-
-/**
- * A filter for to filter ExtendedIterators on Triples.
- * This filter removes any triple that the user can not perform all
- * the actions on.
- */
-public class PermTripleFilter extends Filter<Triple>
-{
- private final SecurityEvaluator evaluator;
- private final SecNode modelNode;
- private final Set<Action> actions;
- private final Object principal;
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param action
- * The action the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- */
- public PermTripleFilter( final Action action, final SecuredItem securedItem )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(new Action[] { action });
- this.evaluator = securedItem.getSecurityEvaluator();
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param action
- * The action the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- * @param evaluator
- * The security evaluator to evaluate the security queries.
- */
- public PermTripleFilter( final Action action,
- final SecuredItem securedItem, final SecurityEvaluator evaluator )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(new Action[] { action });
- this.evaluator = evaluator;
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param actions
- * The actions the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- */
- public PermTripleFilter( final Action[] actions,
- final SecuredItem securedItem )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(actions);
- this.evaluator = securedItem.getSecurityEvaluator();
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param actions
- * The actions the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- * @param evaluator
- * The security evaluator to evaluate the security queries.
- */
- public PermTripleFilter( final Action[] actions,
- final SecuredItem securedItem, final SecurityEvaluator evaluator )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(actions);
- this.evaluator = evaluator;
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param actions
- * The actions the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- */
- public PermTripleFilter( final Collection<Action> actions,
- final SecuredItem securedItem )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(actions);
- this.evaluator = securedItem.getSecurityEvaluator();
- this.principal = evaluator.getPrincipal();
- }
-
- /**
- * Creates a filter that requires that the user have all the permissions
- * listed in the actions parameter
- *
- * @param actions
- * The actions the user must be permitted to perform.
- * @param securedItem
- * The secured item that secures this iterator.
- * @param evaluator
- * The security evaluator to evaluate the security queries.
- */
- public PermTripleFilter( final Collection<Action> actions,
- final SecuredItem securedItem, final SecurityEvaluator evaluator )
- {
- this.modelNode = securedItem.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(actions);
- this.evaluator = evaluator;
- this.principal = evaluator.getPrincipal();
- }
-
- @Override
- public boolean accept( final Triple t )
- {
- return evaluator.evaluateAny(principal, actions, modelNode,
- SecuredItemImpl.convert(t));
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/utils/RDFListIterator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/utils/RDFListIterator.java b/jena-security/src/main/java/org/apache/jena/security/utils/RDFListIterator.java
deleted file mode 100644
index 9c86b95..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/utils/RDFListIterator.java
+++ /dev/null
@@ -1,79 +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.utils;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import org.apache.jena.rdf.model.RDFList ;
-import org.apache.jena.vocabulary.RDF ;
-
-public class RDFListIterator implements Iterator<RDFList>
-{
- private RDFList current;
- private Boolean found;
-
- public RDFListIterator( final RDFList start )
- {
- this.current = start;
- }
-
- private boolean endOfList()
- {
- return current.equals(RDF.nil);
- }
-
- @Override
- public boolean hasNext()
- {
- if ((found == null) && !endOfList())
- {
- found = !endOfList();
- }
- return found == null ? false : found;
- }
-
- private void incrementCurrent()
- {
- if (!endOfList())
- {
- current = current.getRequiredProperty(RDF.rest).getResource()
- .as(RDFList.class);
- }
- }
-
- @Override
- public RDFList next()
- {
- if (hasNext())
- {
- found = null;
- final RDFList retval = current;
- incrementCurrent();
- return retval;
- }
- throw new NoSuchElementException();
- }
-
- @Override
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/utils/RDFListSecFilter.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/utils/RDFListSecFilter.java b/jena-security/src/main/java/org/apache/jena/security/utils/RDFListSecFilter.java
deleted file mode 100644
index 3127c4f..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/utils/RDFListSecFilter.java
+++ /dev/null
@@ -1,58 +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.utils;
-
-import java.util.Set;
-
-import org.apache.jena.rdf.model.RDFList ;
-import org.apache.jena.rdf.model.Statement ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.impl.SecuredItem;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.util.iterator.Filter ;
-import org.apache.jena.vocabulary.RDF ;
-
-public class RDFListSecFilter<T extends RDFList> extends Filter<T>
-{
- private final SecuredItem securedItem;
- private final Set<Action> perms;
- private final Object principal;
-
- public RDFListSecFilter( final SecuredItem securedItem, final Action perm )
- {
- this(securedItem, SecurityEvaluator.Util.asSet(new Action[] { perm }));
- }
-
- public RDFListSecFilter( final SecuredItem securedItem,
- final Set<Action> perms )
- {
- this.securedItem = securedItem;
- this.perms = perms;
- this.principal = securedItem.getSecurityEvaluator().getPrincipal();
- }
-
- @Override
- public boolean accept( final RDFList o )
- {
- final Statement s = o.getRequiredProperty(RDF.first);
- return securedItem.getSecurityEvaluator().evaluate(principal, perms,
- securedItem.getModelNode(),
- SecuredItemImpl.convert(s.asTriple()));
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/overview.html
----------------------------------------------------------------------
diff --git a/jena-security/src/main/overview.html b/jena-security/src/main/overview.html
deleted file mode 100644
index 561c53a..0000000
--- a/jena-security/src/main/overview.html
+++ /dev/null
@@ -1,83 +0,0 @@
-<html>
-<body>
- <p>JenaSecurity is a SecurityEvaluator interface and a set of
- dynamic proxies that apply that interface to Jena Graphs, Models, and
- associated methods and classes.</p>
- <p>
- The SecurityEvaluator class must be implemented. This class provides
- the interface to the authentication results (e.g.
- <code>getPrincipal()</code>
- ) and the authorization system.
- </p>
- <p>
- <ul>
- <li>Create a SecuredGraph by calling <code>Factory.getInstance(
- SecurityEvaluator, String, Graph );</code>
- </li>
- <li>Create a SecuredModel by calling <code>Factory.getInstance(
- SecurityEvaluator, String, Model )</code>
- </li>
- <li>It is not recommended that you use the Jena <code>ModelFactory.createModelForGraph(
- SecuredGraph )</code> See Differences Between Graph and Model below for
- reasons.
- </li>
- </ul>
- </p>
- <p>
- <ul>
- <li>See SecurityEvaluator documentation for description of
- cascading security checks</li>
- <li>Secured methods are annotated with: @sec.graph for
- permissions required on the graph to execute the method.
- @sec.triple for permissions required on the associated triples
- (if any) to execute the method.</li>
- <li>It is possible to implement a SecurityEvaluator that does not
- enforce security at the triple level. See SecurityEvaluator
- documentation for details</li>
- </ul>
- </p>
- <h2>
- Differences Between
- <code>Graph</code>
- and
- <code>Model</code>
- </h2>
- <p>
- The Graph interface does not have the concept of "update". Thus all
- updates are implemented as a delete and an insert. The Model interface
- does have the concept of update as evidenced by the
- <code>replace()</code>
- method in the
- <code>RDFList</code>
- class. This difference means that a
- <code>Model</code>
- created by calling
- <code>ModelFactory.createModelForGraph( SecuredGraph )</code>
- will yield a model that evaluates
- <code>Update</code>
- actions differently from one created with
- <Code>Factory.getInstance( SecurityEvaluator, modelIRI, model)</Code>
- .
- <ul>
- <li>Models created by the Jena ModelFactory will require that the
- user have both delete and create permissions on the underlying graph
- to perform the update. And will delete the existing triple before
- attempting to create the new one. Since the graph interface does not
- have visibility to the model's request for update these are, to the
- graph, separate events. It is possible that the delete may succeed
- while the create fails.</li>
- <li>Models created by the JenaSecurity Factory will require that
- the user have update permissions on the underlying model to perform
- the update. As long as the user has the update permission on the
- graph, and the triple where required, the update is performed as a
- single event.</li>
- </ul>
- This is the well documented case of differences between the two secured
- model creation methods. For this reason it is recommended that the
- model be created with the
- <code>Factory.getInsance()</code>
- method.
- </p>
-
-</body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/test/java/org/apache/jena/security/EqualityTester.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/EqualityTester.java b/jena-security/src/test/java/org/apache/jena/security/EqualityTester.java
deleted file mode 100644
index 4b1d882..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/MockPrefixMapping.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/MockPrefixMapping.java b/jena-security/src/test/java/org/apache/jena/security/MockPrefixMapping.java
deleted file mode 100644
index 5db2402..0000000
--- a/jena-security/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/b712fb28/jena-security/src/test/java/org/apache/jena/security/MockSecurityEvaluator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/test/java/org/apache/jena/security/MockSecurityEvaluator.java b/jena-security/src/test/java/org/apache/jena/security/MockSecurityEvaluator.java
deleted file mode 100644
index 797bdf0..0000000
--- a/jena-security/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);
- }
-
-}
[07/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRDFListImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRDFListImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRDFListImpl.java
deleted file mode 100644
index 86c4251..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRDFListImpl.java
+++ /dev/null
@@ -1,1058 +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.model.impl;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.AccessDeniedException;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.security.impl.SecuredItemInvoker;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredRDFList;
-import org.apache.jena.security.model.SecuredRDFNode;
-import org.apache.jena.security.utils.RDFListIterator;
-import org.apache.jena.security.utils.RDFListSecFilter;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.Map1 ;
-import org.apache.jena.util.iterator.WrappedIterator ;
-import org.apache.jena.vocabulary.RDF ;
-
-public class SecuredRDFListImpl extends SecuredResourceImpl implements
- SecuredRDFList
-{
- // called plain node but still returns a secured node
- private class PlainNodeMap implements Map1<RDFList, RDFNode>
- {
-
- @Override
- public RDFNode map1( final RDFList o )
- {
- return SecuredRDFNodeImpl.getInstance(getModel(), o
- .getRequiredProperty(listFirst()).getObject());
- }
-
- }
-
- private class SecuredListMap implements Map1<RDFList, SecuredRDFList>
- {
-
- @Override
- public SecuredRDFList map1( final RDFList o )
- {
- return SecuredRDFListImpl.getInstance(getModel(), o);
- }
-
- }
-
- private class SecuredNodeMap implements Map1<RDFList, SecuredRDFNode>
- {
-
- private Property p;
- public SecuredNodeMap(Property p)
- {
- this.p=p;
- }
-
- @Override
- public SecuredRDFNode map1( final RDFList o )
- {
- return SecuredRDFNodeImpl.getInstance(getModel(), o
- .getRequiredProperty(p).getObject());
- }
-
- }
-
- /*
- * private class SecuredRDFListIterator implements Iterator<SecuredRDFList>
- * {
- * private SecuredRDFList current;
- * private Boolean found;
- * private final Set<Action> restrictions;
- *
- * private SecuredRDFListIterator( final Action restriction )
- * {
- * this(SecurityEvaluator.Util.asSet(new Action[] { restriction }));
- * }
- *
- * private SecuredRDFListIterator( final Set<Action> restrictions )
- * {
- * this.current = SecuredRDFListImpl.this.holder.getSecuredItem();
- * this.restrictions = restrictions;
- * }
- *
- * private boolean checkCandidate()
- * {
- * if (!endOfList())
- * {
- * final SecNode candidate = current.getRequiredProperty(listFirst())
- * .getObject().asNode();
- * return getSecurityEvaluator().evaluate(
- * restrictions,
- * getModelNode(),
- * new SecurityEvaluator.SecTriple(SecuredItemImpl
- * .convert(current.asNode()), SecuredItemImpl
- * .convert(RDF.first.asNode()), SecuredItemImpl
- * .convert(candidate)));
- * }
- * return false;
- * }
- *
- * private boolean endOfList()
- * {
- * return current.equals(listNil());
- * }
- *
- * @Override
- * public boolean hasNext()
- * {
- * if ((found == null) && !endOfList())
- * {
- * found = checkCandidate();
- * while (!found && !endOfList())
- * {
- * incrementCurrent();
- * found = checkCandidate();
- * }
- * }
- * return found == null ? false : found;
- * }
- *
- * private void incrementCurrent()
- * {
- * if (!endOfList())
- * {
- * current = (SecuredRDFList) current
- * .getRequiredProperty(listRest()).getResource()
- * .as(RDFList.class);
- * }
- * }
- *
- * @Override
- * public SecuredRDFList next()
- * {
- * if (hasNext())
- * {
- * found = null;
- * final SecuredRDFList retval = current;
- * incrementCurrent();
- * return retval;
- * }
- * throw new NoSuchElementException();
- * }
- *
- * @Override
- * public void remove()
- * {
- * throw new UnsupportedOperationException();
- * }
- *
- * }
- */
- /**
- * Get an instance of SecuredProperty
- *
- * @param securedModel
- * the Secured Model to use.
- * @param rdfList
- * The rdfList to secure
- * @return The SecuredProperty
- */
- public static <T extends RDFList> SecuredRDFList getInstance( final SecuredModel securedModel,
- final T rdfList )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (rdfList == null)
- {
- throw new IllegalArgumentException("RDFList may not be null");
- }
-
- // check that property has a securedModel.
- RDFList goodList = rdfList;
- if (goodList.getModel() == null)
- {
- goodList = securedModel.createList(rdfList.asJavaList().iterator());
- }
-
- final ItemHolder<RDFList, SecuredRDFList> holder = new ItemHolder<RDFList, SecuredRDFList>(
- goodList);
- final SecuredRDFListImpl checker = new SecuredRDFListImpl(securedModel,
- holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (goodList instanceof SecuredRDFList)
- {
- if (checker.isEquivalent((SecuredRDFList) goodList))
- {
- return (SecuredRDFList) goodList;
- }
- }
- return holder.setSecuredItem(new SecuredItemInvoker(rdfList.getClass(),
- checker));
- }
-
- /** Error message if validity check fails */
- protected String m_errorMsg = null;
-
- /** Pointer to the node that is the tail of the list */
- protected RDFList m_tail = null;
-
- /** The URI for the 'first' property in this list */
- protected Property m_listFirst = RDF.first;
-
- /** The URI for the 'rest' property in this list */
- protected Property m_listRest = RDF.rest;
-
- /** The URI for the 'nil' Resource in this list */
- protected Resource m_listNil = RDF.nil;
-
- /** The URI for the rdf:type of this list */
- protected Resource m_listType = RDF.List;
-
- private final ItemHolder<RDFList, SecuredRDFList> holder;
-
- protected SecuredRDFListImpl( final SecuredModel securedModel,
- final ItemHolder<RDFList, SecuredRDFList> holder )
- {
- super(securedModel, holder);
- this.holder = holder;
- }
-
- @Override
- public void add( final RDFNode value )
- {
- checkUpdate();
- checkCreateNewList(value, listNil());
- holder.getBaseItem().add(value);
- }
-
- @Override
- public SecuredRDFList append( final Iterator<? extends RDFNode> nodes )
- {
- SecuredRDFList copy = copy();
- if (nodes.hasNext())
- {
- if (((RDFList)copy.getBaseItem()).size()>0)
-// if (copy.size() > 0)
- {
- copy.concatenate(copy.getModel().createList(nodes));
- }
- else
- {
- copy = copy.getModel().createList(nodes);
- }
- }
- return copy;
- }
-
- @Override
- public RDFList append( final RDFList list )
- {
- if (holder.getBaseItem().isEmpty())
- {
- return list.size() == 0 ? ModelFactory.createDefaultModel()
- .createList() : list.copy();
- }
- else
- {
- final RDFList copy = copy();
- if (list.size() > 0)
- {
- copy.concatenate(list.copy());
- }
- return copy;
- }
- }
-
- @Override
- public void apply( final ApplyFn fn )
- {
- // iterator() checks Read
- final ExtendedIterator<RDFNode> i = iterator();
- try
- {
- while (i.hasNext())
- {
- fn.apply(i.next());
- }
- }
- finally
- {
- i.close();
- }
- }
-
- @Override
- public void apply( final Set<Action> perms, final ApplyFn fn )
- {
- // iterator() checks Read
- final ExtendedIterator<RDFNode> i = iterator(perms);
- try
- {
- while (i.hasNext())
- {
- fn.apply(i.next());
- }
- }
- finally
- {
- i.close();
- }
- }
-
- @Override
- public List<RDFNode> asJavaList()
- {
- // iterator() checks Read
- return iterator().toList();
- }
-
- /**
- * Removes val from underlying list.
- *
- * @param val
- * @return the modified RDFList.
- */
- private RDFList baseRemove( final RDFList val )
- {
-
- RDFList prev = null;
- RDFList cell = holder.getBaseItem();
- final boolean searching = true;
-
- while (searching && !cell.isEmpty())
- {
- if (cell.equals(val))
- {
- // found the value to be removed
- final RDFList tail = cell.getTail();
- if (prev != null)
- {
- prev.setTail(tail);
- }
-
- cell.removeProperties();
-
- // return this unless we have removed the head element
- return (prev == null) ? tail : this;
- }
- else
- {
- // not found yet
- prev = cell;
- cell = cell.getTail();
- }
- }
-
- // not found
- return this;
- }
-
- private void checkCreateNewList( final RDFNode value, final Resource tail )
- {
- checkCreate(new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(listFirst().asNode()),
- SecuredItemImpl.convert(value.asNode())));
- checkCreate(new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(listRest().asNode()),
- SecuredItemImpl.convert(tail.asNode())));
- }
-
- private Set<Statement> collectStatements( final Set<Action> actions )
- {
- final Set<Statement> stmts = new HashSet<Statement>();
- final ExtendedIterator<RDFList> iter = WrappedIterator.create(
- new RDFListIterator(holder.getBaseItem())).filterKeep(
- new RDFListSecFilter<RDFList>(this, actions));
- try
- {
- while (iter.hasNext())
- {
- stmts.addAll(iter.next().listProperties().toSet());
- }
- return stmts;
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public void concatenate( final Iterator<? extends RDFNode> nodes )
- {
- checkUpdate();
- if (holder.getBaseItem().isEmpty())
- {
- // concatenating list onto the empty list is an error
- throw new EmptyListUpdateException(
- "Tried to concatenate onto the empty list");
- }
- else
- {
- final org.apache.jena.security.SecurityEvaluator.SecNode p = SecuredItemImpl
- .convert(listFirst().asNode());
- org.apache.jena.security.SecurityEvaluator.SecTriple t = new org.apache.jena.security.SecurityEvaluator.SecTriple(
- org.apache.jena.security.SecurityEvaluator.SecNode.FUTURE,
- p, org.apache.jena.security.SecurityEvaluator.SecNode.ANY);
- if (!canCreate(t))
- {
- final List<RDFNode> list = new ArrayList<RDFNode>();
- while (nodes.hasNext())
- {
- final RDFNode n = nodes.next();
- t = new org.apache.jena.security.SecurityEvaluator.SecTriple(
- org.apache.jena.security.SecurityEvaluator.SecNode.FUTURE,
- p, SecuredItemImpl.convert(n.asNode()));
- checkCreate(t);
- list.add(n);
- }
- holder.getBaseItem().concatenate(list.iterator());
-
- }
- else
- {
- holder.getBaseItem().concatenate(nodes);
- }
- }
- }
-
- @Override
- public void concatenate( final RDFList list )
- {
- checkUpdate();
- if (holder.getBaseItem().isEmpty())
- {
- // concatenating list onto the empty list is an error
- throw new EmptyListUpdateException(
- "Tried to concatenate onto the empty list");
- }
- else
- {
- final org.apache.jena.security.SecurityEvaluator.SecNode p = SecuredItemImpl
- .convert(listFirst().asNode());
- org.apache.jena.security.SecurityEvaluator.SecTriple t = new org.apache.jena.security.SecurityEvaluator.SecTriple(
- org.apache.jena.security.SecurityEvaluator.SecNode.FUTURE,
- p, org.apache.jena.security.SecurityEvaluator.SecNode.ANY);
- if (!canCreate(t))
- {
- final ExtendedIterator<RDFNode> iter = list.iterator();
- try
- {
- while (iter.hasNext())
- {
- t = new org.apache.jena.security.SecurityEvaluator.SecTriple(
- org.apache.jena.security.SecurityEvaluator.SecNode.FUTURE,
- p, SecuredItemImpl
- .convert(iter.next().asNode()));
- checkCreate(t);
- }
- }
- finally
- {
- iter.close();
- }
- }
- holder.getBaseItem().concatenate(list);
- }
- }
-
- @Override
- public SecuredRDFList cons( final RDFNode value )
- {
- checkUpdate();
- checkCreateNewList(value, holder.getBaseItem());
- return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem()
- .cons(value));
- }
-
- @Override
- public boolean contains( final RDFNode value )
- {
- // iterator() checks Read
- final ExtendedIterator<RDFNode> iter = iterator();
- try
- {
- while (iter.hasNext())
- {
- if (value.equals(iter.next()))
- {
- return true;
- }
- }
- return false;
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public SecuredRDFList copy()
- {
- SecuredRDFList retval = null;
- if (canRead())
- {
- final ExtendedIterator<RDFNode> iter = getSecuredRDFListIterator(Action.Read)
- .mapWith( new Map1<RDFList, RDFNode>()
- {
-
- @Override
- public RDFNode map1( final RDFList o )
- {
- return o.getRequiredProperty(listFirst()).getObject();
- }
-
- });
- if (iter.hasNext())
- {
- retval = getModel().createList(iter);
- }
- else
- {
- retval = getModel().createList();
- }
- }
- else
- {
- retval = getModel().createList();
- }
- return retval;
- }
-
- @Override
- public SecuredRDFNode get( final int i )
- {
- checkRead();
- final ExtendedIterator<SecuredRDFNode> iter = getSecuredRDFListIterator(
- Action.Read).mapWith(new SecuredNodeMap(listFirst()));
- int idx = 0;
- try
- {
- while (iter.hasNext())
- {
- if (i == idx)
- {
- return iter.next();
- }
- else
- {
- idx++;
- iter.next();
- }
-
- }
- throw new ListIndexException();
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public SecuredRDFNode getHead()
- {
- checkRead();
- Statement s = holder.getBaseItem().getRequiredProperty( listFirst() );
- checkRead( s );
- return SecuredRDFNodeImpl.getInstance(getModel(), s.getObject());
- }
-
- private ExtendedIterator<RDFList> getSecuredRDFListIterator(
- final Action perm )
- {
- return WrappedIterator
- .create(new RDFListIterator(holder.getBaseItem())).filterKeep(
- new RDFListSecFilter<RDFList>(this, perm));
- }
-
- private ExtendedIterator<RDFList> getSecuredRDFListIterator(
- final Set<Action> perm )
- {
- return WrappedIterator
- .create(new RDFListIterator(holder.getBaseItem())).filterKeep(
- new RDFListSecFilter<RDFList>(this, perm));
- }
-
- @Override
- public boolean getStrict()
- {
- return holder.getBaseItem().getStrict();
- }
-
- @Override
- public SecuredRDFList getTail()
- {
- checkRead();
- Statement s = holder.getBaseItem().getRequiredProperty( listRest() );
- checkRead( s );
- return SecuredRDFListImpl.getInstance(getModel(), s.getObject().as(RDFList.class));
- }
-
- @Override
- public String getValidityErrorMessage()
- {
- checkRead();
- return holder.getBaseItem().getValidityErrorMessage();
- }
-
- @Override
- public int indexOf( final RDFNode value )
- {
- checkRead();
- final ExtendedIterator<SecuredRDFNode> iter = getSecuredRDFListIterator(
- Action.Read).mapWith(new SecuredNodeMap(listFirst()));
- try
- {
- int retval = 0;
- while (iter.hasNext())
- {
- if (value.equals(iter.next()))
- {
- return retval;
- }
- else
- {
- retval++;
- }
- }
- return -1;
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public int indexOf( final RDFNode value, final int start )
- {
- checkRead();
- final ExtendedIterator<SecuredRDFNode> iter = getSecuredRDFListIterator(
- Action.Read).mapWith(new SecuredNodeMap(listFirst()));
- try
- {
- int retval = 0;
- while (iter.hasNext() && (retval < start))
- {
- iter.next();
- retval++;
- }
- while (iter.hasNext())
- {
- if (value.equals(iter.next()))
- {
- return retval;
- }
- else
- {
- retval++;
- }
- }
- return -1;
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public boolean isEmpty()
- {
- checkRead();
- final ExtendedIterator<RDFNode> iter = iterator();
- try
- {
- return !iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public boolean isValid()
- {
- checkRead();
- return holder.getBaseItem().isValid();
- }
-
- @Override
- public ExtendedIterator<RDFNode> iterator()
- {
- checkRead();
- return getSecuredRDFListIterator(Action.Read).mapWith(
- new PlainNodeMap());
-
- }
-
- @Override
- public ExtendedIterator<RDFNode> iterator( final Set<Action> constraints )
- {
- checkRead();
- final Set<Action> req = new HashSet<Action>(constraints);
- req.add(Action.Read);
- return getSecuredRDFListIterator(req).mapWith(new PlainNodeMap());
-
- }
-
- public Class<? extends RDFList> listAbstractionClass()
- {
- return RDFList.class;
- }
-
- public Property listFirst()
- {
- return m_listFirst;
- }
-
- public Resource listNil()
- {
- return m_listNil;
- }
-
- public Property listRest()
- {
- return m_listRest;
- }
-
- public Resource listType()
- {
- return m_listType;
- }
-
- @Override
- public <T> ExtendedIterator<T> mapWith( final Map1<RDFNode, T> fn )
- {
- return iterator().mapWith(fn);
- }
-
- @Override
- public Object reduce( final ReduceFn fn, final Object initial )
- {
- Object acc = initial;
-
- for (final Iterator<RDFNode> i = iterator(); i.hasNext();)
- {
- acc = fn.reduce(i.next(), acc);
- }
-
- return acc;
- }
-
- @Override
- public Object reduce( final Set<Action> requiredActions, final ReduceFn fn,
- final Object initial ) throws AccessDeniedException,
- EmptyListException, ListIndexException, InvalidListException
- {
- Object acc = initial;
- final Set<Action> perms = new HashSet<Action>(requiredActions);
- perms.add(Action.Read);
- for (final Iterator<RDFNode> i = iterator(perms); i.hasNext();)
- {
- acc = fn.reduce(i.next(), acc);
- }
-
- return acc;
- }
-
- @Override
- public RDFList remove( final RDFNode val )
- {
- checkUpdate();
- RDFList cell = null;
- boolean denied = false;
-
- if (!canDelete(new Triple(Node.ANY, listFirst().asNode(), val.asNode())))
- {
- // iterate over the deletable items
- final ExtendedIterator<RDFList> iter = getSecuredRDFListIterator(Action.Delete);// .mapWith(new
- // SecuredListMap());
- while (iter.hasNext())
- {
- cell = iter.next();
-
- if (val.equals(cell.getRequiredProperty(listFirst())
- .getObject()))
- {
- if (canDelete(new Triple(cell.asNode(), listFirst()
- .asNode(), val.asNode())))
- {
- return SecuredRDFListImpl.getInstance(getModel(),
- baseRemove(cell));
-
- }
- else
- {
- denied = true;
- }
- }
- }
- if (denied)
- {
- throw new AccessDeniedException(getModelNode(), Action.Delete);
- }
- else
- {
- return this;
- }
- }
- else
- {
- return SecuredRDFListImpl.getInstance(getModel(), holder
- .getBaseItem().remove(val));
- }
- }
-
- @Override
- @Deprecated
- public void removeAll()
- {
- removeList();
- }
-
- @Override
- public SecuredRDFList removeHead()
- {
- checkUpdate();
- final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator(
- Action.Read).mapWith(new SecuredListMap());
- try
- {
- if (!iter.hasNext())
- {
- throw new EmptyListException(
- "Attempted to delete the head of a nil list");
- }
- final SecuredRDFList cell = iter.next();
- final Statement s = cell.getRequiredProperty(RDF.first);
- checkDelete(s);
- return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell));
-
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public void removeList()
- {
- checkUpdate();
- final Triple t = new Triple(Node.ANY, listFirst().asNode(), Node.ANY);
- /*
- * if (!canRead(t))
- * {
- * throw new EmptyListException(
- * "Attempted to delete the head of a nil list" );
- * }
- */
- // have to be able to read and delete to delete all.
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Read });
- if (getSecurityEvaluator().evaluate(getSecurityEvaluator().getPrincipal(), perms, this.getModelNode(),
- SecuredItemImpl.convert(t)))
- {
- holder.getBaseItem().removeList();
- }
- else
- {
- for (final Statement s : collectStatements(perms))
- {
- if (canDelete(s.asTriple()))
- {
- s.remove();
- }
- }
- }
- }
-
- @Override
- public SecuredRDFNode replace( final int i, final RDFNode value )
- {
- checkUpdate();
- final SecuredNodeMap map = new SecuredNodeMap(listFirst());
- final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator(
- Action.Read).mapWith(new SecuredListMap());
- int idx = 0;
- try
- {
- while (iter.hasNext())
- {
- if (i == idx)
- {
- final SecuredRDFList list = iter.next();
- final SecuredRDFNode retval = map.map1(list);
- final Triple t = new Triple(list.asNode(), listFirst()
- .asNode(), retval.asNode());
- final Triple t2 = new Triple(list.asNode(), listFirst()
- .asNode(), value.asNode());
- checkUpdate(t, t2);
- final RDFList base = (RDFList) list.getBaseItem();
- base.getRequiredProperty(listFirst()).changeObject(value);
- return retval;
- }
- else
- {
- idx++;
- iter.next();
- }
-
- }
- throw new ListIndexException();
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public boolean sameListAs( final RDFList list )
- {
- checkRead();
- ExtendedIterator<RDFNode> thisIter = null;
- ExtendedIterator<RDFNode> thatIter = null;
- try
- {
- thisIter = iterator();
- thatIter = list.iterator();
- while (thisIter.hasNext() && thatIter.hasNext())
- {
- final RDFNode thisN = thisIter.next();
- final RDFNode thatN = thatIter.next();
- if ((thisN == null) || !thisN.equals(thatN))
- {
- // not equal at this position
- return false;
- }
- }
- return !(thisIter.hasNext() || thatIter.hasNext());
- }
- finally
- {
- if (thisIter != null)
- {
- thisIter.close();
- }
- if (thatIter != null)
- {
- thatIter.close();
- }
- }
- }
-
- @Override
- public SecuredRDFNode setHead( final RDFNode value )
- {
- final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator(
- Action.Read).mapWith(new SecuredListMap());
- try
- {
- if (iter.hasNext())
- {
- return replace(0, value);
- }
- else
- {
- throw new EmptyListException(
- "Tried to set the head of an empty list");
- }
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public void setStrict( final boolean strict )
- {
- checkUpdate();
- holder.getBaseItem().setStrict(strict);
- }
-
- @Override
- public SecuredRDFList setTail( final RDFList tail )
- {
- checkUpdate();
-
- final Statement rest = holder.getBaseItem().getRequiredProperty(
- listRest());
- final RDFNode retval = rest.getObject();
- final Triple t = new Triple(holder.getBaseItem().asNode(), listRest()
- .asNode(), retval.asNode());
- final Triple t2 = new Triple(holder.getBaseItem().asNode(), listRest()
- .asNode(), tail.asNode());
- checkUpdate(t, t2);
- rest.changeObject(tail);
- return SecuredRDFListImpl.getInstance(getModel(),
- retval.as(RDFList.class));
- }
-
- @Override
- public int size()
- {
- checkRead();
- final Triple t = new Triple(Node.ANY, listFirst().asNode(), Node.ANY);
- if (canRead(t))
- {
- return holder.getBaseItem().size();
- }
- final ExtendedIterator<RDFNode> iter = iterator();
- int i = 0;
- while (iter.hasNext())
- {
- i++;
- iter.next();
- }
- return i;
- }
-
- @Override
- public SecuredRDFList with( final RDFNode value )
- {
- checkUpdate();
- checkCreate(new SecurityEvaluator.SecTriple(
- SecurityEvaluator.SecNode.FUTURE,
- SecuredItemImpl.convert(listFirst().asNode()),
- SecuredItemImpl.convert(value.asNode())));
- return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem()
- .with(value));
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRDFNodeImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRDFNodeImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRDFNodeImpl.java
deleted file mode 100644
index f538653..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRDFNodeImpl.java
+++ /dev/null
@@ -1,253 +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.model.impl;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.apache.jena.enhanced.UnsupportedPolymorphismException ;
-import org.apache.jena.graph.FrontsNode ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.RDFNode ;
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredRDFNode;
-import org.apache.jena.security.model.SecuredUnsupportedPolymorphismException;
-
-/**
- * Implementation of SecuredRDFNode to be used by a SecuredItemInvoker proxy.
- */
-public abstract class SecuredRDFNodeImpl extends SecuredItemImpl implements
- SecuredRDFNode
-{
- /**
- *
- * @param securedModel
- * the Secured Model to use.
- * @param rdfNode the node to secure.
- * @return the secured RDFNode
- */
- public static SecuredRDFNode getInstance( final SecuredModel securedModel,
- final RDFNode rdfNode )
- {
- if (rdfNode instanceof Literal)
- {
- return SecuredLiteralImpl.getInstance(securedModel,
- (Literal) rdfNode);
- }
- else
- {
- return SecuredResourceImpl.getInstance(securedModel,
- (Resource) rdfNode);
- }
- }
-
- // the item holder that contains this SecuredRDFNode
- private final ItemHolder<? extends RDFNode, ? extends SecuredRDFNode> holder;
-
- // the secured securedModel that contains this node.
- private final SecuredModel securedModel;
-
- /**
- * Constructor
- *
- * @param securedModel
- * the Secured Model to use.
- * @param holder
- * the item holder that will contain this SecuredRDFNode.
- */
- protected SecuredRDFNodeImpl( final SecuredModel securedModel,
- final ItemHolder<? extends RDFNode, ? extends SecuredRDFNode> holder )
- {
- super(securedModel, holder);
- if (holder.getBaseItem().getModel() == null)
- {
- throw new IllegalArgumentException(String.format(
- "Holder base item (%s) must have a securedModel", holder
- .getBaseItem().getClass()));
- }
- this.securedModel = securedModel;
- this.holder = holder;
- }
-
- @SuppressWarnings( "unchecked" )
- @Override
- public <T extends RDFNode> T as( final Class<T> view )
- {
- checkRead();
- // see if the base Item can as
- T baseAs = holder.getBaseItem().as(view);
-
- if (view.equals(SecuredRDFNodeImpl.class)
- || view.equals(RDFNode.class))
- {
- return (T) this;
- }
- final Method m = getConstructor(view);
- if (m == null)
- {
- throw new SecuredUnsupportedPolymorphismException(this, view);
- }
- try
- {
- return (T) m.invoke(null, securedModel, holder.getBaseItem()
- .as(view));
- }
- catch (final UnsupportedPolymorphismException e)
- {
- throw new SecuredUnsupportedPolymorphismException(this, view);
- }
- catch (final IllegalArgumentException e)
- {
- throw new RuntimeException(e);
- }
- catch (final IllegalAccessException e)
- {
- throw new RuntimeException(e);
- }
- catch (final InvocationTargetException e)
- {
- throw new RuntimeException(e);
- }
- /*
- else
- {
- throw new SecuredUnsupportedPolymorphismException(this, view);
- }
- */
- }
-
- @Override
- public Node asNode()
- {
- checkRead();
- return holder.getBaseItem().asNode();
- }
-
- @Override
- public <T extends RDFNode> boolean canAs( final Class<T> view )
- {
- checkRead();
- // see if the base Item can as
- if (holder.getBaseItem().canAs(view))
- {
- return getConstructor(view) != null;
- }
- return false;
- }
-
- private <T extends RDFNode> Method getConstructor( final Class<T> view )
- {
- String classNm = SecuredRDFNodeImpl.class.getName();
- classNm = String.format("%s.Secured%sImpl",
- classNm.substring(0, classNm.lastIndexOf(".")),
- view.getSimpleName());
- try
- {
- final Class<?> c = Class.forName(classNm);
- return c.getDeclaredMethod("getInstance", SecuredModel.class, view);
- }
- catch (final ClassNotFoundException e)
- {
- return null;
- }
- catch (final SecurityException e)
- {
- return null;
- }
- catch (final NoSuchMethodException e)
- {
- return null;
- }
- }
-
- @Override
- public SecuredModel getModel()
- {
- return securedModel;
- }
-
- @Override
- public RDFNode inModel( final Model m )
- {
- checkRead();
- if (securedModel.equals(m))
- {
- return this;
- }
- if (m instanceof SecuredModel)
- {
- return SecuredRDFNodeImpl.getInstance((SecuredModel) m, holder
- .getBaseItem().inModel(m));
- }
- return holder.getBaseItem().inModel(m);
- }
-
- @Override
- public boolean isAnon()
- {
- return holder.getBaseItem().isAnon();
- }
-
- @Override
- public boolean isLiteral()
- {
- return holder.getBaseItem().isLiteral();
- }
-
- @Override
- public boolean isResource()
- {
- return holder.getBaseItem().isResource();
- }
-
- @Override
- public boolean isURIResource()
- {
- return holder.getBaseItem().isURIResource();
- }
-
- /**
- * An RDFNode is equal to another enhanced node n iff the underlying
- * nodes are equal. We generalise to allow the other object to be any class
- * implementing asNode, because we allow other implemementations of
- * Resource, at least in principle.
- * This is deemed to be a complete and correct interpretation of RDFNode
- * equality, which is why this method has been marked final.
- *
- * @param o An object to test for equality with this node
- * @return True if o is equal to this node.
- */
- @Override final public boolean equals( Object o )
- {
- checkRead();
- return o instanceof FrontsNode && asNode().equals(((FrontsNode) o).asNode());
- }
-
- /**
- * The hash code of an RDFnode is defined to be the same as the underlying node.
- * @return The hashcode as an int
- */
- @Override final public int hashCode() {
- return holder.getBaseItem().asNode().hashCode();
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRSIterator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRSIterator.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRSIterator.java
deleted file mode 100644
index a52da02..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredRSIterator.java
+++ /dev/null
@@ -1,174 +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.model.impl;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.jena.rdf.model.RSIterator ;
-import org.apache.jena.rdf.model.ReifiedStatement ;
-import org.apache.jena.security.SecurityEvaluator;
-import org.apache.jena.security.SecurityEvaluator.Action;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.impl.SecuredItemImpl;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.Filter ;
-import org.apache.jena.util.iterator.Map1 ;
-
-/**
- * A secured RSIterator implementation
- */
-public class SecuredRSIterator implements RSIterator
-{
- private class PermReifiedStatementFilter extends Filter<ReifiedStatement>
- {
- private final SecurityEvaluator evaluator;
- private final SecNode modelNode;
- private final Set<Action> actions;
-
- public PermReifiedStatementFilter( final Action[] actions,
- final SecuredModel securedModel )
- {
- this.modelNode = securedModel.getModelNode();
- this.actions = SecurityEvaluator.Util.asSet(actions);
- this.evaluator = securedModel.getSecurityEvaluator();
- }
-
- @Override
- public boolean accept( final ReifiedStatement t )
- {
- return evaluator.evaluateAny(evaluator.getPrincipal(), actions, modelNode,
- SecuredItemImpl.convert(t.getStatement().asTriple()));
- }
-
- }
-
- private class PermReifiedStatementMap implements
- Map1<ReifiedStatement, ReifiedStatement>
- {
- private final SecuredModel securedModel;
-
- public PermReifiedStatementMap( final SecuredModel securedModel )
- {
- this.securedModel = securedModel;
- }
-
- @Override
- public ReifiedStatement map1( final ReifiedStatement o )
- {
- return SecuredReifiedStatementImpl.getInstance(securedModel, o);
- }
- }
-
- private final ExtendedIterator<ReifiedStatement> iter;
-
- /**
- * Constructor
- *
- * @param securedModel
- * The secured model that provides the security context
- * @param wrapped
- * The wrapped iterator.
- */
- public SecuredRSIterator( final SecuredModel securedModel,
- final ExtendedIterator<ReifiedStatement> wrapped )
- {
- final PermReifiedStatementFilter filter = new PermReifiedStatementFilter(
- new Action[] { Action.Read }, securedModel);
- final PermReifiedStatementMap map1 = new PermReifiedStatementMap(
- securedModel);
- iter = wrapped.filterKeep(filter).mapWith(map1);
- }
-
- @Override
- public <X extends ReifiedStatement> ExtendedIterator<ReifiedStatement> andThen(
- final Iterator<X> other )
- {
- return iter.andThen(other);
- }
-
- @Override
- public void close()
- {
- iter.close();
- }
-
- @Override
- public ExtendedIterator<ReifiedStatement> filterDrop(
- final Filter<ReifiedStatement> f )
- {
- return iter.filterDrop(f);
- }
-
- @Override
- public ExtendedIterator<ReifiedStatement> filterKeep(
- final Filter<ReifiedStatement> f )
- {
- return iter.filterKeep(f);
- }
-
- @Override
- public boolean hasNext()
- {
- return iter.hasNext();
- }
-
- @Override
- public <U> ExtendedIterator<U> mapWith( final Map1<ReifiedStatement, U> map1 )
- {
- return iter.mapWith(map1);
- }
-
- @Override
- public ReifiedStatement next()
- {
- return iter.next();
- }
-
- @Override
- public ReifiedStatement nextRS()
- {
- return next();
- }
-
- @Override
- public void remove()
- {
- iter.remove();
- }
-
- @Override
- public ReifiedStatement removeNext()
- {
- return iter.removeNext();
- }
-
- @Override
- public List<ReifiedStatement> toList()
- {
- return iter.toList();
- }
-
- @Override
- public Set<ReifiedStatement> toSet()
- {
- return iter.toSet();
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredReifiedStatementImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredReifiedStatementImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredReifiedStatementImpl.java
deleted file mode 100644
index a357b55..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredReifiedStatementImpl.java
+++ /dev/null
@@ -1,99 +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.model.impl;
-
-import org.apache.jena.rdf.model.ReifiedStatement ;
-import org.apache.jena.security.impl.ItemHolder;
-import org.apache.jena.security.impl.SecuredItemInvoker;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredReifiedStatement;
-import org.apache.jena.security.model.SecuredStatement;
-
-/**
- * Implementation of SecuredReifiedStatement to be used by a SecuredItemInvoker
- * proxy.
- */
-public class SecuredReifiedStatementImpl extends SecuredResourceImpl implements
- SecuredReifiedStatement
-{
- /**
- * Get an instance of SecuredReifiedStatement
- *
- * @param securedModel
- * the Secured Model to use.
- * @param stmt
- * The ReifiedStatement to secure.
- * @return SecuredReifiedStatement
- */
- public static SecuredReifiedStatement getInstance(
- final SecuredModel securedModel, final ReifiedStatement stmt )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (stmt == null)
- {
- throw new IllegalArgumentException("Statement may not be null");
- }
- final ItemHolder<ReifiedStatement, SecuredReifiedStatement> holder = new ItemHolder<ReifiedStatement, SecuredReifiedStatement>(
- stmt);
- final SecuredReifiedStatementImpl checker = new SecuredReifiedStatementImpl(
- securedModel, holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (stmt instanceof SecuredReifiedStatement)
- {
- if (checker.isEquivalent((SecuredReifiedStatement) stmt))
- {
- return (SecuredReifiedStatement) stmt;
- }
- }
- return holder.setSecuredItem(new SecuredItemInvoker(stmt.getClass(),
- checker));
- }
-
- // the item holder that contains this SecuredResource
- private final ItemHolder<? extends ReifiedStatement, ? extends SecuredReifiedStatement> holder;
-
- /**
- * Constructor
- *
- * @param securedModel
- * The secured model to use
- * @param holder
- * the item holder that will contain this SecuredReifiedStatement
- */
- protected SecuredReifiedStatementImpl(
- final SecuredModel securedModel,
- final ItemHolder<? extends ReifiedStatement, ? extends SecuredReifiedStatement> holder )
- {
- super(securedModel, holder);
- this.holder = holder;
- }
-
- @Override
- public SecuredStatement getStatement()
- {
- checkRead();
- return SecuredStatementImpl.getInstance(getModel(), holder
- .getBaseItem().getStatement());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredResIterator.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredResIterator.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredResIterator.java
deleted file mode 100644
index 338c389..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredResIterator.java
+++ /dev/null
@@ -1,133 +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.model.impl;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.jena.rdf.model.ResIterator ;
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.security.model.SecuredModel;
-import org.apache.jena.security.model.SecuredResource;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.Filter ;
-import org.apache.jena.util.iterator.Map1 ;
-
-public class SecuredResIterator implements ResIterator
-{
-
- private class PermResourceMap implements Map1<Resource, Resource>
- {
- private final SecuredModel securedModel;
-
- public PermResourceMap( final SecuredModel securedModel )
- {
- this.securedModel = securedModel;
- }
-
- @Override
- public SecuredResource map1( final Resource o )
- {
- return SecuredResourceImpl.getInstance(securedModel, o);
- }
- }
-
- private final ExtendedIterator<Resource> iter;
-
- public SecuredResIterator( final SecuredModel securedModel,
- final ExtendedIterator<Resource> wrapped)
- {
-
- final PermResourceMap map1 = new PermResourceMap(securedModel);
- iter = wrapped.mapWith(map1);
- }
-
- @Override
- public <X extends Resource> ExtendedIterator<Resource> andThen(
- final Iterator<X> other )
- {
- return iter.andThen(other);
- }
-
- @Override
- public void close()
- {
- iter.close();
- }
-
- @Override
- public ExtendedIterator<Resource> filterDrop( final Filter<Resource> f )
- {
- return iter.filterDrop(f);
- }
-
- @Override
- public ExtendedIterator<Resource> filterKeep( final Filter<Resource> f )
- {
- return iter.filterKeep(f);
- }
-
- @Override
- public boolean hasNext()
- {
- return iter.hasNext();
- }
-
- @Override
- public <U> ExtendedIterator<U> mapWith( final Map1<Resource, U> map1 )
- {
- return iter.mapWith(map1);
- }
-
- @Override
- public Resource next()
- {
- return iter.next();
- }
-
- @Override
- public Resource nextResource()
- {
- return next();
- }
-
- @Override
- public void remove()
- {
- iter.remove();
- }
-
- @Override
- public Resource removeNext()
- {
- return iter.removeNext();
- }
-
- @Override
- public List<Resource> toList()
- {
- return iter.toList();
- }
-
- @Override
- public Set<Resource> toSet()
- {
- return iter.toSet();
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredResourceImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredResourceImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredResourceImpl.java
deleted file mode 100644
index 4a8dc70..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredResourceImpl.java
+++ /dev/null
@@ -1,893 +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.model.impl;
-
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.AccessDeniedException ;
-import org.apache.jena.security.SecurityEvaluator.Action ;
-import org.apache.jena.security.impl.ItemHolder ;
-import org.apache.jena.security.impl.SecuredItemImpl ;
-import org.apache.jena.security.impl.SecuredItemInvoker ;
-import org.apache.jena.security.model.SecuredModel ;
-import org.apache.jena.security.model.SecuredResource ;
-import org.apache.jena.security.model.SecuredStatement ;
-import org.apache.jena.security.utils.PermStatementFilter ;
-import org.apache.jena.shared.PropertyNotFoundException ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-
-/**
- * Implementation of SecuredResource to be used by a SecuredItemInvoker proxy.
- */
-public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
- SecuredResource
-{
- /**
- * Get a SecuredResource.
- *
- * @param securedModel
- * the securedItem that provides the security context.
- * @param resource
- * The resource to secure.
- * @return The SecuredResource
- */
- public static SecuredResource getInstance( final SecuredModel securedModel,
- final Resource resource )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (resource == null)
- {
- throw new IllegalArgumentException("Resource may not be null");
- }
- if (resource.isLiteral())
- {
- throw new IllegalArgumentException("Resource may not be a literal");
- }
- // check that resource has a securedModel.
- Resource goodResource = resource;
- if (goodResource.getModel() == null)
- {
- final Node n = resource.asNode();
- if (resource.isAnon())
- {
- goodResource = securedModel.createResource(n.getBlankNodeId());
- }
- else
- {
- goodResource = securedModel.createResource(n.getURI());
- }
- }
-
- final ItemHolder<Resource, SecuredResource> holder = new ItemHolder<Resource, SecuredResource>(
- goodResource);
-
- final SecuredResourceImpl checker = new SecuredResourceImpl(
- securedModel, holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (goodResource instanceof SecuredResource)
- {
- if (checker.isEquivalent((SecuredResource) goodResource))
- {
- return (SecuredResource) goodResource;
- }
- }
-
- return holder.setSecuredItem(new SecuredItemInvoker(
- resource.getClass(), checker));
-
- }
-
- // the item holder that contains this SecuredResource
- private final ItemHolder<? extends Resource, ? extends SecuredResource> holder;
-
- /**
- * Constructor.
- *
- * @param securedModel
- * The secured model to use
- * @param holder
- * the item holder that will contain this SecuredResource.
- */
- protected SecuredResourceImpl(
- final SecuredModel securedModel,
- final ItemHolder<? extends Resource, ? extends SecuredResource> holder )
- {
- super(securedModel, holder);
- this.holder = holder;
- }
-
- /**
- * Abort the transaction in the associated securedModel.
- *
- * @return This resource to permit cascading.
- */
- @Override
- public SecuredResource abort()
- {
- holder.getBaseItem().abort();
- return holder.getSecuredItem();
- }
-
- /**
- * Add the property <code>p</code> with the typed-literal value
- * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
- * this's securedModel. Answer
- * this resource. The typed literal is equal to one constructed by using
- * <code>this.getModel().createTypedLiteral(o)</code>.
- */
- @Override
- public SecuredResource addLiteral( final Property p, final boolean o )
- {
- return addProperty( p, ResourceFactory.createTypedLiteral(o) );
- }
-
- /**
- * Add the property <code>p</code> with the typed-literal value
- * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
- * this's securedModel. Answer
- * this resource. The typed literal is equal to one constructed by using
- * <code>this.getModel().createTypedLiteral(o)</code>.
- */
- @Override
- public SecuredResource addLiteral( final Property p, final char o )
- {
- return addProperty( p, ResourceFactory.createTypedLiteral(o));
- }
-
- /**
- * Add the property <code>p</code> with the typed-literal value
- * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
- * this's securedModel. Answer
- * this resource. The typed literal is equal to one constructed by using
- * <code>this.getModel().createTypedLiteral(o)</code>.
- */
- @Override
- public SecuredResource addLiteral( final Property value, final double d )
- {
- return addProperty( value, ResourceFactory.createTypedLiteral(d));
- }
-
- /**
- * Add the property <code>p</code> with the typed-literal value
- * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
- * this's securedModel. Answer
- * this resource. The typed literal is equal to one constructed by using
- * <code>this.getModel().createTypedLiteral(o)</code>.
- */
- @Override
- public SecuredResource addLiteral( final Property value, final float d )
- {
- return addProperty( value, ResourceFactory.createTypedLiteral(d) );
- }
-
- /**
- * Add the property <code>p</code> with the pre-constructed Literal value
- * <code>o</code> to this resource, <i>ie</i> add (this, p, o) to this's
- * securedModel. Answer this resource. <b>NOTE</b> thjat this is distinct
- * from the
- * other addLiteral methods in that the Literal is not turned into a
- * Literal.
- */
- @Override
- public SecuredResource addLiteral( final Property p, final Literal o )
- {
- return addProperty( p, o );
- }
-
- /**
- * Add the property <code>p</code> with the typed-literal value
- * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
- * this's securedModel. Answer
- * this resource. The typed literal is equal to one constructed by using
- * <code>this.getModel().createTypedLiteral(o)</code>.
- */
- @Override
- public SecuredResource addLiteral( final Property p, final long o )
- {
- return addProperty( p, ResourceFactory.createTypedLiteral(o));
- }
-
- /**
- * Add the property <code>p</code> with the typed-literal value
- * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
- * this's securedModel. Answer
- * this resource. The typed literal is equal to one constructed by using
- * <code>this.getModel().createTypedLiteral(o)</code>.
- */
- @Override
- public SecuredResource addLiteral( final Property p, final Object o )
- {
- return addProperty( p, ResourceFactory.createTypedLiteral(o));
- }
-
- /**
- * Add a property to this resource.
- *
- * <p>
- * A statement with this resource as the subject, p as the predicate and o
- * as the object is added to the securedModel associated with this resource.
- * </p>
- *
- * @param p
- * The property to be added.
- * @param o
- * The value of the property to be added.
- * @return This resource to allow cascading calls.
- */
- @Override
- public SecuredResource addProperty( final Property p, final RDFNode o )
- {
- checkUpdate();
- checkCreate(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- o.asNode()));
- holder.getBaseItem().addProperty(p, o);
- return holder.getSecuredItem();
- }
-
- /**
- * Add a property to this resource.
- *
- * <p>
- * A statement with this resource as the subject, p as the predicate and o
- * as the object is added to the securedModel associated with this resource.
- * </p>
- *
- * @param p
- * The property to be added.
- * @param o
- * The value of the property to be added.
- * @return This resource to allow cascading calls.
- */
- @Override
- public SecuredResource addProperty( final Property p, final String o )
- {
- return addProperty( p, o, "");
- }
-
- /**
- * Add a property to this resource.
- *
- * <p>
- * A statement with this resource as the subject, p as the predicate and o
- * as the object is added to the securedModel associated with this resource.
- * </p>
- *
- * @param p
- * The property to be added.
- * @param lexicalForm
- * The lexical form of the literal
- * @param datatype
- * The datatype
- * @return This resource to allow cascading calls.
- */
- @Override
- public SecuredResource addProperty( final Property p, final String lexicalForm,
- final RDFDatatype datatype )
- {
- checkUpdate();
- final Literal l = ResourceFactory.createTypedLiteral(lexicalForm,
- datatype);
- checkCreate(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- l.asNode()));
- holder.getBaseItem().addProperty(p, l);
- return holder.getSecuredItem();
- }
-
- /**
- * Add a property to this resource.
- *
- * <p>
- * A statement with this resource as the subject, p as the predicate and o
- * as the object is added to the securedModel associated with this resource.
- * </p>
- *
- * @param p
- * The property to be added.
- * @param o
- * The value of the property to be added.
- * @param l
- * the language of the property
- * @return This resource to allow cascading calls.
- */
- @Override
- public SecuredResource addProperty( final Property p, final String o,
- final String l )
- {
- checkUpdate();
- checkCreate(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- NodeFactory.createLiteral(o, l, false)));
- holder.getBaseItem().addProperty(p, o, l);
- return holder.getSecuredItem();
- }
-
- @Override
- public Literal asLiteral()
- {
- throw new LiteralRequiredException(asNode());
- }
-
- @Override
- public SecuredResource asResource()
- {
- return holder.getSecuredItem();
- }
-
- /**
- * Begin a transaction in the associated securedModel.
- *
- * @return This resource to permit cascading.
- */
- @Override
- public SecuredResource begin()
- {
- holder.getBaseItem().begin();
- return holder.getSecuredItem();
- }
-
- public boolean canReadProperty( final Node p )
- {
- return canRead(new Triple(holder.getBaseItem().asNode(), p, Node.ANY));
- }
-
- protected void checkReadProperty( final Node p )
- {
- if (!canReadProperty(p))
- {
- throw new AccessDeniedException(getModelNode(), SecuredItemImpl
- .convert(
- new Triple(holder.getBaseItem().asNode(), p,
- Node.ANY)).toString(), Action.Read);
- }
- }
-
- /**
- * Commit the transaction in the associated securedModel.
- *
- * @return This resource to permit cascading.
- */
- @Override
- public SecuredResource commit()
- {
- holder.getBaseItem().commit();
- return holder.getSecuredItem();
- }
-
- /**
- * Returns an a unique identifier for anonymous resources.
- *
- * <p>
- * The id is unique within the scope of a particular implementation. All
- * models within an implementation will use the same id for the same
- * anonymous resource.
- * </p>
- *
- * <p>
- * This method is undefined if called on resources which are not anonymous
- * and may raise an exception.
- * </p>
- *
- * @return A unique id for an anonymous resource.
- */
- @Override
- public AnonId getId()
- {
- checkRead();
- return holder.getBaseItem().getId();
-
- }
-
- /**
- * Returns the name of this resource within its namespace.
- *
- * @return The name of this property within its namespace.
- */
- @Override
- public String getLocalName()
- {
- checkRead();
- return holder.getBaseItem().getLocalName();
- }
-
- /**
- * Returns the namespace associated with this resource.
- *
- * @return The namespace for this property.
- */
- @Override
- public String getNameSpace()
- {
- checkRead();
- return holder.getBaseItem().getNameSpace();
- }
-
- /**
- * Answer some statement (this, p, O) in the associated securedModel. If
- * there are
- * several
- * such statements, any one of them may be returned. If no such statements
- * exist,
- * null is returned - in this is differs from getRequiredProperty.
- *
- * @param p
- * the property sought
- * @return a statement (this, p, O), or null if no such statements exist
- * here
- */
- @Override
- public SecuredStatement getProperty( final Property p )
- {
- checkRead();
- final ExtendedIterator<Statement> iter = holder.getBaseItem()
- .listProperties(p)
- .filterKeep(new PermStatementFilter(Action.Read, this));
- try
- {
- if (iter.hasNext())
- {
- return org.apache.jena.security.model.impl.SecuredStatementImpl
- .getInstance(getModel(), iter.next());
- }
- else
- {
- return null;
- }
- }
- finally
- {
- iter.close();
- }
- }
-
- /**
- * Answer some resource R for which this.hasProperty( p, R ),
- * or null if no such R exists.
- */
- @Override
- public SecuredResource getPropertyResourceValue( final Property p )
- {
- final SecuredStatementIterator iter = listProperties(p);
- try
- {
- while (iter.hasNext())
- {
- final Statement s = iter.next();
- if (s.getObject().isResource())
- {
- return SecuredResourceImpl.getInstance(getModel(), s
- .getObject().asResource());
- }
- }
- return null;
- }
- finally
- {
- iter.close();
- }
- }
-
- /**
- * Get a property value of this resource.
- *
- * <p>
- * The securedModel associated with the resource instance is searched for
- * statements whose subject is this resource and whose predicate is p. If
- * such a statement is found, it is returned. If several such statements are
- * found, any one may be returned. If no such statements are found, an
- * exception is thrown.
- * </p>
- *
- * @param p
- * The property sought.
- * @return some (this, p, ?O) statement if one exists
- * @throws PropertyNotFoundException
- * if no such statement found
- */
- @Override
- public SecuredStatement getRequiredProperty( final Property p )
- throws PropertyNotFoundException
- {
- checkRead();
- final ExtendedIterator<Statement> iter = holder.getBaseItem()
- .listProperties(p)
- .filterKeep(new PermStatementFilter(Action.Read, this));
- try
- {
- if (iter.hasNext())
- {
- return org.apache.jena.security.model.impl.SecuredStatementImpl
- .getInstance(getModel(), iter.next());
- }
- else
- {
- throw new PropertyNotFoundException(p);
- }
- }
- finally
- {
- iter.close();
- }
- // return org.apache.jena.security.model.impl.Factory.getInstance(
- // this, holder.getBaseItem().getRequiredProperty(p));
- }
-
- /**
- * Return the URI of the resource, or null if it's a bnode.
- *
- * @return The URI of the resource, or null if it's a bnode.
- */
- @Override
- public String getURI()
- {
- checkRead();
- return holder.getBaseItem().getURI();
- }
-
- /**
- * Answer true iff this resource has the value <code>o</code> for
- * property <code>p</code>. <code>o</code> is interpreted as
- * a typed literal with the appropriate RDF type.
- */
- @Override
- public boolean hasLiteral( final Property p, final boolean o )
- {
- checkRead();
- checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- ResourceFactory.createTypedLiteral(o).asNode()));
- return holder.getBaseItem().hasLiteral(p, o);
- }
-
- /**
- * Answer true iff this resource has the value <code>o</code> for
- * property <code>p</code>. <code>o</code> is interpreted as
- * a typed literal with the appropriate RDF type.
- */
- @Override
- public boolean hasLiteral( final Property p, final char o )
- {
- checkRead();
- checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- ResourceFactory.createTypedLiteral(o).asNode()));
- return holder.getBaseItem().hasLiteral(p, o);
- }
-
- /**
- * Answer true iff this resource has the value <code>o</code> for
- * property <code>p</code>. <code>o</code> is interpreted as
- * a typed literal with the appropriate RDF type.
- */
- @Override
- public boolean hasLiteral( final Property p, final double o )
- {
- checkRead();
- checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- ResourceFactory.createTypedLiteral(o).asNode()));
- return holder.getBaseItem().hasLiteral(p, o);
- }
-
- /**
- * Answer true iff this resource has the value <code>o</code> for
- * property <code>p</code>. <code>o</code> is interpreted as
- * a typed literal with the appropriate RDF type.
- */
- @Override
- public boolean hasLiteral( final Property p, final float o )
- {
- checkRead();
- checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- ResourceFactory.createTypedLiteral(o).asNode()));
- return holder.getBaseItem().hasLiteral(p, o);
- }
-
- /**
- * Answer true iff this resource has the value <code>o</code> for
- * property <code>p</code>. <code>o</code> is interpreted as
- * a typed literal with the appropriate RDF type.
- */
- @Override
- public boolean hasLiteral( final Property p, final long o )
- {
- checkRead();
- checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- ResourceFactory.createTypedLiteral(o).asNode()));
- return holder.getBaseItem().hasLiteral(p, o);
- }
-
- /**
- * Answer true iff this resource has the value <code>o</code> for
- * property <code>p</code>. <code>o</code> is interpreted as
- * a typed literal with the appropriate RDF type.
- */
- @Override
- public boolean hasLiteral( final Property p, final Object o )
- {
- checkRead();
- checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- ResourceFactory.createTypedLiteral(o).asNode()));
- return holder.getBaseItem().hasLiteral(p, o);
- }
-
- /**
- * Determine whether this resource has any values for a given property.
- *
- * @param p
- * The property sought.
- * @return true if and only if this resource has at least one
- * value for the property.
- */
- @Override
- public boolean hasProperty( final Property p )
- {
- checkRead();
- final ExtendedIterator<Statement> iter = holder.getBaseItem()
- .listProperties(p)
- .filterKeep(new PermStatementFilter(Action.Read, this));
- try
- {
- return iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
-
- /**
- * Test if this resource has a given property with a given value.
- *
- * @param p
- * The property sought.
- * @param o
- * The value of the property sought.
- * @return true if and only if this resource has property p with
- * value o.
- */
- @Override
- public boolean hasProperty( final Property p, final RDFNode o )
- {
- checkRead();
- final ExtendedIterator<Statement> iter = holder.getBaseItem()
- .getModel().listStatements(this, p, o)
- .filterKeep(new PermStatementFilter(Action.Read, this));
- try
- {
- return iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
-
- /**
- * Test if this resource has a given property with a given value.
- *
- * @param p
- * The property sought.
- * @param o
- * The value of the property sought.
- * @return true if and only if this resource has property p with
- * value o.
- */
- @Override
- public boolean hasProperty( final Property p, final String o )
- {
- checkRead();
- final ExtendedIterator<Statement> iter = holder.getBaseItem()
- .getModel().listStatements(this, p, o)
- .filterKeep(new PermStatementFilter(Action.Read, this));
- try
- {
- return iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
-
- /**
- * Test if this resource has a given property with a given value.
- *
- * @param p
- * The property sought.
- * @param o
- * The value of the property sought.
- * @param l
- * The language of the property sought.
- * @return true if and only if this resource has property p with
- * value o.
- */
- @Override
- public boolean hasProperty( final Property p, final String o, final String l )
- {
- checkRead();
- final Literal ll = holder.getBaseItem().getModel().createLiteral(o, l);
- final ExtendedIterator<Statement> iter = holder.getBaseItem()
- .getModel().listStatements(this, p, ll)
- .filterKeep(new PermStatementFilter(Action.Read, this));
- try
- {
- return iter.hasNext();
- }
- finally
- {
- iter.close();
- }
- }
-
- /**
- * Answer true iff this Resource is a URI resource with the given URI.
- * Using this is preferred to using getURI() and .equals().
- */
- @Override
- public boolean hasURI( final String uri )
- {
- checkRead();
- return holder.getBaseItem().hasURI(uri);
- }
-
- @Override
- public Resource inModel( final Model m )
- {
- return (Resource) super.inModel(m);
- }
-
- /**
- * Return an iterator over all the properties of this resource.
- *
- * <p>
- * The securedModel associated with this resource is search and an iterator
- * is returned which iterates over all the statements which have this
- * resource as a subject.
- * </p>
- *
- * @return An iterator over all the statements about this object.
- */
- @Override
- public SecuredStatementIterator listProperties()
- {
- checkRead();
- return new SecuredStatementIterator(getModel(), holder.getBaseItem()
- .listProperties());
- }
-
- /**
- * List all the values of the property p.
- *
- * <p>
- * Returns an iterator over all the statements in the associated
- * securedModel whose subject is this resource and whose predicate is p.
- * </p>
- *
- * @param p
- * The predicate sought.
- * @return An iterator over the statements.
- */
- @Override
- public SecuredStatementIterator listProperties( final Property p )
- {
- checkRead();
- return new SecuredStatementIterator(getModel(), holder.getBaseItem()
- .listProperties(p));
-
- }
-
- /**
- * Delete all the statements with predicate <code>p</code> for this resource
- * from its associated securedModel.
- *
- * @param p
- * the property to remove
- * @return this resource, to permit cascading
- */
- @Override
- public SecuredResource removeAll( final Property p )
- {
- checkUpdate();
- if (!canDelete(new Triple(holder.getBaseItem().asNode(), p.asNode(),
- Node.ANY)))
- {
- final StmtIterator iter = holder.getBaseItem().listProperties(p);
- try
- {
- if (!iter.hasNext())
- {
- // thre arn't any to delete -- so return
- return holder.getSecuredItem();
- }
- while (iter.hasNext())
- {
- checkDelete(iter.next().asTriple());
- }
- }
- finally
- {
- iter.close();
- }
- }
- holder.getBaseItem().removeAll(p);
- return holder.getSecuredItem();
- }
-
- /**
- * Delete all the properties for this resource from the associated
- * securedModel.
- *
- * @return This resource to permit cascading.
- */
- @Override
- public SecuredResource removeProperties()
- {
- checkUpdate();
- if (!canDelete(new Triple(holder.getBaseItem().asNode(), Node.ANY,
- Node.ANY)))
- {
- final StmtIterator iter = holder.getBaseItem().listProperties();
- try
- {
- if (!iter.hasNext())
- {
- // thre arn't any to delete -- so return
- return holder.getSecuredItem();
- }
- while (iter.hasNext())
- {
- checkDelete(iter.next().asTriple());
- }
- }
- finally
- {
- iter.close();
- }
- }
- holder.getBaseItem().removeProperties();
- return holder.getSecuredItem();
- }
-
- /**
- * Return a string representation of the resource.
- *
- * Returns the URI of the resource unless the resource is anonymous
- * in which case it returns the id of the resource enclosed in square
- * brackets.
- *
- * @return Return a string representation of the resource.
- * if it is anonymous.
- */
- @Override
- public String toString()
- {
- return holder.getBaseItem().toString();
- }
-
- @Override
- public Object visitWith( final RDFVisitor rv )
- {
- return isAnon() ? rv.visitBlank(this, getId()) : rv.visitURI(this,
- getURI());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredSelector.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredSelector.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredSelector.java
deleted file mode 100644
index 9102a2a..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredSelector.java
+++ /dev/null
@@ -1,94 +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.model.impl;
-
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.SecurityEvaluator.SecNode;
-import org.apache.jena.security.SecurityEvaluator.SecTriple;
-import org.apache.jena.security.impl.SecuredItem;
-import org.apache.jena.security.impl.SecuredItemImpl;
-
-public class SecuredSelector implements Selector
-{
- private final SecuredItem securedItem;
- private final Selector selector;
-
- public SecuredSelector( final SecuredItem securedItem )
- {
- this(securedItem, new SimpleSelector());
- }
-
- public SecuredSelector( final SecuredItem securedItem,
- final Selector selector )
- {
- this.securedItem = securedItem;
- this.selector = selector;
- }
-
- private SecNode getNode( final RDFNode node )
- {
- return node == null ? SecNode.ANY : SecuredItemImpl.convert(node
- .asNode());
- }
-
- @Override
- public RDFNode getObject()
- {
- return selector.getObject();
- }
-
- @Override
- public Property getPredicate()
- {
- return selector.getPredicate();
- }
-
- @Override
- public Resource getSubject()
- {
- return selector.getSubject();
- }
-
- @Override
- public boolean isSimple()
- {
- return securedItem.canRead(SecTriple.ANY);
- }
-
- /**
- * This method is designed to be over ridden by subclasses to define
- * application
- * specific constraints on the statements selected.
- *
- * @param s
- * the statement to be tested
- * @return true if the statement satisfies the constraint
- */
- @Override
- public boolean test( final Statement s )
- {
- if (selector.test(s))
- {
- final SecTriple t = new SecTriple(getNode(s.getSubject()),
- getNode(s.getPredicate()), getNode(s.getObject()));
- return securedItem.canRead(t);
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredSeqImpl.java
----------------------------------------------------------------------
diff --git a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredSeqImpl.java b/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredSeqImpl.java
deleted file mode 100644
index 9514417..0000000
--- a/jena-security/src/main/java/org/apache/jena/security/model/impl/SecuredSeqImpl.java
+++ /dev/null
@@ -1,511 +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.model.impl;
-
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.security.impl.ItemHolder ;
-import org.apache.jena.security.impl.SecuredItemInvoker ;
-import org.apache.jena.security.model.* ;
-import org.apache.jena.util.iterator.ExtendedIterator ;
-import org.apache.jena.util.iterator.Filter ;
-import org.apache.jena.vocabulary.RDF ;
-
-/**
- * Implementation of SecuredSeq to be used by a SecuredItemInvoker proxy.
- *
- * Sequence may have breaks in the order.
- * http://www.w3.org/TR/2004/REC-rdf-mt-20040210/#Containers
- *
- */
-public class SecuredSeqImpl extends SecuredContainerImpl implements SecuredSeq
-{
- private class RDFNodeFilter extends Filter<Statement>
- {
- private final RDFNode n;
-
- public RDFNodeFilter( final RDFNode n )
- {
- this.n = n;
- }
-
- @Override
- public boolean accept( final Statement o )
- {
- return (o.getPredicate().getOrdinal() != 0)
- && n.equals(o.getObject());
- }
-
- }
-
- /**
- * get a SecuredSeq.
- *
- * @param securedModel
- * The secured model that provides the security context
- * @param seq
- * The Seq to secure.
- * @return the SecuredSeq
- */
- public static SecuredSeq getInstance( final SecuredModel securedModel,
- final Seq seq )
- {
- if (securedModel == null)
- {
- throw new IllegalArgumentException(
- "Secured securedModel may not be null");
- }
- if (seq == null)
- {
- throw new IllegalArgumentException("Seq may not be null");
- }
- final ItemHolder<Seq, SecuredSeq> holder = new ItemHolder<Seq, SecuredSeq>(
- seq);
- final SecuredSeqImpl checker = new SecuredSeqImpl(securedModel, holder);
- // if we are going to create a duplicate proxy, just return this
- // one.
- if (seq instanceof SecuredSeq)
- {
- if (checker.isEquivalent((SecuredSeq) seq))
- {
- return (SecuredSeq) seq;
- }
- }
- return holder.setSecuredItem(new SecuredItemInvoker(seq.getClass(),
- checker));
- }
-
- // the item holder that contains this SecuredSeq.
- private final ItemHolder<? extends Seq, ? extends SecuredSeq> holder;
-
- /**
- * Constructor.
- *
- * @param securedModel
- * The secured model that provides the security context
- * @param holder
- * The item holder that will contain this SecuredSeq.
- */
- protected SecuredSeqImpl( final SecuredModel securedModel,
- final ItemHolder<? extends Seq, ? extends SecuredSeq> holder )
- {
- super(securedModel, holder);
- this.holder = holder;
- }
-
- @Override
- public SecuredSeq add( final int index, final boolean o )
- {
- return add( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq add( final int index, final char o )
- {
- return add( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq add( final int index, final double o )
- {
- return add( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq add( final int index, final float o )
- {
- return add( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq add( final int index, final long o )
- {
- return add( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq add( final int index, final Object o )
- {
- return add( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq add( final int index, final RDFNode o )
- {
- checkUpdate();
- final Literal l = holder.getBaseItem().getModel().createTypedLiteral(o);
- checkCreate(index, l);
- holder.getBaseItem().add(index, o);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredSeq add( final int index, final String o )
- {
- return add( index, o, "" );
- }
-
- @Override
- public SecuredSeq add( final int index, final String o, final String l )
- {
- return add( index, holder.getBaseItem().getModel().createLiteral(o, l));
- }
-
- private void checkCreate( final int index, final Literal l )
- {
- checkCreate(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), l.asNode()));
- }
-
- private Statement containerIndexOf( final RDFNode n )
- {
- final ExtendedIterator<Statement> iter = listProperties().filterKeep(
- new RDFNodeFilter(n));
- try
- {
- if (iter.hasNext())
- {
- return iter.next();
- }
- else
- {
- return null;
- }
- }
- finally
- {
- iter.close();
- }
- }
-
- @Override
- public SecuredAlt getAlt( final int index )
- {
- checkRead();
- final Alt a = holder.getBaseItem().getAlt(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), a.asNode()));
- return SecuredAltImpl.getInstance(getModel(), a);
- }
-
- @Override
- public SecuredBag getBag( final int index )
- {
- checkRead();
- final Bag b = holder.getBaseItem().getBag(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), b.asNode()));
- return SecuredBagImpl.getInstance(getModel(), b);
- }
-
- @Override
- public boolean getBoolean( final int index )
- {
- checkRead();
- final boolean retval = holder.getBaseItem().getBoolean(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), asObject(retval).asNode()));
- return retval;
- }
-
- @Override
- public byte getByte( final int index )
- {
- checkRead();
- final byte retval = holder.getBaseItem().getByte(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), asObject(retval).asNode()));
- return retval;
- }
-
- @Override
- public char getChar( final int index )
- {
- checkRead();
- final char retval = holder.getBaseItem().getChar(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), asObject(retval).asNode()));
- return retval;
-
- }
-
- @Override
- public double getDouble( final int index )
- {
- checkRead();
- final double retval = holder.getBaseItem().getDouble(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), asObject(retval).asNode()));
- return retval;
- }
-
- @Override
- public float getFloat( final int index )
- {
- checkRead();
- final float retval = holder.getBaseItem().getFloat(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), asObject(retval).asNode()));
- return retval;
- }
-
- @Override
- public int getInt( final int index )
- {
- checkRead();
- final int retval = holder.getBaseItem().getInt(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), asObject(retval).asNode()));
- return retval;
- }
-
- @Override
- public String getLanguage( final int index )
- {
- checkRead();
- final Literal literal = holder.getBaseItem().getLiteral(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), literal.asNode()));
- return literal.getLanguage();
- }
-
- @Override
- public SecuredLiteral getLiteral( final int index )
- {
- checkRead();
- final Literal literal = holder.getBaseItem().getLiteral(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), literal.asNode()));
- return SecuredLiteralImpl.getInstance(getModel(), literal);
- }
-
- @Override
- public long getLong( final int index )
- {
- checkRead();
- final long retval = holder.getBaseItem().getLong(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), asObject(retval).asNode()));
- return retval;
- }
-
- @Override
- public SecuredRDFNode getObject( final int index )
- {
- checkRead();
- final RDFNode retval = holder.getBaseItem().getObject(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), retval.asNode()));
- return SecuredRDFNodeImpl.getInstance(getModel(), retval);
- }
-
- @Override
- public SecuredResource getResource( final int index )
- {
- checkRead();
- final Resource retval = holder.getBaseItem().getResource(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), retval.asNode()));
- return SecuredResourceImpl.getInstance(getModel(), retval);
- }
-
- @Override
- @Deprecated
- public SecuredResource getResource( final int index, final ResourceF f )
- {
- checkRead();
- final Resource retval = holder.getBaseItem().getResource(index, f);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), retval.asNode()));
- return SecuredResourceImpl.getInstance(getModel(), retval);
- }
-
- @Override
- public SecuredSeq getSeq( final int index )
- {
- checkRead();
- final Seq retval = holder.getBaseItem().getSeq(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), retval.asNode()));
- return SecuredSeqImpl.getInstance(getModel(), retval);
- }
-
- @Override
- public short getShort( final int index )
- {
- checkRead();
- final short retval = holder.getBaseItem().getShort(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), ResourceFactory.createTypedLiteral(retval).asNode()));
- return retval;
- }
-
- @Override
- public String getString( final int index )
- {
- checkRead();
- final String retval = holder.getBaseItem().getString(index);
- checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), ResourceFactory.createTypedLiteral(retval).asNode()));
- return retval;
- }
-
- @Override
- public int indexOf( final boolean o )
- {
- return indexOf( asObject( o ));
- }
-
- @Override
- public int indexOf( final char o )
- {
- return indexOf( asObject( o ));
- }
-
- @Override
- public int indexOf( final double o )
- {
- return indexOf( asObject( o ));
- }
-
- @Override
- public int indexOf( final float o )
- {
- return indexOf( asObject( o ));
- }
-
- @Override
- public int indexOf( final long o )
- {
- return indexOf( asObject( o ));
- }
-
- @Override
- public int indexOf( final Object o )
- {
- return indexOf( asObject( o ));
- }
-
- @Override
- public int indexOf( final RDFNode o )
- {
- checkRead();
- final Statement stmt = containerIndexOf(o);
- if (stmt == null)
- {
- return 0;
- }
- checkRead(stmt);
- return stmt.getPredicate().getOrdinal();
- }
-
- @Override
- public int indexOf( final String o )
- {
- return indexOf( asLiteral( o, "" ));
- }
-
- @Override
- public int indexOf( final String o, final String l )
- {
- return indexOf( asLiteral( o, l));
- }
-
- @Override
- public SecuredSeq remove( final int index )
- {
- checkUpdate();
- final RDFNode rdfNode = holder.getBaseItem().getObject(index);
- if (rdfNode != null)
- {
- checkDelete(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
- .asNode(), rdfNode.asNode()));
- holder.getBaseItem().remove(index);
- }
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredSeq set( final int index, final boolean o )
- {
- return set( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq set( final int index, final char o )
- {
- return set( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq set( final int index, final double o )
- {
- return set( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq set( final int index, final float o )
- {
- return set( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq set( final int index, final long o )
- {
- return set( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq set( final int index, final Object o )
- {
- return set( index, asObject( o ));
- }
-
- @Override
- public SecuredSeq set( final int index, final RDFNode o )
- {
- checkUpdate();
- final Triple t2 = new Triple(holder.getBaseItem().asNode(), RDF.li(
- index).asNode(), o.asNode());
- final RDFNode rdfNode = holder.getBaseItem().getObject(index);
- if (rdfNode != null)
- {
- final Triple t1 = new Triple(holder.getBaseItem().asNode(), RDF.li(
- index).asNode(), rdfNode.asNode());
- checkUpdate(t1, t2);
- }
- else
- {
- checkCreate(t2);
- }
- holder.getBaseItem().set(index, o);
- return holder.getSecuredItem();
- }
-
- @Override
- public SecuredSeq set( final int index, final String o )
- {
- return set( index, asLiteral( o, "" ));
- }
-
- @Override
- public SecuredSeq set( final int index, final String o, final String l )
- {
- return set( index, asLiteral(o, l));
- }
-}
[18/24] jena git commit: Module jena-seurity becomes jena-permissions
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRDFListImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRDFListImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRDFListImpl.java
new file mode 100644
index 0000000..86c4251
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRDFListImpl.java
@@ -0,0 +1,1058 @@
+/*
+ * 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.model.impl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.AccessDeniedException;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.security.impl.SecuredItemInvoker;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredRDFList;
+import org.apache.jena.security.model.SecuredRDFNode;
+import org.apache.jena.security.utils.RDFListIterator;
+import org.apache.jena.security.utils.RDFListSecFilter;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.Map1 ;
+import org.apache.jena.util.iterator.WrappedIterator ;
+import org.apache.jena.vocabulary.RDF ;
+
+public class SecuredRDFListImpl extends SecuredResourceImpl implements
+ SecuredRDFList
+{
+ // called plain node but still returns a secured node
+ private class PlainNodeMap implements Map1<RDFList, RDFNode>
+ {
+
+ @Override
+ public RDFNode map1( final RDFList o )
+ {
+ return SecuredRDFNodeImpl.getInstance(getModel(), o
+ .getRequiredProperty(listFirst()).getObject());
+ }
+
+ }
+
+ private class SecuredListMap implements Map1<RDFList, SecuredRDFList>
+ {
+
+ @Override
+ public SecuredRDFList map1( final RDFList o )
+ {
+ return SecuredRDFListImpl.getInstance(getModel(), o);
+ }
+
+ }
+
+ private class SecuredNodeMap implements Map1<RDFList, SecuredRDFNode>
+ {
+
+ private Property p;
+ public SecuredNodeMap(Property p)
+ {
+ this.p=p;
+ }
+
+ @Override
+ public SecuredRDFNode map1( final RDFList o )
+ {
+ return SecuredRDFNodeImpl.getInstance(getModel(), o
+ .getRequiredProperty(p).getObject());
+ }
+
+ }
+
+ /*
+ * private class SecuredRDFListIterator implements Iterator<SecuredRDFList>
+ * {
+ * private SecuredRDFList current;
+ * private Boolean found;
+ * private final Set<Action> restrictions;
+ *
+ * private SecuredRDFListIterator( final Action restriction )
+ * {
+ * this(SecurityEvaluator.Util.asSet(new Action[] { restriction }));
+ * }
+ *
+ * private SecuredRDFListIterator( final Set<Action> restrictions )
+ * {
+ * this.current = SecuredRDFListImpl.this.holder.getSecuredItem();
+ * this.restrictions = restrictions;
+ * }
+ *
+ * private boolean checkCandidate()
+ * {
+ * if (!endOfList())
+ * {
+ * final SecNode candidate = current.getRequiredProperty(listFirst())
+ * .getObject().asNode();
+ * return getSecurityEvaluator().evaluate(
+ * restrictions,
+ * getModelNode(),
+ * new SecurityEvaluator.SecTriple(SecuredItemImpl
+ * .convert(current.asNode()), SecuredItemImpl
+ * .convert(RDF.first.asNode()), SecuredItemImpl
+ * .convert(candidate)));
+ * }
+ * return false;
+ * }
+ *
+ * private boolean endOfList()
+ * {
+ * return current.equals(listNil());
+ * }
+ *
+ * @Override
+ * public boolean hasNext()
+ * {
+ * if ((found == null) && !endOfList())
+ * {
+ * found = checkCandidate();
+ * while (!found && !endOfList())
+ * {
+ * incrementCurrent();
+ * found = checkCandidate();
+ * }
+ * }
+ * return found == null ? false : found;
+ * }
+ *
+ * private void incrementCurrent()
+ * {
+ * if (!endOfList())
+ * {
+ * current = (SecuredRDFList) current
+ * .getRequiredProperty(listRest()).getResource()
+ * .as(RDFList.class);
+ * }
+ * }
+ *
+ * @Override
+ * public SecuredRDFList next()
+ * {
+ * if (hasNext())
+ * {
+ * found = null;
+ * final SecuredRDFList retval = current;
+ * incrementCurrent();
+ * return retval;
+ * }
+ * throw new NoSuchElementException();
+ * }
+ *
+ * @Override
+ * public void remove()
+ * {
+ * throw new UnsupportedOperationException();
+ * }
+ *
+ * }
+ */
+ /**
+ * Get an instance of SecuredProperty
+ *
+ * @param securedModel
+ * the Secured Model to use.
+ * @param rdfList
+ * The rdfList to secure
+ * @return The SecuredProperty
+ */
+ public static <T extends RDFList> SecuredRDFList getInstance( final SecuredModel securedModel,
+ final T rdfList )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (rdfList == null)
+ {
+ throw new IllegalArgumentException("RDFList may not be null");
+ }
+
+ // check that property has a securedModel.
+ RDFList goodList = rdfList;
+ if (goodList.getModel() == null)
+ {
+ goodList = securedModel.createList(rdfList.asJavaList().iterator());
+ }
+
+ final ItemHolder<RDFList, SecuredRDFList> holder = new ItemHolder<RDFList, SecuredRDFList>(
+ goodList);
+ final SecuredRDFListImpl checker = new SecuredRDFListImpl(securedModel,
+ holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (goodList instanceof SecuredRDFList)
+ {
+ if (checker.isEquivalent((SecuredRDFList) goodList))
+ {
+ return (SecuredRDFList) goodList;
+ }
+ }
+ return holder.setSecuredItem(new SecuredItemInvoker(rdfList.getClass(),
+ checker));
+ }
+
+ /** Error message if validity check fails */
+ protected String m_errorMsg = null;
+
+ /** Pointer to the node that is the tail of the list */
+ protected RDFList m_tail = null;
+
+ /** The URI for the 'first' property in this list */
+ protected Property m_listFirst = RDF.first;
+
+ /** The URI for the 'rest' property in this list */
+ protected Property m_listRest = RDF.rest;
+
+ /** The URI for the 'nil' Resource in this list */
+ protected Resource m_listNil = RDF.nil;
+
+ /** The URI for the rdf:type of this list */
+ protected Resource m_listType = RDF.List;
+
+ private final ItemHolder<RDFList, SecuredRDFList> holder;
+
+ protected SecuredRDFListImpl( final SecuredModel securedModel,
+ final ItemHolder<RDFList, SecuredRDFList> holder )
+ {
+ super(securedModel, holder);
+ this.holder = holder;
+ }
+
+ @Override
+ public void add( final RDFNode value )
+ {
+ checkUpdate();
+ checkCreateNewList(value, listNil());
+ holder.getBaseItem().add(value);
+ }
+
+ @Override
+ public SecuredRDFList append( final Iterator<? extends RDFNode> nodes )
+ {
+ SecuredRDFList copy = copy();
+ if (nodes.hasNext())
+ {
+ if (((RDFList)copy.getBaseItem()).size()>0)
+// if (copy.size() > 0)
+ {
+ copy.concatenate(copy.getModel().createList(nodes));
+ }
+ else
+ {
+ copy = copy.getModel().createList(nodes);
+ }
+ }
+ return copy;
+ }
+
+ @Override
+ public RDFList append( final RDFList list )
+ {
+ if (holder.getBaseItem().isEmpty())
+ {
+ return list.size() == 0 ? ModelFactory.createDefaultModel()
+ .createList() : list.copy();
+ }
+ else
+ {
+ final RDFList copy = copy();
+ if (list.size() > 0)
+ {
+ copy.concatenate(list.copy());
+ }
+ return copy;
+ }
+ }
+
+ @Override
+ public void apply( final ApplyFn fn )
+ {
+ // iterator() checks Read
+ final ExtendedIterator<RDFNode> i = iterator();
+ try
+ {
+ while (i.hasNext())
+ {
+ fn.apply(i.next());
+ }
+ }
+ finally
+ {
+ i.close();
+ }
+ }
+
+ @Override
+ public void apply( final Set<Action> perms, final ApplyFn fn )
+ {
+ // iterator() checks Read
+ final ExtendedIterator<RDFNode> i = iterator(perms);
+ try
+ {
+ while (i.hasNext())
+ {
+ fn.apply(i.next());
+ }
+ }
+ finally
+ {
+ i.close();
+ }
+ }
+
+ @Override
+ public List<RDFNode> asJavaList()
+ {
+ // iterator() checks Read
+ return iterator().toList();
+ }
+
+ /**
+ * Removes val from underlying list.
+ *
+ * @param val
+ * @return the modified RDFList.
+ */
+ private RDFList baseRemove( final RDFList val )
+ {
+
+ RDFList prev = null;
+ RDFList cell = holder.getBaseItem();
+ final boolean searching = true;
+
+ while (searching && !cell.isEmpty())
+ {
+ if (cell.equals(val))
+ {
+ // found the value to be removed
+ final RDFList tail = cell.getTail();
+ if (prev != null)
+ {
+ prev.setTail(tail);
+ }
+
+ cell.removeProperties();
+
+ // return this unless we have removed the head element
+ return (prev == null) ? tail : this;
+ }
+ else
+ {
+ // not found yet
+ prev = cell;
+ cell = cell.getTail();
+ }
+ }
+
+ // not found
+ return this;
+ }
+
+ private void checkCreateNewList( final RDFNode value, final Resource tail )
+ {
+ checkCreate(new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(listFirst().asNode()),
+ SecuredItemImpl.convert(value.asNode())));
+ checkCreate(new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(listRest().asNode()),
+ SecuredItemImpl.convert(tail.asNode())));
+ }
+
+ private Set<Statement> collectStatements( final Set<Action> actions )
+ {
+ final Set<Statement> stmts = new HashSet<Statement>();
+ final ExtendedIterator<RDFList> iter = WrappedIterator.create(
+ new RDFListIterator(holder.getBaseItem())).filterKeep(
+ new RDFListSecFilter<RDFList>(this, actions));
+ try
+ {
+ while (iter.hasNext())
+ {
+ stmts.addAll(iter.next().listProperties().toSet());
+ }
+ return stmts;
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public void concatenate( final Iterator<? extends RDFNode> nodes )
+ {
+ checkUpdate();
+ if (holder.getBaseItem().isEmpty())
+ {
+ // concatenating list onto the empty list is an error
+ throw new EmptyListUpdateException(
+ "Tried to concatenate onto the empty list");
+ }
+ else
+ {
+ final org.apache.jena.security.SecurityEvaluator.SecNode p = SecuredItemImpl
+ .convert(listFirst().asNode());
+ org.apache.jena.security.SecurityEvaluator.SecTriple t = new org.apache.jena.security.SecurityEvaluator.SecTriple(
+ org.apache.jena.security.SecurityEvaluator.SecNode.FUTURE,
+ p, org.apache.jena.security.SecurityEvaluator.SecNode.ANY);
+ if (!canCreate(t))
+ {
+ final List<RDFNode> list = new ArrayList<RDFNode>();
+ while (nodes.hasNext())
+ {
+ final RDFNode n = nodes.next();
+ t = new org.apache.jena.security.SecurityEvaluator.SecTriple(
+ org.apache.jena.security.SecurityEvaluator.SecNode.FUTURE,
+ p, SecuredItemImpl.convert(n.asNode()));
+ checkCreate(t);
+ list.add(n);
+ }
+ holder.getBaseItem().concatenate(list.iterator());
+
+ }
+ else
+ {
+ holder.getBaseItem().concatenate(nodes);
+ }
+ }
+ }
+
+ @Override
+ public void concatenate( final RDFList list )
+ {
+ checkUpdate();
+ if (holder.getBaseItem().isEmpty())
+ {
+ // concatenating list onto the empty list is an error
+ throw new EmptyListUpdateException(
+ "Tried to concatenate onto the empty list");
+ }
+ else
+ {
+ final org.apache.jena.security.SecurityEvaluator.SecNode p = SecuredItemImpl
+ .convert(listFirst().asNode());
+ org.apache.jena.security.SecurityEvaluator.SecTriple t = new org.apache.jena.security.SecurityEvaluator.SecTriple(
+ org.apache.jena.security.SecurityEvaluator.SecNode.FUTURE,
+ p, org.apache.jena.security.SecurityEvaluator.SecNode.ANY);
+ if (!canCreate(t))
+ {
+ final ExtendedIterator<RDFNode> iter = list.iterator();
+ try
+ {
+ while (iter.hasNext())
+ {
+ t = new org.apache.jena.security.SecurityEvaluator.SecTriple(
+ org.apache.jena.security.SecurityEvaluator.SecNode.FUTURE,
+ p, SecuredItemImpl
+ .convert(iter.next().asNode()));
+ checkCreate(t);
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ holder.getBaseItem().concatenate(list);
+ }
+ }
+
+ @Override
+ public SecuredRDFList cons( final RDFNode value )
+ {
+ checkUpdate();
+ checkCreateNewList(value, holder.getBaseItem());
+ return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem()
+ .cons(value));
+ }
+
+ @Override
+ public boolean contains( final RDFNode value )
+ {
+ // iterator() checks Read
+ final ExtendedIterator<RDFNode> iter = iterator();
+ try
+ {
+ while (iter.hasNext())
+ {
+ if (value.equals(iter.next()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public SecuredRDFList copy()
+ {
+ SecuredRDFList retval = null;
+ if (canRead())
+ {
+ final ExtendedIterator<RDFNode> iter = getSecuredRDFListIterator(Action.Read)
+ .mapWith( new Map1<RDFList, RDFNode>()
+ {
+
+ @Override
+ public RDFNode map1( final RDFList o )
+ {
+ return o.getRequiredProperty(listFirst()).getObject();
+ }
+
+ });
+ if (iter.hasNext())
+ {
+ retval = getModel().createList(iter);
+ }
+ else
+ {
+ retval = getModel().createList();
+ }
+ }
+ else
+ {
+ retval = getModel().createList();
+ }
+ return retval;
+ }
+
+ @Override
+ public SecuredRDFNode get( final int i )
+ {
+ checkRead();
+ final ExtendedIterator<SecuredRDFNode> iter = getSecuredRDFListIterator(
+ Action.Read).mapWith(new SecuredNodeMap(listFirst()));
+ int idx = 0;
+ try
+ {
+ while (iter.hasNext())
+ {
+ if (i == idx)
+ {
+ return iter.next();
+ }
+ else
+ {
+ idx++;
+ iter.next();
+ }
+
+ }
+ throw new ListIndexException();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public SecuredRDFNode getHead()
+ {
+ checkRead();
+ Statement s = holder.getBaseItem().getRequiredProperty( listFirst() );
+ checkRead( s );
+ return SecuredRDFNodeImpl.getInstance(getModel(), s.getObject());
+ }
+
+ private ExtendedIterator<RDFList> getSecuredRDFListIterator(
+ final Action perm )
+ {
+ return WrappedIterator
+ .create(new RDFListIterator(holder.getBaseItem())).filterKeep(
+ new RDFListSecFilter<RDFList>(this, perm));
+ }
+
+ private ExtendedIterator<RDFList> getSecuredRDFListIterator(
+ final Set<Action> perm )
+ {
+ return WrappedIterator
+ .create(new RDFListIterator(holder.getBaseItem())).filterKeep(
+ new RDFListSecFilter<RDFList>(this, perm));
+ }
+
+ @Override
+ public boolean getStrict()
+ {
+ return holder.getBaseItem().getStrict();
+ }
+
+ @Override
+ public SecuredRDFList getTail()
+ {
+ checkRead();
+ Statement s = holder.getBaseItem().getRequiredProperty( listRest() );
+ checkRead( s );
+ return SecuredRDFListImpl.getInstance(getModel(), s.getObject().as(RDFList.class));
+ }
+
+ @Override
+ public String getValidityErrorMessage()
+ {
+ checkRead();
+ return holder.getBaseItem().getValidityErrorMessage();
+ }
+
+ @Override
+ public int indexOf( final RDFNode value )
+ {
+ checkRead();
+ final ExtendedIterator<SecuredRDFNode> iter = getSecuredRDFListIterator(
+ Action.Read).mapWith(new SecuredNodeMap(listFirst()));
+ try
+ {
+ int retval = 0;
+ while (iter.hasNext())
+ {
+ if (value.equals(iter.next()))
+ {
+ return retval;
+ }
+ else
+ {
+ retval++;
+ }
+ }
+ return -1;
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public int indexOf( final RDFNode value, final int start )
+ {
+ checkRead();
+ final ExtendedIterator<SecuredRDFNode> iter = getSecuredRDFListIterator(
+ Action.Read).mapWith(new SecuredNodeMap(listFirst()));
+ try
+ {
+ int retval = 0;
+ while (iter.hasNext() && (retval < start))
+ {
+ iter.next();
+ retval++;
+ }
+ while (iter.hasNext())
+ {
+ if (value.equals(iter.next()))
+ {
+ return retval;
+ }
+ else
+ {
+ retval++;
+ }
+ }
+ return -1;
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ checkRead();
+ final ExtendedIterator<RDFNode> iter = iterator();
+ try
+ {
+ return !iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public boolean isValid()
+ {
+ checkRead();
+ return holder.getBaseItem().isValid();
+ }
+
+ @Override
+ public ExtendedIterator<RDFNode> iterator()
+ {
+ checkRead();
+ return getSecuredRDFListIterator(Action.Read).mapWith(
+ new PlainNodeMap());
+
+ }
+
+ @Override
+ public ExtendedIterator<RDFNode> iterator( final Set<Action> constraints )
+ {
+ checkRead();
+ final Set<Action> req = new HashSet<Action>(constraints);
+ req.add(Action.Read);
+ return getSecuredRDFListIterator(req).mapWith(new PlainNodeMap());
+
+ }
+
+ public Class<? extends RDFList> listAbstractionClass()
+ {
+ return RDFList.class;
+ }
+
+ public Property listFirst()
+ {
+ return m_listFirst;
+ }
+
+ public Resource listNil()
+ {
+ return m_listNil;
+ }
+
+ public Property listRest()
+ {
+ return m_listRest;
+ }
+
+ public Resource listType()
+ {
+ return m_listType;
+ }
+
+ @Override
+ public <T> ExtendedIterator<T> mapWith( final Map1<RDFNode, T> fn )
+ {
+ return iterator().mapWith(fn);
+ }
+
+ @Override
+ public Object reduce( final ReduceFn fn, final Object initial )
+ {
+ Object acc = initial;
+
+ for (final Iterator<RDFNode> i = iterator(); i.hasNext();)
+ {
+ acc = fn.reduce(i.next(), acc);
+ }
+
+ return acc;
+ }
+
+ @Override
+ public Object reduce( final Set<Action> requiredActions, final ReduceFn fn,
+ final Object initial ) throws AccessDeniedException,
+ EmptyListException, ListIndexException, InvalidListException
+ {
+ Object acc = initial;
+ final Set<Action> perms = new HashSet<Action>(requiredActions);
+ perms.add(Action.Read);
+ for (final Iterator<RDFNode> i = iterator(perms); i.hasNext();)
+ {
+ acc = fn.reduce(i.next(), acc);
+ }
+
+ return acc;
+ }
+
+ @Override
+ public RDFList remove( final RDFNode val )
+ {
+ checkUpdate();
+ RDFList cell = null;
+ boolean denied = false;
+
+ if (!canDelete(new Triple(Node.ANY, listFirst().asNode(), val.asNode())))
+ {
+ // iterate over the deletable items
+ final ExtendedIterator<RDFList> iter = getSecuredRDFListIterator(Action.Delete);// .mapWith(new
+ // SecuredListMap());
+ while (iter.hasNext())
+ {
+ cell = iter.next();
+
+ if (val.equals(cell.getRequiredProperty(listFirst())
+ .getObject()))
+ {
+ if (canDelete(new Triple(cell.asNode(), listFirst()
+ .asNode(), val.asNode())))
+ {
+ return SecuredRDFListImpl.getInstance(getModel(),
+ baseRemove(cell));
+
+ }
+ else
+ {
+ denied = true;
+ }
+ }
+ }
+ if (denied)
+ {
+ throw new AccessDeniedException(getModelNode(), Action.Delete);
+ }
+ else
+ {
+ return this;
+ }
+ }
+ else
+ {
+ return SecuredRDFListImpl.getInstance(getModel(), holder
+ .getBaseItem().remove(val));
+ }
+ }
+
+ @Override
+ @Deprecated
+ public void removeAll()
+ {
+ removeList();
+ }
+
+ @Override
+ public SecuredRDFList removeHead()
+ {
+ checkUpdate();
+ final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator(
+ Action.Read).mapWith(new SecuredListMap());
+ try
+ {
+ if (!iter.hasNext())
+ {
+ throw new EmptyListException(
+ "Attempted to delete the head of a nil list");
+ }
+ final SecuredRDFList cell = iter.next();
+ final Statement s = cell.getRequiredProperty(RDF.first);
+ checkDelete(s);
+ return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell));
+
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public void removeList()
+ {
+ checkUpdate();
+ final Triple t = new Triple(Node.ANY, listFirst().asNode(), Node.ANY);
+ /*
+ * if (!canRead(t))
+ * {
+ * throw new EmptyListException(
+ * "Attempted to delete the head of a nil list" );
+ * }
+ */
+ // have to be able to read and delete to delete all.
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
+ Action.Delete, Action.Read });
+ if (getSecurityEvaluator().evaluate(getSecurityEvaluator().getPrincipal(), perms, this.getModelNode(),
+ SecuredItemImpl.convert(t)))
+ {
+ holder.getBaseItem().removeList();
+ }
+ else
+ {
+ for (final Statement s : collectStatements(perms))
+ {
+ if (canDelete(s.asTriple()))
+ {
+ s.remove();
+ }
+ }
+ }
+ }
+
+ @Override
+ public SecuredRDFNode replace( final int i, final RDFNode value )
+ {
+ checkUpdate();
+ final SecuredNodeMap map = new SecuredNodeMap(listFirst());
+ final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator(
+ Action.Read).mapWith(new SecuredListMap());
+ int idx = 0;
+ try
+ {
+ while (iter.hasNext())
+ {
+ if (i == idx)
+ {
+ final SecuredRDFList list = iter.next();
+ final SecuredRDFNode retval = map.map1(list);
+ final Triple t = new Triple(list.asNode(), listFirst()
+ .asNode(), retval.asNode());
+ final Triple t2 = new Triple(list.asNode(), listFirst()
+ .asNode(), value.asNode());
+ checkUpdate(t, t2);
+ final RDFList base = (RDFList) list.getBaseItem();
+ base.getRequiredProperty(listFirst()).changeObject(value);
+ return retval;
+ }
+ else
+ {
+ idx++;
+ iter.next();
+ }
+
+ }
+ throw new ListIndexException();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public boolean sameListAs( final RDFList list )
+ {
+ checkRead();
+ ExtendedIterator<RDFNode> thisIter = null;
+ ExtendedIterator<RDFNode> thatIter = null;
+ try
+ {
+ thisIter = iterator();
+ thatIter = list.iterator();
+ while (thisIter.hasNext() && thatIter.hasNext())
+ {
+ final RDFNode thisN = thisIter.next();
+ final RDFNode thatN = thatIter.next();
+ if ((thisN == null) || !thisN.equals(thatN))
+ {
+ // not equal at this position
+ return false;
+ }
+ }
+ return !(thisIter.hasNext() || thatIter.hasNext());
+ }
+ finally
+ {
+ if (thisIter != null)
+ {
+ thisIter.close();
+ }
+ if (thatIter != null)
+ {
+ thatIter.close();
+ }
+ }
+ }
+
+ @Override
+ public SecuredRDFNode setHead( final RDFNode value )
+ {
+ final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator(
+ Action.Read).mapWith(new SecuredListMap());
+ try
+ {
+ if (iter.hasNext())
+ {
+ return replace(0, value);
+ }
+ else
+ {
+ throw new EmptyListException(
+ "Tried to set the head of an empty list");
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public void setStrict( final boolean strict )
+ {
+ checkUpdate();
+ holder.getBaseItem().setStrict(strict);
+ }
+
+ @Override
+ public SecuredRDFList setTail( final RDFList tail )
+ {
+ checkUpdate();
+
+ final Statement rest = holder.getBaseItem().getRequiredProperty(
+ listRest());
+ final RDFNode retval = rest.getObject();
+ final Triple t = new Triple(holder.getBaseItem().asNode(), listRest()
+ .asNode(), retval.asNode());
+ final Triple t2 = new Triple(holder.getBaseItem().asNode(), listRest()
+ .asNode(), tail.asNode());
+ checkUpdate(t, t2);
+ rest.changeObject(tail);
+ return SecuredRDFListImpl.getInstance(getModel(),
+ retval.as(RDFList.class));
+ }
+
+ @Override
+ public int size()
+ {
+ checkRead();
+ final Triple t = new Triple(Node.ANY, listFirst().asNode(), Node.ANY);
+ if (canRead(t))
+ {
+ return holder.getBaseItem().size();
+ }
+ final ExtendedIterator<RDFNode> iter = iterator();
+ int i = 0;
+ while (iter.hasNext())
+ {
+ i++;
+ iter.next();
+ }
+ return i;
+ }
+
+ @Override
+ public SecuredRDFList with( final RDFNode value )
+ {
+ checkUpdate();
+ checkCreate(new SecurityEvaluator.SecTriple(
+ SecurityEvaluator.SecNode.FUTURE,
+ SecuredItemImpl.convert(listFirst().asNode()),
+ SecuredItemImpl.convert(value.asNode())));
+ return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem()
+ .with(value));
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRDFNodeImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRDFNodeImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRDFNodeImpl.java
new file mode 100644
index 0000000..f538653
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRDFNodeImpl.java
@@ -0,0 +1,253 @@
+/*
+ * 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.model.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.jena.enhanced.UnsupportedPolymorphismException ;
+import org.apache.jena.graph.FrontsNode ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.rdf.model.Literal ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.RDFNode ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredRDFNode;
+import org.apache.jena.security.model.SecuredUnsupportedPolymorphismException;
+
+/**
+ * Implementation of SecuredRDFNode to be used by a SecuredItemInvoker proxy.
+ */
+public abstract class SecuredRDFNodeImpl extends SecuredItemImpl implements
+ SecuredRDFNode
+{
+ /**
+ *
+ * @param securedModel
+ * the Secured Model to use.
+ * @param rdfNode the node to secure.
+ * @return the secured RDFNode
+ */
+ public static SecuredRDFNode getInstance( final SecuredModel securedModel,
+ final RDFNode rdfNode )
+ {
+ if (rdfNode instanceof Literal)
+ {
+ return SecuredLiteralImpl.getInstance(securedModel,
+ (Literal) rdfNode);
+ }
+ else
+ {
+ return SecuredResourceImpl.getInstance(securedModel,
+ (Resource) rdfNode);
+ }
+ }
+
+ // the item holder that contains this SecuredRDFNode
+ private final ItemHolder<? extends RDFNode, ? extends SecuredRDFNode> holder;
+
+ // the secured securedModel that contains this node.
+ private final SecuredModel securedModel;
+
+ /**
+ * Constructor
+ *
+ * @param securedModel
+ * the Secured Model to use.
+ * @param holder
+ * the item holder that will contain this SecuredRDFNode.
+ */
+ protected SecuredRDFNodeImpl( final SecuredModel securedModel,
+ final ItemHolder<? extends RDFNode, ? extends SecuredRDFNode> holder )
+ {
+ super(securedModel, holder);
+ if (holder.getBaseItem().getModel() == null)
+ {
+ throw new IllegalArgumentException(String.format(
+ "Holder base item (%s) must have a securedModel", holder
+ .getBaseItem().getClass()));
+ }
+ this.securedModel = securedModel;
+ this.holder = holder;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ @Override
+ public <T extends RDFNode> T as( final Class<T> view )
+ {
+ checkRead();
+ // see if the base Item can as
+ T baseAs = holder.getBaseItem().as(view);
+
+ if (view.equals(SecuredRDFNodeImpl.class)
+ || view.equals(RDFNode.class))
+ {
+ return (T) this;
+ }
+ final Method m = getConstructor(view);
+ if (m == null)
+ {
+ throw new SecuredUnsupportedPolymorphismException(this, view);
+ }
+ try
+ {
+ return (T) m.invoke(null, securedModel, holder.getBaseItem()
+ .as(view));
+ }
+ catch (final UnsupportedPolymorphismException e)
+ {
+ throw new SecuredUnsupportedPolymorphismException(this, view);
+ }
+ catch (final IllegalArgumentException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (final IllegalAccessException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (final InvocationTargetException e)
+ {
+ throw new RuntimeException(e);
+ }
+ /*
+ else
+ {
+ throw new SecuredUnsupportedPolymorphismException(this, view);
+ }
+ */
+ }
+
+ @Override
+ public Node asNode()
+ {
+ checkRead();
+ return holder.getBaseItem().asNode();
+ }
+
+ @Override
+ public <T extends RDFNode> boolean canAs( final Class<T> view )
+ {
+ checkRead();
+ // see if the base Item can as
+ if (holder.getBaseItem().canAs(view))
+ {
+ return getConstructor(view) != null;
+ }
+ return false;
+ }
+
+ private <T extends RDFNode> Method getConstructor( final Class<T> view )
+ {
+ String classNm = SecuredRDFNodeImpl.class.getName();
+ classNm = String.format("%s.Secured%sImpl",
+ classNm.substring(0, classNm.lastIndexOf(".")),
+ view.getSimpleName());
+ try
+ {
+ final Class<?> c = Class.forName(classNm);
+ return c.getDeclaredMethod("getInstance", SecuredModel.class, view);
+ }
+ catch (final ClassNotFoundException e)
+ {
+ return null;
+ }
+ catch (final SecurityException e)
+ {
+ return null;
+ }
+ catch (final NoSuchMethodException e)
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public SecuredModel getModel()
+ {
+ return securedModel;
+ }
+
+ @Override
+ public RDFNode inModel( final Model m )
+ {
+ checkRead();
+ if (securedModel.equals(m))
+ {
+ return this;
+ }
+ if (m instanceof SecuredModel)
+ {
+ return SecuredRDFNodeImpl.getInstance((SecuredModel) m, holder
+ .getBaseItem().inModel(m));
+ }
+ return holder.getBaseItem().inModel(m);
+ }
+
+ @Override
+ public boolean isAnon()
+ {
+ return holder.getBaseItem().isAnon();
+ }
+
+ @Override
+ public boolean isLiteral()
+ {
+ return holder.getBaseItem().isLiteral();
+ }
+
+ @Override
+ public boolean isResource()
+ {
+ return holder.getBaseItem().isResource();
+ }
+
+ @Override
+ public boolean isURIResource()
+ {
+ return holder.getBaseItem().isURIResource();
+ }
+
+ /**
+ * An RDFNode is equal to another enhanced node n iff the underlying
+ * nodes are equal. We generalise to allow the other object to be any class
+ * implementing asNode, because we allow other implemementations of
+ * Resource, at least in principle.
+ * This is deemed to be a complete and correct interpretation of RDFNode
+ * equality, which is why this method has been marked final.
+ *
+ * @param o An object to test for equality with this node
+ * @return True if o is equal to this node.
+ */
+ @Override final public boolean equals( Object o )
+ {
+ checkRead();
+ return o instanceof FrontsNode && asNode().equals(((FrontsNode) o).asNode());
+ }
+
+ /**
+ * The hash code of an RDFnode is defined to be the same as the underlying node.
+ * @return The hashcode as an int
+ */
+ @Override final public int hashCode() {
+ return holder.getBaseItem().asNode().hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRSIterator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRSIterator.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRSIterator.java
new file mode 100644
index 0000000..a52da02
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredRSIterator.java
@@ -0,0 +1,174 @@
+/*
+ * 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.model.impl;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jena.rdf.model.RSIterator ;
+import org.apache.jena.rdf.model.ReifiedStatement ;
+import org.apache.jena.security.SecurityEvaluator;
+import org.apache.jena.security.SecurityEvaluator.Action;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.impl.SecuredItemImpl;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.Filter ;
+import org.apache.jena.util.iterator.Map1 ;
+
+/**
+ * A secured RSIterator implementation
+ */
+public class SecuredRSIterator implements RSIterator
+{
+ private class PermReifiedStatementFilter extends Filter<ReifiedStatement>
+ {
+ private final SecurityEvaluator evaluator;
+ private final SecNode modelNode;
+ private final Set<Action> actions;
+
+ public PermReifiedStatementFilter( final Action[] actions,
+ final SecuredModel securedModel )
+ {
+ this.modelNode = securedModel.getModelNode();
+ this.actions = SecurityEvaluator.Util.asSet(actions);
+ this.evaluator = securedModel.getSecurityEvaluator();
+ }
+
+ @Override
+ public boolean accept( final ReifiedStatement t )
+ {
+ return evaluator.evaluateAny(evaluator.getPrincipal(), actions, modelNode,
+ SecuredItemImpl.convert(t.getStatement().asTriple()));
+ }
+
+ }
+
+ private class PermReifiedStatementMap implements
+ Map1<ReifiedStatement, ReifiedStatement>
+ {
+ private final SecuredModel securedModel;
+
+ public PermReifiedStatementMap( final SecuredModel securedModel )
+ {
+ this.securedModel = securedModel;
+ }
+
+ @Override
+ public ReifiedStatement map1( final ReifiedStatement o )
+ {
+ return SecuredReifiedStatementImpl.getInstance(securedModel, o);
+ }
+ }
+
+ private final ExtendedIterator<ReifiedStatement> iter;
+
+ /**
+ * Constructor
+ *
+ * @param securedModel
+ * The secured model that provides the security context
+ * @param wrapped
+ * The wrapped iterator.
+ */
+ public SecuredRSIterator( final SecuredModel securedModel,
+ final ExtendedIterator<ReifiedStatement> wrapped )
+ {
+ final PermReifiedStatementFilter filter = new PermReifiedStatementFilter(
+ new Action[] { Action.Read }, securedModel);
+ final PermReifiedStatementMap map1 = new PermReifiedStatementMap(
+ securedModel);
+ iter = wrapped.filterKeep(filter).mapWith(map1);
+ }
+
+ @Override
+ public <X extends ReifiedStatement> ExtendedIterator<ReifiedStatement> andThen(
+ final Iterator<X> other )
+ {
+ return iter.andThen(other);
+ }
+
+ @Override
+ public void close()
+ {
+ iter.close();
+ }
+
+ @Override
+ public ExtendedIterator<ReifiedStatement> filterDrop(
+ final Filter<ReifiedStatement> f )
+ {
+ return iter.filterDrop(f);
+ }
+
+ @Override
+ public ExtendedIterator<ReifiedStatement> filterKeep(
+ final Filter<ReifiedStatement> f )
+ {
+ return iter.filterKeep(f);
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return iter.hasNext();
+ }
+
+ @Override
+ public <U> ExtendedIterator<U> mapWith( final Map1<ReifiedStatement, U> map1 )
+ {
+ return iter.mapWith(map1);
+ }
+
+ @Override
+ public ReifiedStatement next()
+ {
+ return iter.next();
+ }
+
+ @Override
+ public ReifiedStatement nextRS()
+ {
+ return next();
+ }
+
+ @Override
+ public void remove()
+ {
+ iter.remove();
+ }
+
+ @Override
+ public ReifiedStatement removeNext()
+ {
+ return iter.removeNext();
+ }
+
+ @Override
+ public List<ReifiedStatement> toList()
+ {
+ return iter.toList();
+ }
+
+ @Override
+ public Set<ReifiedStatement> toSet()
+ {
+ return iter.toSet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredReifiedStatementImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredReifiedStatementImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredReifiedStatementImpl.java
new file mode 100644
index 0000000..a357b55
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredReifiedStatementImpl.java
@@ -0,0 +1,99 @@
+/*
+ * 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.model.impl;
+
+import org.apache.jena.rdf.model.ReifiedStatement ;
+import org.apache.jena.security.impl.ItemHolder;
+import org.apache.jena.security.impl.SecuredItemInvoker;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredReifiedStatement;
+import org.apache.jena.security.model.SecuredStatement;
+
+/**
+ * Implementation of SecuredReifiedStatement to be used by a SecuredItemInvoker
+ * proxy.
+ */
+public class SecuredReifiedStatementImpl extends SecuredResourceImpl implements
+ SecuredReifiedStatement
+{
+ /**
+ * Get an instance of SecuredReifiedStatement
+ *
+ * @param securedModel
+ * the Secured Model to use.
+ * @param stmt
+ * The ReifiedStatement to secure.
+ * @return SecuredReifiedStatement
+ */
+ public static SecuredReifiedStatement getInstance(
+ final SecuredModel securedModel, final ReifiedStatement stmt )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (stmt == null)
+ {
+ throw new IllegalArgumentException("Statement may not be null");
+ }
+ final ItemHolder<ReifiedStatement, SecuredReifiedStatement> holder = new ItemHolder<ReifiedStatement, SecuredReifiedStatement>(
+ stmt);
+ final SecuredReifiedStatementImpl checker = new SecuredReifiedStatementImpl(
+ securedModel, holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (stmt instanceof SecuredReifiedStatement)
+ {
+ if (checker.isEquivalent((SecuredReifiedStatement) stmt))
+ {
+ return (SecuredReifiedStatement) stmt;
+ }
+ }
+ return holder.setSecuredItem(new SecuredItemInvoker(stmt.getClass(),
+ checker));
+ }
+
+ // the item holder that contains this SecuredResource
+ private final ItemHolder<? extends ReifiedStatement, ? extends SecuredReifiedStatement> holder;
+
+ /**
+ * Constructor
+ *
+ * @param securedModel
+ * The secured model to use
+ * @param holder
+ * the item holder that will contain this SecuredReifiedStatement
+ */
+ protected SecuredReifiedStatementImpl(
+ final SecuredModel securedModel,
+ final ItemHolder<? extends ReifiedStatement, ? extends SecuredReifiedStatement> holder )
+ {
+ super(securedModel, holder);
+ this.holder = holder;
+ }
+
+ @Override
+ public SecuredStatement getStatement()
+ {
+ checkRead();
+ return SecuredStatementImpl.getInstance(getModel(), holder
+ .getBaseItem().getStatement());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredResIterator.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredResIterator.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredResIterator.java
new file mode 100644
index 0000000..338c389
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredResIterator.java
@@ -0,0 +1,133 @@
+/*
+ * 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.model.impl;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jena.rdf.model.ResIterator ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.security.model.SecuredModel;
+import org.apache.jena.security.model.SecuredResource;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.Filter ;
+import org.apache.jena.util.iterator.Map1 ;
+
+public class SecuredResIterator implements ResIterator
+{
+
+ private class PermResourceMap implements Map1<Resource, Resource>
+ {
+ private final SecuredModel securedModel;
+
+ public PermResourceMap( final SecuredModel securedModel )
+ {
+ this.securedModel = securedModel;
+ }
+
+ @Override
+ public SecuredResource map1( final Resource o )
+ {
+ return SecuredResourceImpl.getInstance(securedModel, o);
+ }
+ }
+
+ private final ExtendedIterator<Resource> iter;
+
+ public SecuredResIterator( final SecuredModel securedModel,
+ final ExtendedIterator<Resource> wrapped)
+ {
+
+ final PermResourceMap map1 = new PermResourceMap(securedModel);
+ iter = wrapped.mapWith(map1);
+ }
+
+ @Override
+ public <X extends Resource> ExtendedIterator<Resource> andThen(
+ final Iterator<X> other )
+ {
+ return iter.andThen(other);
+ }
+
+ @Override
+ public void close()
+ {
+ iter.close();
+ }
+
+ @Override
+ public ExtendedIterator<Resource> filterDrop( final Filter<Resource> f )
+ {
+ return iter.filterDrop(f);
+ }
+
+ @Override
+ public ExtendedIterator<Resource> filterKeep( final Filter<Resource> f )
+ {
+ return iter.filterKeep(f);
+ }
+
+ @Override
+ public boolean hasNext()
+ {
+ return iter.hasNext();
+ }
+
+ @Override
+ public <U> ExtendedIterator<U> mapWith( final Map1<Resource, U> map1 )
+ {
+ return iter.mapWith(map1);
+ }
+
+ @Override
+ public Resource next()
+ {
+ return iter.next();
+ }
+
+ @Override
+ public Resource nextResource()
+ {
+ return next();
+ }
+
+ @Override
+ public void remove()
+ {
+ iter.remove();
+ }
+
+ @Override
+ public Resource removeNext()
+ {
+ return iter.removeNext();
+ }
+
+ @Override
+ public List<Resource> toList()
+ {
+ return iter.toList();
+ }
+
+ @Override
+ public Set<Resource> toSet()
+ {
+ return iter.toSet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredResourceImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredResourceImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredResourceImpl.java
new file mode 100644
index 0000000..4a8dc70
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredResourceImpl.java
@@ -0,0 +1,893 @@
+/*
+ * 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.model.impl;
+
+import org.apache.jena.datatypes.RDFDatatype ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.AccessDeniedException ;
+import org.apache.jena.security.SecurityEvaluator.Action ;
+import org.apache.jena.security.impl.ItemHolder ;
+import org.apache.jena.security.impl.SecuredItemImpl ;
+import org.apache.jena.security.impl.SecuredItemInvoker ;
+import org.apache.jena.security.model.SecuredModel ;
+import org.apache.jena.security.model.SecuredResource ;
+import org.apache.jena.security.model.SecuredStatement ;
+import org.apache.jena.security.utils.PermStatementFilter ;
+import org.apache.jena.shared.PropertyNotFoundException ;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+
+/**
+ * Implementation of SecuredResource to be used by a SecuredItemInvoker proxy.
+ */
+public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
+ SecuredResource
+{
+ /**
+ * Get a SecuredResource.
+ *
+ * @param securedModel
+ * the securedItem that provides the security context.
+ * @param resource
+ * The resource to secure.
+ * @return The SecuredResource
+ */
+ public static SecuredResource getInstance( final SecuredModel securedModel,
+ final Resource resource )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (resource == null)
+ {
+ throw new IllegalArgumentException("Resource may not be null");
+ }
+ if (resource.isLiteral())
+ {
+ throw new IllegalArgumentException("Resource may not be a literal");
+ }
+ // check that resource has a securedModel.
+ Resource goodResource = resource;
+ if (goodResource.getModel() == null)
+ {
+ final Node n = resource.asNode();
+ if (resource.isAnon())
+ {
+ goodResource = securedModel.createResource(n.getBlankNodeId());
+ }
+ else
+ {
+ goodResource = securedModel.createResource(n.getURI());
+ }
+ }
+
+ final ItemHolder<Resource, SecuredResource> holder = new ItemHolder<Resource, SecuredResource>(
+ goodResource);
+
+ final SecuredResourceImpl checker = new SecuredResourceImpl(
+ securedModel, holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (goodResource instanceof SecuredResource)
+ {
+ if (checker.isEquivalent((SecuredResource) goodResource))
+ {
+ return (SecuredResource) goodResource;
+ }
+ }
+
+ return holder.setSecuredItem(new SecuredItemInvoker(
+ resource.getClass(), checker));
+
+ }
+
+ // the item holder that contains this SecuredResource
+ private final ItemHolder<? extends Resource, ? extends SecuredResource> holder;
+
+ /**
+ * Constructor.
+ *
+ * @param securedModel
+ * The secured model to use
+ * @param holder
+ * the item holder that will contain this SecuredResource.
+ */
+ protected SecuredResourceImpl(
+ final SecuredModel securedModel,
+ final ItemHolder<? extends Resource, ? extends SecuredResource> holder )
+ {
+ super(securedModel, holder);
+ this.holder = holder;
+ }
+
+ /**
+ * Abort the transaction in the associated securedModel.
+ *
+ * @return This resource to permit cascading.
+ */
+ @Override
+ public SecuredResource abort()
+ {
+ holder.getBaseItem().abort();
+ return holder.getSecuredItem();
+ }
+
+ /**
+ * Add the property <code>p</code> with the typed-literal value
+ * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
+ * this's securedModel. Answer
+ * this resource. The typed literal is equal to one constructed by using
+ * <code>this.getModel().createTypedLiteral(o)</code>.
+ */
+ @Override
+ public SecuredResource addLiteral( final Property p, final boolean o )
+ {
+ return addProperty( p, ResourceFactory.createTypedLiteral(o) );
+ }
+
+ /**
+ * Add the property <code>p</code> with the typed-literal value
+ * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
+ * this's securedModel. Answer
+ * this resource. The typed literal is equal to one constructed by using
+ * <code>this.getModel().createTypedLiteral(o)</code>.
+ */
+ @Override
+ public SecuredResource addLiteral( final Property p, final char o )
+ {
+ return addProperty( p, ResourceFactory.createTypedLiteral(o));
+ }
+
+ /**
+ * Add the property <code>p</code> with the typed-literal value
+ * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
+ * this's securedModel. Answer
+ * this resource. The typed literal is equal to one constructed by using
+ * <code>this.getModel().createTypedLiteral(o)</code>.
+ */
+ @Override
+ public SecuredResource addLiteral( final Property value, final double d )
+ {
+ return addProperty( value, ResourceFactory.createTypedLiteral(d));
+ }
+
+ /**
+ * Add the property <code>p</code> with the typed-literal value
+ * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
+ * this's securedModel. Answer
+ * this resource. The typed literal is equal to one constructed by using
+ * <code>this.getModel().createTypedLiteral(o)</code>.
+ */
+ @Override
+ public SecuredResource addLiteral( final Property value, final float d )
+ {
+ return addProperty( value, ResourceFactory.createTypedLiteral(d) );
+ }
+
+ /**
+ * Add the property <code>p</code> with the pre-constructed Literal value
+ * <code>o</code> to this resource, <i>ie</i> add (this, p, o) to this's
+ * securedModel. Answer this resource. <b>NOTE</b> thjat this is distinct
+ * from the
+ * other addLiteral methods in that the Literal is not turned into a
+ * Literal.
+ */
+ @Override
+ public SecuredResource addLiteral( final Property p, final Literal o )
+ {
+ return addProperty( p, o );
+ }
+
+ /**
+ * Add the property <code>p</code> with the typed-literal value
+ * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
+ * this's securedModel. Answer
+ * this resource. The typed literal is equal to one constructed by using
+ * <code>this.getModel().createTypedLiteral(o)</code>.
+ */
+ @Override
+ public SecuredResource addLiteral( final Property p, final long o )
+ {
+ return addProperty( p, ResourceFactory.createTypedLiteral(o));
+ }
+
+ /**
+ * Add the property <code>p</code> with the typed-literal value
+ * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to
+ * this's securedModel. Answer
+ * this resource. The typed literal is equal to one constructed by using
+ * <code>this.getModel().createTypedLiteral(o)</code>.
+ */
+ @Override
+ public SecuredResource addLiteral( final Property p, final Object o )
+ {
+ return addProperty( p, ResourceFactory.createTypedLiteral(o));
+ }
+
+ /**
+ * Add a property to this resource.
+ *
+ * <p>
+ * A statement with this resource as the subject, p as the predicate and o
+ * as the object is added to the securedModel associated with this resource.
+ * </p>
+ *
+ * @param p
+ * The property to be added.
+ * @param o
+ * The value of the property to be added.
+ * @return This resource to allow cascading calls.
+ */
+ @Override
+ public SecuredResource addProperty( final Property p, final RDFNode o )
+ {
+ checkUpdate();
+ checkCreate(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ o.asNode()));
+ holder.getBaseItem().addProperty(p, o);
+ return holder.getSecuredItem();
+ }
+
+ /**
+ * Add a property to this resource.
+ *
+ * <p>
+ * A statement with this resource as the subject, p as the predicate and o
+ * as the object is added to the securedModel associated with this resource.
+ * </p>
+ *
+ * @param p
+ * The property to be added.
+ * @param o
+ * The value of the property to be added.
+ * @return This resource to allow cascading calls.
+ */
+ @Override
+ public SecuredResource addProperty( final Property p, final String o )
+ {
+ return addProperty( p, o, "");
+ }
+
+ /**
+ * Add a property to this resource.
+ *
+ * <p>
+ * A statement with this resource as the subject, p as the predicate and o
+ * as the object is added to the securedModel associated with this resource.
+ * </p>
+ *
+ * @param p
+ * The property to be added.
+ * @param lexicalForm
+ * The lexical form of the literal
+ * @param datatype
+ * The datatype
+ * @return This resource to allow cascading calls.
+ */
+ @Override
+ public SecuredResource addProperty( final Property p, final String lexicalForm,
+ final RDFDatatype datatype )
+ {
+ checkUpdate();
+ final Literal l = ResourceFactory.createTypedLiteral(lexicalForm,
+ datatype);
+ checkCreate(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ l.asNode()));
+ holder.getBaseItem().addProperty(p, l);
+ return holder.getSecuredItem();
+ }
+
+ /**
+ * Add a property to this resource.
+ *
+ * <p>
+ * A statement with this resource as the subject, p as the predicate and o
+ * as the object is added to the securedModel associated with this resource.
+ * </p>
+ *
+ * @param p
+ * The property to be added.
+ * @param o
+ * The value of the property to be added.
+ * @param l
+ * the language of the property
+ * @return This resource to allow cascading calls.
+ */
+ @Override
+ public SecuredResource addProperty( final Property p, final String o,
+ final String l )
+ {
+ checkUpdate();
+ checkCreate(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ NodeFactory.createLiteral(o, l, false)));
+ holder.getBaseItem().addProperty(p, o, l);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public Literal asLiteral()
+ {
+ throw new LiteralRequiredException(asNode());
+ }
+
+ @Override
+ public SecuredResource asResource()
+ {
+ return holder.getSecuredItem();
+ }
+
+ /**
+ * Begin a transaction in the associated securedModel.
+ *
+ * @return This resource to permit cascading.
+ */
+ @Override
+ public SecuredResource begin()
+ {
+ holder.getBaseItem().begin();
+ return holder.getSecuredItem();
+ }
+
+ public boolean canReadProperty( final Node p )
+ {
+ return canRead(new Triple(holder.getBaseItem().asNode(), p, Node.ANY));
+ }
+
+ protected void checkReadProperty( final Node p )
+ {
+ if (!canReadProperty(p))
+ {
+ throw new AccessDeniedException(getModelNode(), SecuredItemImpl
+ .convert(
+ new Triple(holder.getBaseItem().asNode(), p,
+ Node.ANY)).toString(), Action.Read);
+ }
+ }
+
+ /**
+ * Commit the transaction in the associated securedModel.
+ *
+ * @return This resource to permit cascading.
+ */
+ @Override
+ public SecuredResource commit()
+ {
+ holder.getBaseItem().commit();
+ return holder.getSecuredItem();
+ }
+
+ /**
+ * Returns an a unique identifier for anonymous resources.
+ *
+ * <p>
+ * The id is unique within the scope of a particular implementation. All
+ * models within an implementation will use the same id for the same
+ * anonymous resource.
+ * </p>
+ *
+ * <p>
+ * This method is undefined if called on resources which are not anonymous
+ * and may raise an exception.
+ * </p>
+ *
+ * @return A unique id for an anonymous resource.
+ */
+ @Override
+ public AnonId getId()
+ {
+ checkRead();
+ return holder.getBaseItem().getId();
+
+ }
+
+ /**
+ * Returns the name of this resource within its namespace.
+ *
+ * @return The name of this property within its namespace.
+ */
+ @Override
+ public String getLocalName()
+ {
+ checkRead();
+ return holder.getBaseItem().getLocalName();
+ }
+
+ /**
+ * Returns the namespace associated with this resource.
+ *
+ * @return The namespace for this property.
+ */
+ @Override
+ public String getNameSpace()
+ {
+ checkRead();
+ return holder.getBaseItem().getNameSpace();
+ }
+
+ /**
+ * Answer some statement (this, p, O) in the associated securedModel. If
+ * there are
+ * several
+ * such statements, any one of them may be returned. If no such statements
+ * exist,
+ * null is returned - in this is differs from getRequiredProperty.
+ *
+ * @param p
+ * the property sought
+ * @return a statement (this, p, O), or null if no such statements exist
+ * here
+ */
+ @Override
+ public SecuredStatement getProperty( final Property p )
+ {
+ checkRead();
+ final ExtendedIterator<Statement> iter = holder.getBaseItem()
+ .listProperties(p)
+ .filterKeep(new PermStatementFilter(Action.Read, this));
+ try
+ {
+ if (iter.hasNext())
+ {
+ return org.apache.jena.security.model.impl.SecuredStatementImpl
+ .getInstance(getModel(), iter.next());
+ }
+ else
+ {
+ return null;
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ /**
+ * Answer some resource R for which this.hasProperty( p, R ),
+ * or null if no such R exists.
+ */
+ @Override
+ public SecuredResource getPropertyResourceValue( final Property p )
+ {
+ final SecuredStatementIterator iter = listProperties(p);
+ try
+ {
+ while (iter.hasNext())
+ {
+ final Statement s = iter.next();
+ if (s.getObject().isResource())
+ {
+ return SecuredResourceImpl.getInstance(getModel(), s
+ .getObject().asResource());
+ }
+ }
+ return null;
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ /**
+ * Get a property value of this resource.
+ *
+ * <p>
+ * The securedModel associated with the resource instance is searched for
+ * statements whose subject is this resource and whose predicate is p. If
+ * such a statement is found, it is returned. If several such statements are
+ * found, any one may be returned. If no such statements are found, an
+ * exception is thrown.
+ * </p>
+ *
+ * @param p
+ * The property sought.
+ * @return some (this, p, ?O) statement if one exists
+ * @throws PropertyNotFoundException
+ * if no such statement found
+ */
+ @Override
+ public SecuredStatement getRequiredProperty( final Property p )
+ throws PropertyNotFoundException
+ {
+ checkRead();
+ final ExtendedIterator<Statement> iter = holder.getBaseItem()
+ .listProperties(p)
+ .filterKeep(new PermStatementFilter(Action.Read, this));
+ try
+ {
+ if (iter.hasNext())
+ {
+ return org.apache.jena.security.model.impl.SecuredStatementImpl
+ .getInstance(getModel(), iter.next());
+ }
+ else
+ {
+ throw new PropertyNotFoundException(p);
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ // return org.apache.jena.security.model.impl.Factory.getInstance(
+ // this, holder.getBaseItem().getRequiredProperty(p));
+ }
+
+ /**
+ * Return the URI of the resource, or null if it's a bnode.
+ *
+ * @return The URI of the resource, or null if it's a bnode.
+ */
+ @Override
+ public String getURI()
+ {
+ checkRead();
+ return holder.getBaseItem().getURI();
+ }
+
+ /**
+ * Answer true iff this resource has the value <code>o</code> for
+ * property <code>p</code>. <code>o</code> is interpreted as
+ * a typed literal with the appropriate RDF type.
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final boolean o )
+ {
+ checkRead();
+ checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ ResourceFactory.createTypedLiteral(o).asNode()));
+ return holder.getBaseItem().hasLiteral(p, o);
+ }
+
+ /**
+ * Answer true iff this resource has the value <code>o</code> for
+ * property <code>p</code>. <code>o</code> is interpreted as
+ * a typed literal with the appropriate RDF type.
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final char o )
+ {
+ checkRead();
+ checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ ResourceFactory.createTypedLiteral(o).asNode()));
+ return holder.getBaseItem().hasLiteral(p, o);
+ }
+
+ /**
+ * Answer true iff this resource has the value <code>o</code> for
+ * property <code>p</code>. <code>o</code> is interpreted as
+ * a typed literal with the appropriate RDF type.
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final double o )
+ {
+ checkRead();
+ checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ ResourceFactory.createTypedLiteral(o).asNode()));
+ return holder.getBaseItem().hasLiteral(p, o);
+ }
+
+ /**
+ * Answer true iff this resource has the value <code>o</code> for
+ * property <code>p</code>. <code>o</code> is interpreted as
+ * a typed literal with the appropriate RDF type.
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final float o )
+ {
+ checkRead();
+ checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ ResourceFactory.createTypedLiteral(o).asNode()));
+ return holder.getBaseItem().hasLiteral(p, o);
+ }
+
+ /**
+ * Answer true iff this resource has the value <code>o</code> for
+ * property <code>p</code>. <code>o</code> is interpreted as
+ * a typed literal with the appropriate RDF type.
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final long o )
+ {
+ checkRead();
+ checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ ResourceFactory.createTypedLiteral(o).asNode()));
+ return holder.getBaseItem().hasLiteral(p, o);
+ }
+
+ /**
+ * Answer true iff this resource has the value <code>o</code> for
+ * property <code>p</code>. <code>o</code> is interpreted as
+ * a typed literal with the appropriate RDF type.
+ */
+ @Override
+ public boolean hasLiteral( final Property p, final Object o )
+ {
+ checkRead();
+ checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ ResourceFactory.createTypedLiteral(o).asNode()));
+ return holder.getBaseItem().hasLiteral(p, o);
+ }
+
+ /**
+ * Determine whether this resource has any values for a given property.
+ *
+ * @param p
+ * The property sought.
+ * @return true if and only if this resource has at least one
+ * value for the property.
+ */
+ @Override
+ public boolean hasProperty( final Property p )
+ {
+ checkRead();
+ final ExtendedIterator<Statement> iter = holder.getBaseItem()
+ .listProperties(p)
+ .filterKeep(new PermStatementFilter(Action.Read, this));
+ try
+ {
+ return iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ /**
+ * Test if this resource has a given property with a given value.
+ *
+ * @param p
+ * The property sought.
+ * @param o
+ * The value of the property sought.
+ * @return true if and only if this resource has property p with
+ * value o.
+ */
+ @Override
+ public boolean hasProperty( final Property p, final RDFNode o )
+ {
+ checkRead();
+ final ExtendedIterator<Statement> iter = holder.getBaseItem()
+ .getModel().listStatements(this, p, o)
+ .filterKeep(new PermStatementFilter(Action.Read, this));
+ try
+ {
+ return iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ /**
+ * Test if this resource has a given property with a given value.
+ *
+ * @param p
+ * The property sought.
+ * @param o
+ * The value of the property sought.
+ * @return true if and only if this resource has property p with
+ * value o.
+ */
+ @Override
+ public boolean hasProperty( final Property p, final String o )
+ {
+ checkRead();
+ final ExtendedIterator<Statement> iter = holder.getBaseItem()
+ .getModel().listStatements(this, p, o)
+ .filterKeep(new PermStatementFilter(Action.Read, this));
+ try
+ {
+ return iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ /**
+ * Test if this resource has a given property with a given value.
+ *
+ * @param p
+ * The property sought.
+ * @param o
+ * The value of the property sought.
+ * @param l
+ * The language of the property sought.
+ * @return true if and only if this resource has property p with
+ * value o.
+ */
+ @Override
+ public boolean hasProperty( final Property p, final String o, final String l )
+ {
+ checkRead();
+ final Literal ll = holder.getBaseItem().getModel().createLiteral(o, l);
+ final ExtendedIterator<Statement> iter = holder.getBaseItem()
+ .getModel().listStatements(this, p, ll)
+ .filterKeep(new PermStatementFilter(Action.Read, this));
+ try
+ {
+ return iter.hasNext();
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ /**
+ * Answer true iff this Resource is a URI resource with the given URI.
+ * Using this is preferred to using getURI() and .equals().
+ */
+ @Override
+ public boolean hasURI( final String uri )
+ {
+ checkRead();
+ return holder.getBaseItem().hasURI(uri);
+ }
+
+ @Override
+ public Resource inModel( final Model m )
+ {
+ return (Resource) super.inModel(m);
+ }
+
+ /**
+ * Return an iterator over all the properties of this resource.
+ *
+ * <p>
+ * The securedModel associated with this resource is search and an iterator
+ * is returned which iterates over all the statements which have this
+ * resource as a subject.
+ * </p>
+ *
+ * @return An iterator over all the statements about this object.
+ */
+ @Override
+ public SecuredStatementIterator listProperties()
+ {
+ checkRead();
+ return new SecuredStatementIterator(getModel(), holder.getBaseItem()
+ .listProperties());
+ }
+
+ /**
+ * List all the values of the property p.
+ *
+ * <p>
+ * Returns an iterator over all the statements in the associated
+ * securedModel whose subject is this resource and whose predicate is p.
+ * </p>
+ *
+ * @param p
+ * The predicate sought.
+ * @return An iterator over the statements.
+ */
+ @Override
+ public SecuredStatementIterator listProperties( final Property p )
+ {
+ checkRead();
+ return new SecuredStatementIterator(getModel(), holder.getBaseItem()
+ .listProperties(p));
+
+ }
+
+ /**
+ * Delete all the statements with predicate <code>p</code> for this resource
+ * from its associated securedModel.
+ *
+ * @param p
+ * the property to remove
+ * @return this resource, to permit cascading
+ */
+ @Override
+ public SecuredResource removeAll( final Property p )
+ {
+ checkUpdate();
+ if (!canDelete(new Triple(holder.getBaseItem().asNode(), p.asNode(),
+ Node.ANY)))
+ {
+ final StmtIterator iter = holder.getBaseItem().listProperties(p);
+ try
+ {
+ if (!iter.hasNext())
+ {
+ // thre arn't any to delete -- so return
+ return holder.getSecuredItem();
+ }
+ while (iter.hasNext())
+ {
+ checkDelete(iter.next().asTriple());
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ holder.getBaseItem().removeAll(p);
+ return holder.getSecuredItem();
+ }
+
+ /**
+ * Delete all the properties for this resource from the associated
+ * securedModel.
+ *
+ * @return This resource to permit cascading.
+ */
+ @Override
+ public SecuredResource removeProperties()
+ {
+ checkUpdate();
+ if (!canDelete(new Triple(holder.getBaseItem().asNode(), Node.ANY,
+ Node.ANY)))
+ {
+ final StmtIterator iter = holder.getBaseItem().listProperties();
+ try
+ {
+ if (!iter.hasNext())
+ {
+ // thre arn't any to delete -- so return
+ return holder.getSecuredItem();
+ }
+ while (iter.hasNext())
+ {
+ checkDelete(iter.next().asTriple());
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+ holder.getBaseItem().removeProperties();
+ return holder.getSecuredItem();
+ }
+
+ /**
+ * Return a string representation of the resource.
+ *
+ * Returns the URI of the resource unless the resource is anonymous
+ * in which case it returns the id of the resource enclosed in square
+ * brackets.
+ *
+ * @return Return a string representation of the resource.
+ * if it is anonymous.
+ */
+ @Override
+ public String toString()
+ {
+ return holder.getBaseItem().toString();
+ }
+
+ @Override
+ public Object visitWith( final RDFVisitor rv )
+ {
+ return isAnon() ? rv.visitBlank(this, getId()) : rv.visitURI(this,
+ getURI());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredSelector.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredSelector.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredSelector.java
new file mode 100644
index 0000000..9102a2a
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredSelector.java
@@ -0,0 +1,94 @@
+/*
+ * 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.model.impl;
+
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.SecurityEvaluator.SecNode;
+import org.apache.jena.security.SecurityEvaluator.SecTriple;
+import org.apache.jena.security.impl.SecuredItem;
+import org.apache.jena.security.impl.SecuredItemImpl;
+
+public class SecuredSelector implements Selector
+{
+ private final SecuredItem securedItem;
+ private final Selector selector;
+
+ public SecuredSelector( final SecuredItem securedItem )
+ {
+ this(securedItem, new SimpleSelector());
+ }
+
+ public SecuredSelector( final SecuredItem securedItem,
+ final Selector selector )
+ {
+ this.securedItem = securedItem;
+ this.selector = selector;
+ }
+
+ private SecNode getNode( final RDFNode node )
+ {
+ return node == null ? SecNode.ANY : SecuredItemImpl.convert(node
+ .asNode());
+ }
+
+ @Override
+ public RDFNode getObject()
+ {
+ return selector.getObject();
+ }
+
+ @Override
+ public Property getPredicate()
+ {
+ return selector.getPredicate();
+ }
+
+ @Override
+ public Resource getSubject()
+ {
+ return selector.getSubject();
+ }
+
+ @Override
+ public boolean isSimple()
+ {
+ return securedItem.canRead(SecTriple.ANY);
+ }
+
+ /**
+ * This method is designed to be over ridden by subclasses to define
+ * application
+ * specific constraints on the statements selected.
+ *
+ * @param s
+ * the statement to be tested
+ * @return true if the statement satisfies the constraint
+ */
+ @Override
+ public boolean test( final Statement s )
+ {
+ if (selector.test(s))
+ {
+ final SecTriple t = new SecTriple(getNode(s.getSubject()),
+ getNode(s.getPredicate()), getNode(s.getObject()));
+ return securedItem.canRead(t);
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/b712fb28/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredSeqImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredSeqImpl.java b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredSeqImpl.java
new file mode 100644
index 0000000..9514417
--- /dev/null
+++ b/jena-permissions/src/main/java/org/apache/jena/security/model/impl/SecuredSeqImpl.java
@@ -0,0 +1,511 @@
+/*
+ * 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.model.impl;
+
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.security.impl.ItemHolder ;
+import org.apache.jena.security.impl.SecuredItemInvoker ;
+import org.apache.jena.security.model.* ;
+import org.apache.jena.util.iterator.ExtendedIterator ;
+import org.apache.jena.util.iterator.Filter ;
+import org.apache.jena.vocabulary.RDF ;
+
+/**
+ * Implementation of SecuredSeq to be used by a SecuredItemInvoker proxy.
+ *
+ * Sequence may have breaks in the order.
+ * http://www.w3.org/TR/2004/REC-rdf-mt-20040210/#Containers
+ *
+ */
+public class SecuredSeqImpl extends SecuredContainerImpl implements SecuredSeq
+{
+ private class RDFNodeFilter extends Filter<Statement>
+ {
+ private final RDFNode n;
+
+ public RDFNodeFilter( final RDFNode n )
+ {
+ this.n = n;
+ }
+
+ @Override
+ public boolean accept( final Statement o )
+ {
+ return (o.getPredicate().getOrdinal() != 0)
+ && n.equals(o.getObject());
+ }
+
+ }
+
+ /**
+ * get a SecuredSeq.
+ *
+ * @param securedModel
+ * The secured model that provides the security context
+ * @param seq
+ * The Seq to secure.
+ * @return the SecuredSeq
+ */
+ public static SecuredSeq getInstance( final SecuredModel securedModel,
+ final Seq seq )
+ {
+ if (securedModel == null)
+ {
+ throw new IllegalArgumentException(
+ "Secured securedModel may not be null");
+ }
+ if (seq == null)
+ {
+ throw new IllegalArgumentException("Seq may not be null");
+ }
+ final ItemHolder<Seq, SecuredSeq> holder = new ItemHolder<Seq, SecuredSeq>(
+ seq);
+ final SecuredSeqImpl checker = new SecuredSeqImpl(securedModel, holder);
+ // if we are going to create a duplicate proxy, just return this
+ // one.
+ if (seq instanceof SecuredSeq)
+ {
+ if (checker.isEquivalent((SecuredSeq) seq))
+ {
+ return (SecuredSeq) seq;
+ }
+ }
+ return holder.setSecuredItem(new SecuredItemInvoker(seq.getClass(),
+ checker));
+ }
+
+ // the item holder that contains this SecuredSeq.
+ private final ItemHolder<? extends Seq, ? extends SecuredSeq> holder;
+
+ /**
+ * Constructor.
+ *
+ * @param securedModel
+ * The secured model that provides the security context
+ * @param holder
+ * The item holder that will contain this SecuredSeq.
+ */
+ protected SecuredSeqImpl( final SecuredModel securedModel,
+ final ItemHolder<? extends Seq, ? extends SecuredSeq> holder )
+ {
+ super(securedModel, holder);
+ this.holder = holder;
+ }
+
+ @Override
+ public SecuredSeq add( final int index, final boolean o )
+ {
+ return add( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq add( final int index, final char o )
+ {
+ return add( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq add( final int index, final double o )
+ {
+ return add( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq add( final int index, final float o )
+ {
+ return add( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq add( final int index, final long o )
+ {
+ return add( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq add( final int index, final Object o )
+ {
+ return add( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq add( final int index, final RDFNode o )
+ {
+ checkUpdate();
+ final Literal l = holder.getBaseItem().getModel().createTypedLiteral(o);
+ checkCreate(index, l);
+ holder.getBaseItem().add(index, o);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredSeq add( final int index, final String o )
+ {
+ return add( index, o, "" );
+ }
+
+ @Override
+ public SecuredSeq add( final int index, final String o, final String l )
+ {
+ return add( index, holder.getBaseItem().getModel().createLiteral(o, l));
+ }
+
+ private void checkCreate( final int index, final Literal l )
+ {
+ checkCreate(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), l.asNode()));
+ }
+
+ private Statement containerIndexOf( final RDFNode n )
+ {
+ final ExtendedIterator<Statement> iter = listProperties().filterKeep(
+ new RDFNodeFilter(n));
+ try
+ {
+ if (iter.hasNext())
+ {
+ return iter.next();
+ }
+ else
+ {
+ return null;
+ }
+ }
+ finally
+ {
+ iter.close();
+ }
+ }
+
+ @Override
+ public SecuredAlt getAlt( final int index )
+ {
+ checkRead();
+ final Alt a = holder.getBaseItem().getAlt(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), a.asNode()));
+ return SecuredAltImpl.getInstance(getModel(), a);
+ }
+
+ @Override
+ public SecuredBag getBag( final int index )
+ {
+ checkRead();
+ final Bag b = holder.getBaseItem().getBag(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), b.asNode()));
+ return SecuredBagImpl.getInstance(getModel(), b);
+ }
+
+ @Override
+ public boolean getBoolean( final int index )
+ {
+ checkRead();
+ final boolean retval = holder.getBaseItem().getBoolean(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), asObject(retval).asNode()));
+ return retval;
+ }
+
+ @Override
+ public byte getByte( final int index )
+ {
+ checkRead();
+ final byte retval = holder.getBaseItem().getByte(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), asObject(retval).asNode()));
+ return retval;
+ }
+
+ @Override
+ public char getChar( final int index )
+ {
+ checkRead();
+ final char retval = holder.getBaseItem().getChar(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), asObject(retval).asNode()));
+ return retval;
+
+ }
+
+ @Override
+ public double getDouble( final int index )
+ {
+ checkRead();
+ final double retval = holder.getBaseItem().getDouble(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), asObject(retval).asNode()));
+ return retval;
+ }
+
+ @Override
+ public float getFloat( final int index )
+ {
+ checkRead();
+ final float retval = holder.getBaseItem().getFloat(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), asObject(retval).asNode()));
+ return retval;
+ }
+
+ @Override
+ public int getInt( final int index )
+ {
+ checkRead();
+ final int retval = holder.getBaseItem().getInt(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), asObject(retval).asNode()));
+ return retval;
+ }
+
+ @Override
+ public String getLanguage( final int index )
+ {
+ checkRead();
+ final Literal literal = holder.getBaseItem().getLiteral(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), literal.asNode()));
+ return literal.getLanguage();
+ }
+
+ @Override
+ public SecuredLiteral getLiteral( final int index )
+ {
+ checkRead();
+ final Literal literal = holder.getBaseItem().getLiteral(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), literal.asNode()));
+ return SecuredLiteralImpl.getInstance(getModel(), literal);
+ }
+
+ @Override
+ public long getLong( final int index )
+ {
+ checkRead();
+ final long retval = holder.getBaseItem().getLong(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), asObject(retval).asNode()));
+ return retval;
+ }
+
+ @Override
+ public SecuredRDFNode getObject( final int index )
+ {
+ checkRead();
+ final RDFNode retval = holder.getBaseItem().getObject(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), retval.asNode()));
+ return SecuredRDFNodeImpl.getInstance(getModel(), retval);
+ }
+
+ @Override
+ public SecuredResource getResource( final int index )
+ {
+ checkRead();
+ final Resource retval = holder.getBaseItem().getResource(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), retval.asNode()));
+ return SecuredResourceImpl.getInstance(getModel(), retval);
+ }
+
+ @Override
+ @Deprecated
+ public SecuredResource getResource( final int index, final ResourceF f )
+ {
+ checkRead();
+ final Resource retval = holder.getBaseItem().getResource(index, f);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), retval.asNode()));
+ return SecuredResourceImpl.getInstance(getModel(), retval);
+ }
+
+ @Override
+ public SecuredSeq getSeq( final int index )
+ {
+ checkRead();
+ final Seq retval = holder.getBaseItem().getSeq(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), retval.asNode()));
+ return SecuredSeqImpl.getInstance(getModel(), retval);
+ }
+
+ @Override
+ public short getShort( final int index )
+ {
+ checkRead();
+ final short retval = holder.getBaseItem().getShort(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), ResourceFactory.createTypedLiteral(retval).asNode()));
+ return retval;
+ }
+
+ @Override
+ public String getString( final int index )
+ {
+ checkRead();
+ final String retval = holder.getBaseItem().getString(index);
+ checkRead(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), ResourceFactory.createTypedLiteral(retval).asNode()));
+ return retval;
+ }
+
+ @Override
+ public int indexOf( final boolean o )
+ {
+ return indexOf( asObject( o ));
+ }
+
+ @Override
+ public int indexOf( final char o )
+ {
+ return indexOf( asObject( o ));
+ }
+
+ @Override
+ public int indexOf( final double o )
+ {
+ return indexOf( asObject( o ));
+ }
+
+ @Override
+ public int indexOf( final float o )
+ {
+ return indexOf( asObject( o ));
+ }
+
+ @Override
+ public int indexOf( final long o )
+ {
+ return indexOf( asObject( o ));
+ }
+
+ @Override
+ public int indexOf( final Object o )
+ {
+ return indexOf( asObject( o ));
+ }
+
+ @Override
+ public int indexOf( final RDFNode o )
+ {
+ checkRead();
+ final Statement stmt = containerIndexOf(o);
+ if (stmt == null)
+ {
+ return 0;
+ }
+ checkRead(stmt);
+ return stmt.getPredicate().getOrdinal();
+ }
+
+ @Override
+ public int indexOf( final String o )
+ {
+ return indexOf( asLiteral( o, "" ));
+ }
+
+ @Override
+ public int indexOf( final String o, final String l )
+ {
+ return indexOf( asLiteral( o, l));
+ }
+
+ @Override
+ public SecuredSeq remove( final int index )
+ {
+ checkUpdate();
+ final RDFNode rdfNode = holder.getBaseItem().getObject(index);
+ if (rdfNode != null)
+ {
+ checkDelete(new Triple(holder.getBaseItem().asNode(), RDF.li(index)
+ .asNode(), rdfNode.asNode()));
+ holder.getBaseItem().remove(index);
+ }
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredSeq set( final int index, final boolean o )
+ {
+ return set( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq set( final int index, final char o )
+ {
+ return set( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq set( final int index, final double o )
+ {
+ return set( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq set( final int index, final float o )
+ {
+ return set( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq set( final int index, final long o )
+ {
+ return set( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq set( final int index, final Object o )
+ {
+ return set( index, asObject( o ));
+ }
+
+ @Override
+ public SecuredSeq set( final int index, final RDFNode o )
+ {
+ checkUpdate();
+ final Triple t2 = new Triple(holder.getBaseItem().asNode(), RDF.li(
+ index).asNode(), o.asNode());
+ final RDFNode rdfNode = holder.getBaseItem().getObject(index);
+ if (rdfNode != null)
+ {
+ final Triple t1 = new Triple(holder.getBaseItem().asNode(), RDF.li(
+ index).asNode(), rdfNode.asNode());
+ checkUpdate(t1, t2);
+ }
+ else
+ {
+ checkCreate(t2);
+ }
+ holder.getBaseItem().set(index, o);
+ return holder.getSecuredItem();
+ }
+
+ @Override
+ public SecuredSeq set( final int index, final String o )
+ {
+ return set( index, asLiteral( o, "" ));
+ }
+
+ @Override
+ public SecuredSeq set( final int index, final String o, final String l )
+ {
+ return set( index, asLiteral(o, l));
+ }
+}