org.fcrepo.server.security.xacml.pdp.data
Class ExistPolicyIndex

java.lang.Object
  extended by org.fcrepo.server.security.xacml.pdp.data.PolicyIndexBase
      extended by org.fcrepo.server.security.xacml.pdp.data.XPathPolicyIndex
          extended by org.fcrepo.server.security.xacml.pdp.data.ExistPolicyIndex
All Implemented Interfaces:
PolicyIndex

public class ExistPolicyIndex
extends XPathPolicyIndex
implements PolicyIndex

A PolicyIndex based on an XPath XML database. This implementation only tested on eXist, but as only generic xmldb API methods have been used it should work with some customisation on other XML databases that support the xmldb API. Customisations will be required for driver configuration, indexing, and potentially organisation of collections (eg root collection name). Concurrency handled with a ReentrantReadWriteLock (although eXist does natively have some concurrency support).

Version:
$Id$
Author:
Stephen Bayliss

Field Summary
protected  org.xmldb.api.base.Collection m_collection
           
 
Fields inherited from class org.fcrepo.server.security.xacml.pdp.data.PolicyIndexBase
ACTION_KEY, ENVIRONMENT_KEY, indexed, indexMap, m_policyReader, METADATA_POLICY_NS, namespaces, RESOURCE_KEY, SUBJECT_KEY
 
Fields inherited from interface org.fcrepo.server.security.xacml.pdp.data.PolicyIndex
XACML_RESOURCE_ID, XACML20_POLICY_NS
 
Constructor Summary
protected ExistPolicyIndex(PolicyReader policyReader)
           
 
Method Summary
 String addPolicy(String name, String document)
          Generates a policy based on the string data provided and the name.
 boolean clear()
          Clear the policy index completely
 void close()
           
 boolean contains(String policyName)
          Check if the policy identified by policyName exists.
protected  org.xmldb.api.base.Collection createCollectionPath(String collectionPath, org.xmldb.api.base.Collection rootCollection)
          Create a collection given a full path to the collection.
protected static Document createDocument(String document)
           
protected  void deleteCollection()
          delete the policy collection from the database
 boolean deletePolicy(String name)
          Removes the policy given by name from the data store.
protected  org.xmldb.api.base.ResourceSet doQuery(String query, Map<String,String> variables)
           
 Map<String,com.sun.xacml.AbstractPolicy> getPolicies(com.sun.xacml.EvaluationCtx eval, com.sun.xacml.finder.PolicyFinder policyFinder)
          Extracts a list of policies from the Policy Index that are relevant to the given Evaluation Context.
 com.sun.xacml.AbstractPolicy getPolicy(String name, com.sun.xacml.finder.PolicyFinder policyFinder)
          Obtains the policy with the provided name from the Policy Store.
protected static String IdToName(String Id)
           
 void init()
           
protected  void initCollection()
           
 void initDatabase()
           
protected static String nameToId(String name)
           
protected static byte[] nodeToByte(Node node)
          get XML document supplied as w3c dom Node as bytes
 void setCollectionName(String collectionName)
           
 void setDatabaseURI(String databaseURI)
           
 void setPassword(String password)
           
 void setUser(String user)
           
protected static String[] sortDescending(String[] s)
          sorts a string array in descending order of length
 boolean updatePolicy(String name, String newDocument)
          Generates a new policy based for the given policy name and replaces the old policy in the Policy Store with it.
 
Methods inherited from class org.fcrepo.server.security.xacml.pdp.data.XPathPolicyIndex
getXpath, getXpathVariables
 
Methods inherited from class org.fcrepo.server.security.xacml.pdp.data.PolicyIndexBase
getAttributeMap, handleDocument, makeComponents, setActionAttributes, setAttributeMap, setEnvironmentAttributes, setResourceAttributes, setSubjectAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_collection

protected org.xmldb.api.base.Collection m_collection
Constructor Detail

ExistPolicyIndex

protected ExistPolicyIndex(PolicyReader policyReader)
                    throws PolicyIndexException
Throws:
PolicyIndexException
Method Detail

addPolicy

public String addPolicy(String name,
                        String document)
                 throws PolicyIndexException
Description copied from interface: PolicyIndex
Generates a policy based on the string data provided and the name. The policy is then added to the Policy Store.

Specified by:
addPolicy in interface PolicyIndex
document - the policy as a String
Returns:
the name of the added policy
Throws:
PolicyIndexException

