org.openpermis.policy.io.xml
Class PermisXmlReader

java.lang.Object
  extended by org.openpermis.policy.io.xml.PermisXmlReader
All Implemented Interfaces:
PolicyReader

public class PermisXmlReader
extends Object
implements PolicyReader

Policy reader implementation for Permis XML policies.

Since:
0.1.0

Constructor Summary
PermisXmlReader(Reader reader, PartBeanFactory partFactory)
          Creates a new policy reader that uses the specified reader but has not problem reporter.
PermisXmlReader(Reader reader, PartBeanFactory partFactory, ProblemReporter problemReporter)
          Creates a new policy reader that uses the specified reader.
 
Method Summary
protected  URI createUri(String string, String element, String attribute)
          Creates an URI for the specified input string.
protected  String encode(String ldapDn)
          Encodes an LDAP DN to a valid URI name.
protected  String expectAttribute(String attribute)
          Returns the value of the attribute of the current element.
protected  String getLocation()
          Returns the current reader location in format "line:column".
protected  boolean isElement(int type, String name)
          Returns true if the cursor points to the element of type and name.
protected  void next(int type)
          Moves the cursor of parser to the next position of the given XMLStreamConstants type.
protected  void nextElement()
          Moves the cursor of parser to the next element, it may be a starting or ending element.
protected  void nextElement(int findType, String findName)
          Moves the cursor of parser to the next element of type findType and element name findName.
protected  boolean nextElement(int findType, String findName, int stopType, String stopName)
          Moves the cursor of parser to the next element of type findType and element name findName but the cursor will stop on stopType and stopName.
protected  String optionalAttribute(String attribute)
          Returns the value of the optional attribute, null if attribute does not exist.
protected  Map<String,Action> readActionPolicy(Map<String,Class<?>> map)
          Reads an action policy and fill map with parameter name and type.
protected  Predicate readCondition()
          Reads a if statement condition and returns it as a Predicate.
protected  List<List<URI>> readDomainURIs(String domainSpecElementType)
          Reads all the URIs of a domain definition.
protected  ObligationCollection readObligationList(Map<String,Obligation> obligations)
          Reads a list of obligations.
protected  Map<String,Obligation> readObligationPolicy()
          Reads an obligation policy.
 Policy readPolicy()
          Parses the stream and build the policy.
protected  Map<String,Domain> readResourceDomainPolicy()
          Reads a resource domain policy.
protected  RoleAssignmentRuleCollection readRoleAssignmentPolicy(Map<String,DomainBean> subjectDomains, Map<String,RoleHierarchyBean> hierachies, Map<String,Authority> soas)
          Reads a role assignment policy.
protected  Map<String,RoleHierarchyBean> readRoleHierarchyPolicy()
          Reads a role hierarchy policy.
protected  Collection<Role> readRoleList(Map<String,RoleHierarchyBean> hierarchies)
          Reads a role list element.
protected  Map<String,Authority> readSoaPolicy()
          Reads a soa policy.
protected  Map<String,DomainBean> readSubjectDomainPolicy()
          Reads a subject domain policy.
protected  TargetAccessRuleCollection readTargetAccessPolicy(Map<String,Domain> domains, Map<String,RoleHierarchyBean> hierarchies, Map<String,Action> actions, Map<String,Target> targets, Map<String,Obligation> obligations)
          Reads a target access policy.
protected  Map<String,Target> readTargetPolicy(Map<String,Domain> domains, Map<String,Action> actions)
          Reads a target policy.
protected  TimePeriodConstraint readValidity(org.joda.time.DateTimeZone defaultZone)
          Reads the validity of a role assignment rule.
protected  void reportProblem(ProblemType type, Object... parameters)
          Reports a problem of the specified type with the given parameters.
protected  void setParameterMap(Map<String,Class<?>> parameterMap)
          Defines the relation (actionname, parametername, type).
protected  void setZone(org.joda.time.DateTimeZone zone)
          Sets the time zone of this policy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PermisXmlReader

public PermisXmlReader(Reader reader,
                       PartBeanFactory partFactory)
                throws PolicyException
Creates a new policy reader that uses the specified reader but has not problem reporter.

Readers created by this constructor will throw a PolicyException if a problem is encountered that could have been reported to a ProblemReporter.

