SunTM's XACML Implementation for JavaTM

com.sun.xacml.finder.impl
Class FilePolicyModule

java.lang.Object
  extended bycom.sun.xacml.finder.PolicyFinderModule
      extended bycom.sun.xacml.finder.impl.FilePolicyModule
All Implemented Interfaces:
ErrorHandler

public class FilePolicyModule
extends PolicyFinderModule
implements ErrorHandler

This module represents a collection of files containing polices, each of which will be searched through when trying to find a policy that is applicable to a specific request.

Note: this module is provided only as an example and for testing purposes. It is not part of the standard, and it should not be relied upon for production systems. In the future, this will likely be moved into a package with other similar example and testing code.

Since:
1.0

Field Summary
static String JAXP_SCHEMA_LANGUAGE
           
static String JAXP_SCHEMA_SOURCE
           
static String POLICY_SCHEMA_PROPERTY
          The property which is used to specify the schema file to validate against (if any)
static String W3C_XML_SCHEMA
           
 
Constructor Summary
FilePolicyModule()
          Constructor which retrieves the schema file to validate policies against from the POLICY_SCHEMA_PROPERTY.
FilePolicyModule(File schemaFile)
          Constructor that uses the specified input as the schema file to validate policies against.
FilePolicyModule(List fileNames)
          Constructor that specifies a set of initial policy files to use.
 
Method Summary
 boolean addPolicy(String filename)
          Adds a file (containing a policy) to the collection of filenames associated with this module.
 void error(SAXParseException exception)
          Standard handler routine for the XML parsing.
 void fatalError(SAXParseException exception)
          Standard handler routine for the XML parsing.
 PolicyFinderResult findPolicy(EvaluationCtx context)
          Finds a policy based on a request's context.
 void init(PolicyFinder finder)
          Initializes the FilePolicyModule by loading the policies contained in the collection of files associated with this module.
 boolean isRequestSupported()
          Indicates whether this module supports finding policies based on a request (target matching).
static AbstractPolicy loadPolicy(String filename, PolicyFinder finder)
          Loads a policy from the specified filename and uses the specified PolicyFinder to help with instantiating PolicySets.
static AbstractPolicy loadPolicy(String filename, PolicyFinder finder, File schemaFile, ErrorHandler handler)
          Loads a policy from the specified filename, using the specified PolicyFinder to help with instantiating PolicySets, and using the specified input as the schema file to validate policies against.
 void warning(SAXParseException exception)
          Standard handler routine for the XML parsing.
 
Methods inherited from class com.sun.xacml.finder.PolicyFinderModule
findPolicy, getIdentifier, invalidateCache, isIdReferenceSupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POLICY_SCHEMA_PROPERTY

public static final String POLICY_SCHEMA_PROPERTY
The property which is used to specify the schema file to validate against (if any)

See Also:
Constant Field Values

JAXP_SCHEMA_LANGUAGE

public static final String JAXP_SCHEMA_LANGUAGE
See Also:
Constant Field Values

W3C_XML_SCHEMA

public static final String W3C_XML_SCHEMA
See Also:
Constant Field Values

JAXP_SCHEMA_SOURCE

public static final String JAXP_SCHEMA_SOURCE
See Also:
Constant Field Values
Constructor Detail

FilePolicyModule

public FilePolicyModule()
Constructor which retrieves the schema file to validate policies against from the POLICY_SCHEMA_PROPERTY. If the retrieved property is null, then no schema validation will occur.


FilePolicyModule

public FilePolicyModule(File schemaFile)
Constructor that uses the specified input as the schema file to validate policies against. If schema validation is not desired, a null value should be used.

Parameters:
schemaFile - the schema file to validate policies against, or null if schema validation is not desired.

FilePolicyModule

public FilePolicyModule(List fileNames)
Constructor that specifies a set of initial policy files to use. No schema validation is performed.

Parameters:
fileNames - a List of Strings that identify policy files
Method Detail

isRequestSupported

public boolean isRequestSupported()
Indicates whether this module supports finding policies based on a request (target matching). Since this module does support finding policies based on requests, it returns true.

Overrides:
isRequestSupported in class PolicyFinderModule
Returns:
true, since finding policies based on requests is supported

init

public void init(PolicyFinder finder)
Initializes the FilePolicyModule by loading the policies contained in the collection of files associated with this module. This method also uses the specified PolicyFinder to help in instantiating PolicySets.

Specified by:
init in class PolicyFinderModule
Parameters:
finder - a PolicyFinder used to help in instantiating PolicySets

addPolicy

public boolean addPolicy(String filename)
Adds a file (containing a policy) to the collection of filenames associated with this module.

Parameters:
filename - the file to add to this module's collection of files

loadPolicy

public static AbstractPolicy loadPolicy(String filename,
                                        PolicyFinder finder)
Loads a policy from the specified filename and uses the specified PolicyFinder to help with instantiating PolicySets.

Parameters:
filename - the file to load the policy from
finder - a PolicyFinder used to help in instantiating PolicySets
Returns:
a (potentially schema-validated) policy associated with the specified filename, or null if there was an error

loadPolicy

public static AbstractPolicy loadPolicy(String filename,
                                        PolicyFinder finder,
                                        File schemaFile,
                                        ErrorHandler handler)
Loads a policy from the specified filename, using the specified PolicyFinder to help with instantiating PolicySets, and using the specified input as the schema file to validate policies against. If schema validation is not desired, a null value should be used for schemaFile

Parameters:
filename - the file to load the policy from
finder - a PolicyFinder used to help in instantiating PolicySets
schemaFile - the schema file to validate policies against, or null if schema validation is not desired
handler - an error handler used to print warnings and errors during parsing
Returns:
a (potentially schema-validated) policy associated with the specified filename, or null if there was an error

findPolicy

public PolicyFinderResult findPolicy(EvaluationCtx context)
Finds a policy based on a request's context. This may involve using the request data as indexing data to lookup a policy. This will always do a Target match to make sure that the given policy applies. If more than one applicable policy is found, this will return an error. NOTE: this is basically just a subset of the OnlyOneApplicable Policy Combining Alg that skips the evaluation step. See comments in there for details on this algorithm.

Overrides:
findPolicy in class PolicyFinderModule
Parameters:
context - the representation of the request data
Returns:
the result of trying to find an applicable policy

warning

public void warning(SAXParseException exception)
             throws SAXException
Standard handler routine for the XML parsing.

Specified by:
warning in interface ErrorHandler
Parameters:
exception - information on what caused the problem
Throws:
SAXException

error

public void error(SAXParseException exception)
           throws SAXException
Standard handler routine for the XML parsing.

Specified by:
error in interface ErrorHandler
Parameters:
exception - information on what caused the problem
Throws:
SAXException - always to halt parsing on errors

fatalError

public void fatalError(SAXParseException exception)
                throws SAXException
Standard handler routine for the XML parsing.

Specified by:
fatalError in interface ErrorHandler
Parameters:
exception - information on what caused the problem
Throws:
SAXException - always to halt parsing on errors

Sun's XACML Implementation Version 1.2

Copyright 2003-2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

Sun, Sun Microsystems, the Sun Logo, and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.