clear

public boolean clear()
              throws PolicyIndexException
Description copied from interface: PolicyIndex
Clear the policy index completely

Specified by:
clear in interface PolicyIndex
Returns:
Throws:
PolicyIndexException

contains

public boolean contains(String policyName)
                 throws PolicyIndexException
Description copied from interface: PolicyIndex
Check if the policy identified by policyName exists.

Specified by:
contains in interface PolicyIndex
Returns:
true iff the policy store contains a policy with the same PolicyId
Throws:
PolicyIndexException

deletePolicy

public boolean deletePolicy(String name)
                     throws PolicyIndexException
Description copied from interface: PolicyIndex
Removes the policy given by name from the data store.

Specified by:
deletePolicy in interface PolicyIndex
Parameters:
name - the name of the policy
Returns:
true if policy was deleted
Throws:
PolicyIndexException

getPolicies

public Map<String,com.sun.xacml.AbstractPolicy> getPolicies(com.sun.xacml.EvaluationCtx eval,
                                                            com.sun.xacml.finder.PolicyFinder policyFinder)
                                                     throws PolicyIndexException
Description copied from interface: PolicyIndex
Extracts a list of policies from the Policy Index that are relevant to the given Evaluation Context. Note that this returns a set that still has to be further filtered by the PolicyFinder to find policies that match 100%. This merely eliminates the need to match every policy, just the most likely ones to apply.

Specified by:
getPolicies in interface PolicyIndex
Parameters:
eval - the Evaluation Context from which to match policies against
Returns:
the List of potential policies
Throws:
PolicyIndexException

getPolicy

public com.sun.xacml.AbstractPolicy getPolicy(String name,
                                              com.sun.xacml.finder.PolicyFinder policyFinder)
                                       throws PolicyIndexException
Description copied from interface: PolicyIndex
Obtains the policy with the provided name from the Policy Store.

Specified by:
getPolicy in interface PolicyIndex
Parameters:
name - the name of the policy to return
Returns:
the policy as an array of bytes
Throws:
PolicyIndexException

updatePolicy

public boolean updatePolicy(String name,
                            String newDocument)
                     throws PolicyIndexException
Description copied from interface: PolicyIndex
Generates a new policy based for the given policy name and replaces the old policy in the Policy Store with it. An exception is thrown if the policy with the given name cannot be found.

Specified by:
updatePolicy in interface PolicyIndex
Parameters:
name - the name of the policy to update
newDocument - the new policy as a String
Returns:
true if policy was updated
Throws:
PolicyIndexException

nodeToByte

protected static byte[] nodeToByte(Node node)
                            throws PolicyIndexException
get XML document supplied as w3c dom Node as bytes

Parameters:
node -
Returns:
Throws:
PolicyIndexException

nameToId

protected static String nameToId(String name)

IdToName

protected static String IdToName(String Id)

sortDescending

protected static String[] sortDescending(String[] s)
sorts a string array in descending order of length

Parameters:
s -
Returns:

doQuery

protected org.xmldb.api.base.ResourceSet doQuery(String query,
                                                 Map<String,String> variables)
                                          throws PolicyIndexException
Throws:
PolicyIndexException

createCollectionPath

protected org.xmldb.api.base.Collection createCollectionPath(String collectionPath,
                                                             org.xmldb.api.base.Collection rootCollection)
                                                      throws PolicyIndexException
Create a collection given a full path to the collection. The collection path must include the root collection. Intermediate collections in the path are created if they do not already exist.

Parameters:
collectionPath -
rootCollection -
Returns:
Throws:
PolicyIndexException

setDatabaseURI

public void setDatabaseURI(String databaseURI)

setCollectionName

public void setCollectionName(String collectionName)

setUser

public void setUser(String user)

setPassword

public void setPassword(String password)

init

public void init()
          throws PolicyIndexException
Throws:
PolicyIndexException

initDatabase

public void initDatabase()
                  throws PolicyIndexException
Throws:
PolicyIndexException

initCollection

protected void initCollection()
                       throws PolicyIndexException
Throws:
PolicyIndexException

deleteCollection

protected void deleteCollection()
                         throws PolicyIndexException
delete the policy collection from the database

Throws:
PolicyIndexException

createDocument

protected static Document createDocument(String document)
                                  throws PolicyIndexException
Throws:
PolicyIndexException

close

public void close()


Copyright © 2012 DuraSpace. All Rights Reserved.