Parameters:
reader - the reader to read the policy from.
partFactory - the PartBeanFactory to use for creating policy parts.
See Also:
PermisXmlReader(Reader, PartBeanFactory, ProblemReporter)
Throws:
PolicyException - if the XML reader cannot be created.
Since:
0.1.0

PermisXmlReader

public PermisXmlReader(Reader reader,
                       PartBeanFactory partFactory,
                       ProblemReporter problemReporter)
                throws PolicyException
Creates a new policy reader that uses the specified reader.

Readers created with a null ProblemReporter will throw a PolicyException if a non-fatal problem is encountered that could have been reported to a ProblemReporter.

Parameters:
reader - the reader to read the policy from.
partFactory - the PartBeanFactory to use for creating policy parts.
problemReporter - reporter for serialization problems, may be null.
Throws:
PolicyException - if the XML reader cannot be created.
Since:
0.3.0
Method Detail

getLocation

protected String getLocation()
Returns the current reader location in format "line:column".

Returns:
the current reader location as string.
Since:
0.3.0

reportProblem

protected void reportProblem(ProblemType type,
                             Object... parameters)
                      throws PolicyException
Reports a problem of the specified type with the given parameters.

The current reader location is passed as the first parameter.

Parameters:
type - the problem type to report.
parameters - the parameters to pass on.
Throws:
PolicyException - if there is no problem reporter available.
Since:
0.3.0

setZone

protected void setZone(org.joda.time.DateTimeZone zone)
Sets the time zone of this policy.

Parameters:
zone - a DateTimeZone.
Since:
0.1.0

setParameterMap

protected void setParameterMap(Map<String,Class<?>> parameterMap)
Defines the relation (actionname, parametername, type).

Parameters:
parameterMap - the parameters.
Since:
0.1.0

nextElement

protected void nextElement()
                    throws PolicyException
Moves the cursor of parser to the next element, it may be a starting or ending element.

Throws:
PolicyException - if next element could not be found.

isElement

protected boolean isElement(int type,
                            String name)
                     throws PolicyException
Returns true if the cursor points to the element of type and name.

Returns:
true if the cursor points to the element of type and name.
Throws:
PolicyException - if next element could not be found.

next

protected void next(int type)
             throws PolicyException
Moves the cursor of parser to the next position of the given XMLStreamConstants type.

Parameters:
type - type of the next position.
Throws:
PolicyException - if next position could not be found.

nextElement

protected void nextElement(int findType,
                           String findName)
                    throws PolicyException
Moves the cursor of parser to the next element of type findType and element name findName.

Parameters:
findType - type of the next element.
findName - name of the next element.
Throws:
PolicyException - if next element with name could not be found.

nextElement

protected boolean nextElement(int findType,
                              String findName,
                              int stopType,
                              String stopName)
                       throws PolicyException
Moves the cursor of parser to the next element of type findType and element name findName but the cursor will stop on stopType and stopName.

Parameters:
findType - type of the next element to find.
findName - name of the next element to find.
stopType - type of the next element to stop.
stopName - name of the next element to stop.
Returns:
true if cursor on find position, false if cursor on stop position.
Throws:
PolicyException - if no next element could not be found.

expectAttribute

protected String expectAttribute(String attribute)
                          throws PolicyException
Returns the value of the attribute of the current element.

Parameters:
attribute - name of the attribute.
Returns:
String the attribute value.
Throws:
PolicyException - if no such attribute exists.
Since:
0.1.0

optionalAttribute

protected String optionalAttribute(String attribute)
Returns the value of the optional attribute, null if attribute does not exist.

Parameters:
attribute - name of the attribute.
Returns:
String the attribute value if exist, null otherwise.
Since:
0.1.0

encode

protected String encode(String ldapDn)
                 throws UnsupportedEncodingException
Encodes an LDAP DN to a valid URI name.

Parameters:
ldapDn - the LDAP DN to encode.
Returns:
the encoded LDAP DN.
Throws:
UnsupportedEncodingException - if encoding fails.
Since:
0.3.0

createUri

protected URI createUri(String string,
                        String element,
                        String attribute)
                 throws URISyntaxException,
                        PolicyException
Creates an URI for the specified input string.

If the URI cannot be created the string is first converted to a valid URI name and then converted. This conversion will issue a warning.

