issrg.utils.repository
Class FileRepository

java.lang.Object
  extended by issrg.utils.repository.DefaultRepository
      extended by issrg.utils.repository.FileRepository
All Implemented Interfaces:
AttributeRepository

public class FileRepository
extends DefaultRepository

This repository uses File URLs and the DN hash to find the attributes from an entry. The File URLs should be of the form:

 file://<path>[?<attribute type>=<file name mask>[&...]...]
 
The path should normally point to the directory where the files are. However, it may point to a file, if a single file has to be used. (This may be useful when loading a Policy AC). The filename of the AC may not match the hash of the DN in this case. The path may be absolute or relative; in the latter case the path is computed from the current directory of the application.

The query part of the URL tells the FileRepository the mapping between the attribute types and file name mask (a regular expression). You should specify at least one attribute type mapping (a URL is meaningless otherwise - no attributes can be retrieved). However, if the query is omitted altogether, "?attributeCertificateAttribute;binary=^.*\.ace$&userCertificate;binary=^.*\.cer$" is assumed.

If the attribute type doesn't have the ";binary" suffix, the file is treated as a text file with one value in it, and it is returned as a string. Otherwise, a byte[] is the attribute value.

Example:

 file:///c:/certificates/?attributeCertificateAttribute;binary=^.*\.ace$&userCertificate;binary=^.*\.cer$&eduPerson=^.*\.edu$
 

This URL will tell the File Repository to look for attributeCertificateAttribute;binary in *.ace files, and look for userCertificate;binary attributes in *.cer files in c:/certificates/ subdirectory.

Author:
A.Otenko

Field Summary
static java.lang.String BINARY_SUFFIX
          Suffix used to name binary attributes.
static java.lang.String DEFAULT_QUERY
          The default query assumed by the repository, if the query is omitted.
protected  RepositoryException diagnosis
           
static java.lang.String FILE_PROTOCOL
           
protected  java.io.File rootDir
           
protected  java.io.File[] rootFile
           
protected  int status
           
protected static java.io.File[] systemRoots
           
protected  java.util.Map typeMap
           
 
Fields inherited from interface issrg.utils.repository.AttributeRepository
FAILURE_STATUS, INHERENT_FAILURE_STATUS, PARTIAL_SUCCESS_STATUS, SUCCESS_STATUS
 
Constructor Summary
FileRepository(java.lang.String url)
          Constructs a File Repository given the URL as defined above.
 
Method Summary
 javax.naming.directory.Attributes getAttributes(java.security.Principal dn, java.lang.String[] attributes)
          This method is called by getAttribute and getAllAttributes methods and returns the attributes named, or all attributes, if no attribute names were provided.
 java.lang.Throwable getDiagnosis()
          This method returns the last Exception thrown or an exception the Repository wanted to throw very much, but did not, only because the error was not fatal.
 int getStatus()
          This method returns the status of the Repository.
 
Methods inherited from class issrg.utils.repository.DefaultRepository
getAllAttributes, getAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_PROTOCOL

public static final java.lang.String FILE_PROTOCOL
See Also:
Constant Field Values

BINARY_SUFFIX

public static final java.lang.String BINARY_SUFFIX
Suffix used to name binary attributes. It is ";binary".

See Also:
Constant Field Values

DEFAULT_QUERY

public static final java.lang.String DEFAULT_QUERY
The default query assumed by the repository, if the query is omitted. Current value is: "attributeCertificateAttribute;binary=^.*\.ace$&userCertificate;binary=^.*\.cer$"

See Also:
Constant Field Values

rootDir

protected java.io.File rootDir

rootFile

protected java.io.File[] rootFile

typeMap

protected java.util.Map typeMap

systemRoots

protected static final java.io.File[] systemRoots

status

protected int status

diagnosis

protected RepositoryException diagnosis
Constructor Detail

FileRepository

public FileRepository(java.lang.String url)
               throws RepositoryException
Constructs a File Repository given the URL as defined above.

Parameters:
url - - the file URL
Throws:
RepositoryException, - if the URL is not a valid file URL, or the path doesn't exist
RepositoryException
Method Detail

getAttributes

public javax.naming.directory.Attributes getAttributes(java.security.Principal dn,
                                                       java.lang.String[] attributes)
                                                throws RepositoryException
This method is called by getAttribute and getAllAttributes methods and returns the attributes named, or all attributes, if no attribute names were provided.

Parameters:
dn - - the name of the entry; FileRepository assumes they are RFC2253-compliant LDAP DNs
attributes - - the list of attribute names to return; if the array is null, all available attributes are returned from the entry
Returns:
Attributes filled with the attributes requested, or null, if there was a problem (getStatus will return FAILURE_STATUS)
Throws:
RepositoryException

getStatus

public int getStatus()
Description copied from interface: AttributeRepository
This method returns the status of the Repository.

Returns:
one of the *_STATUS values
See Also:
AttributeRepository.SUCCESS_STATUS, AttributeRepository.FAILURE_STATUS, AttributeRepository.PARTIAL_SUCCESS_STATUS, AttributeRepository.INHERENT_FAILURE_STATUS

getDiagnosis

public java.lang.Throwable getDiagnosis()
Description copied from interface: AttributeRepository
This method returns the last Exception thrown or an exception the Repository wanted to throw very much, but did not, only because the error was not fatal.

TODO: I am very keen to remove getStatus() method, and return DiagnosisException only; which will contain the status code in it and a reference to an embedded exception. Thus it will be possible to throw such an exception in cases of need, and still it will be possible to keep it for further information. I envisage that the PbaException is one of this sort: a DiagnosisException.

Returns:
the last Throwable the Repository was eager to throw or has thrown
See Also:
AttributeRepository.getStatus()