Parameters:
string - the string to be converted.
element - the element for which to create the URI.
attribute - the attribute that holds the URI.
Returns:
the URI requested.
Throws:
URISyntaxException - if the conversion fails and an URI cannot be created.
PolicyException - if a conversion takes place and there is no problem reporter.
Since:
0.3.0

readPolicy

public Policy readPolicy()
                  throws PolicyException
Parses the stream and build the policy.

Specified by:
readPolicy in interface PolicyReader
Returns:
the policy.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.1.0

readSubjectDomainPolicy

protected Map<String,DomainBean> readSubjectDomainPolicy()
                                                  throws PolicyException
Reads a subject domain policy.

Returns:
a map of subject domains.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.1.0

readResourceDomainPolicy

protected Map<String,Domain> readResourceDomainPolicy()
                                               throws PolicyException
Reads a resource domain policy.

Returns:
a map of resouce domains.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.1.0

readDomainURIs

protected List<List<URI>> readDomainURIs(String domainSpecElementType)
                                  throws PolicyException
Reads all the URIs of a domain definition.

Returns:
an List of URI Lists.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.3.0

readRoleHierarchyPolicy

protected Map<String,RoleHierarchyBean> readRoleHierarchyPolicy()
                                                         throws PolicyException
Reads a role hierarchy policy.

Returns:
a map of role hierarchies.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.1.0

readSoaPolicy

protected Map<String,Authority> readSoaPolicy()
                                       throws PolicyException
Reads a soa policy.

Returns:
a map of subjects.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.1.0

readRoleAssignmentPolicy

protected RoleAssignmentRuleCollection readRoleAssignmentPolicy(Map<String,DomainBean> subjectDomains,
                                                                Map<String,RoleHierarchyBean> hierachies,
                                                                Map<String,Authority> soas)
                                                         throws PolicyException
Reads a role assignment policy.

Parameters:
subjectDomains - existing subject domains.
hierachies - existing role hierarchies.
soas - existing soas.
Returns:
a role assignment rule collection.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.3.0

readTargetPolicy

protected Map<String,Target> readTargetPolicy(Map<String,Domain> domains,
                                              Map<String,Action> actions)
                                       throws PolicyException
Reads a target policy.

Parameters:
domains - read Domains.
actions - read Actions.
Returns:
a map of targets.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.3.0

readActionPolicy

protected Map<String,Action> readActionPolicy(Map<String,Class<?>> map)
                                       throws PolicyException
Reads an action policy and fill map with parameter name and type.

Parameters:
map - a mapping of parameter name and type.
Returns:
a map of actions.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.1.0

readTargetAccessPolicy

protected TargetAccessRuleCollection readTargetAccessPolicy(Map<String,Domain> domains,
                                                            Map<String,RoleHierarchyBean> hierarchies,
                                                            Map<String,Action> actions,
                                                            Map<String,Target> targets,
                                                            Map<String,Obligation> obligations)
                                                     throws PolicyException
Reads a target access policy.

Parameters:
domains - existing target domains.
hierarchies - existing role hierarchies.
actions - existing actions.
targets - existing targets.
Returns:
collection of target access rules.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.3.0

readObligationPolicy

protected Map<String,Obligation> readObligationPolicy()
                                               throws PolicyException
Reads an obligation policy.

Returns:
a map of obligations.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.3.0

readObligationList

protected ObligationCollection readObligationList(Map<String,Obligation> obligations)
                                           throws PolicyException
Reads a list of obligations.

Parameters:
obligations - existing obligations.
Returns:
an ObligationCollection.
Throws:
PolicyException
Since:
0.3.0

readValidity

protected TimePeriodConstraint readValidity(org.joda.time.DateTimeZone defaultZone)
                                     throws PolicyException
Reads the validity of a role assignment rule.

Returns:
a TimePeriodConstraint.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.3.0

readRoleList

protected Collection<Role> readRoleList(Map<String,RoleHierarchyBean> hierarchies)
                                 throws PolicyException
Reads a role list element.

Parameters:
hierarchies - the existing role hierarchies.
Returns:
set of roles.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.1.0

readCondition

protected Predicate readCondition()
                           throws PolicyException
Reads a if statement condition and returns it as a Predicate.

Returns:
the condition as Predicate.
Throws:
PolicyException - signals a problem in reading the policy.
Since:
0.3.0


OpenPermis Role Based Access Control 0.9.0 (Build 16)
2009/08/13 07:16:59
Copyright (c) 2002-2007 Ergon Informatik AG