org.openpermis.policy.bean.basic
Class BasicRoleHierarchy

java.lang.Object
  extended by org.openpermis.policy.bean.basic.BasicPart
      extended by org.openpermis.policy.bean.basic.BasicPartBean
          extended by org.openpermis.policy.bean.basic.BasicRoleHierarchy
All Implemented Interfaces:
Serializable, IdentifiableBean, PartBean, RoleHierarchyBean, Identifiable, Part, RoleHierarchy

public class BasicRoleHierarchy
extends BasicPartBean
implements RoleHierarchyBean

A DAG of roles.

See Also:
Serialized Form
Since:
0.1.0

Nested Class Summary
private  class BasicRoleHierarchy.AdjacentSet
          Set for Adjacent Roles using SerialNumber as primary key.
static class BasicRoleHierarchy.Direction
           
private  class BasicRoleHierarchy.RoleSet
          Set for Roles using SerialNumber as primary key.
 
Field Summary
private  BasicRoleHierarchy.RoleSet roles
           
private static long serialVersionUID
           
private  BasicRoleHierarchy.AdjacentSet subroles
           
private  BasicRoleHierarchy.AdjacentSet superroles
           
 
Constructor Summary
protected BasicRoleHierarchy(SerialNumber serialNumber, URI identity)
          Creates a role hierarchy.
 
Method Summary
private  void addEdge(String role, String subrole)
          Adds an edge. precondition: edge not yet exists.
 void addRole(String role)
          Adds a new role in this role hierarchy, if not yet exists.
 void addRole(String role, Set<String> parentRoles)
          Adds a new role in this role hierarchy.
 void addRole(String role, String parentRole)
          Adds a new role in this role hierarchy.
protected  void appendPartDetails(StringBuilder sb)
          Appends the details of this extended part for the string representation of this part.
private  void appendRolePartDetails(StringBuilder sb)
           
private  boolean areRolesEqual(String role1, String role2)
          Checks for equal roles.
protected  boolean comparablePart(BasicPart part)
          Check if the part specified is comparable to this part.
 boolean connectRoles(String parentRole, String childRole)
          Convenience method: add an edge between two roles.
 boolean disconnectRoles(String parentRole, String childRole)
          Convenience method: remove an edge between two roles.
private  boolean edgeExists(String parentRole, String childRole)
          Returns true if childRole is a child-role of role.
 PartBean findBySerialNumber(SerialNumber partSerialNumber)
          Returns the part bean corresponding to the specified serial number. The basic implementation returns this bean if its serial number matches the one passed in or null if not.
private  String findNodeWithNoSubNodes(BasicRoleHierarchy.Direction direction, BasicRoleHierarchy.RoleSet subsetRoles)
          Try to find any node in given subsetRoles with no successors within given subsetRoles.
private  void fireRoleHierarchyEvent()
           
private  void forceArgumentNotNull(Object obj)
          Checks for null-argument.
private  void forceEdgeExists(String parentRole, String childRole)
          Checks for existence.
private  void forceEdgeNotExists(String parentRole, String childRole)
          Checks for existence.
private  void forceRoleExists(String role)
          Checks for existence.
private  void forceRoleNotExists(String role)
          Checks for existence.
private  void forceRolesExist(Collection<String> checkRoles)
          Checks for existence.
private  BasicRoleHierarchy.RoleSet getAdjacentRoles(String role, BasicRoleHierarchy.Direction direction)
          Returns a unmodifiable list of all adjacent role.
 Set<String> getChildRoles(String role)
          Returns a unmodifiable list of all children.
 Set<String> getLeafRoles()
          Returns a list of all roles with no children.
 Set<String> getParentRoles(String role)
          Returns a unmodifiable list of all parents.
 Set<String> getRoles()
          Returns a unmodifiable list of all roles in this hierarchy.
 Set<String> getRootRoles()
          Returns a list of all roles with no parents.
protected  String getSimpleClassName()
          Returns the simple implementation class name of this class.
 Set<String> getSubRoles(String role)
          Returns all sub roles of 'role' including 'role' itself.
 Set<String> getSuperRoles(String role)
          Returns all superior roles of 'role' including 'role' itself.
private  BasicRoleHierarchy.RoleSet getTransitiveClosure(String role, BasicRoleHierarchy.Direction direction)
           
private  boolean inTransitiveClosure(String role, String findRole, BasicRoleHierarchy.Direction direction)
          Returns true if there's a way from "role" to "findrole" using given direction. precondition: role exists and graph is cycle-free
 boolean isChildRole(String role, String childRole)
          Returns true if childRole is a child-role of role.
 boolean isLeafRole(String role)
          Returns true if role is leaf, i.e. has no children.
 boolean isParentRole(String role, String parentRole)
          Returns true if parentRole is a parent-role of role.
 boolean isPartValid(PartProblemReporter reporter)
          Checks if the extended state of this part is valid.
 boolean isRootRole(String role)
          Returns true if role is root, i.e. has no parents.
 boolean isSubRole(String role, String subRole)
          Returns true if subRole is a sub-role of role.
 boolean isSuperRole(String role, String superRole)
          Returns true if superRole is a super-role of role.
private  void removeEdge(String role, String subrole)
          Removes an edge. precondition: edge exists.
 void removeRole(String role)
          Removes a role from role hierarchy
 boolean renameRole(String role, String newName)
          Renames an existing role.
 boolean roleExists(String role)
          Checks if a role exists in this role hierarchy.
 void setChildRoles(String role, Set<String> childrenRoles)
          Set new children roles of a role.
 void setParentRoles(String role, Set<String> parentRoles)
          Set new parent roles of a role.
private  boolean treeClosed()
          Check if role tree is closed.
private  boolean treeTopologicallySortable()
          Check if role tree is cycle-free.
private  boolean treeTopologicallySortable(BasicRoleHierarchy.Direction direction)
          Check if role tree is cycle-free in the given direction.
 
Methods inherited from class org.openpermis.policy.bean.basic.BasicPartBean
addPropertyChangeListener, equalSerialNumber, firePropertyChange, getPartBeanType, getSerialNumber, getSerialNumberString, notifyIdentityChange, notifyNameChange, removePropertyChangeListener, toShortString
 
Methods inherited from class org.openpermis.policy.bean.basic.BasicPart
appendDetails, equalPart, equals, getIdentity, getName, hashCode, hasPartIdentity, hasPartName, isChildCollectionValid, isChildNotNull, isChildNullOrValid, isChildValid, isIdentityValid, isNameValid, isValid, partHashCode, reportProblem, setIdentity, setName, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.openpermis.policy.Part
equals, hashCode, isValid, toString
 
Methods inherited from interface org.openpermis.policy.Identifiable
getIdentity
 
Methods inherited from interface org.openpermis.policy.bean.PartBean
addPropertyChangeListener, equalSerialNumber, getPartBeanType, getSerialNumber, removePropertyChangeListener, toShortString
 
Methods inherited from interface org.openpermis.policy.Part
equals, hashCode, isValid, toString
 
Methods inherited from interface org.openpermis.policy.bean.IdentifiableBean
setIdentity
 
Methods inherited from interface org.openpermis.policy.Identifiable
getIdentity
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Constant Field Value:
-1728538401158979463L
Since:
0.1.0

roles

private final BasicRoleHierarchy.RoleSet roles
Since:
0.3.0

subroles

private final BasicRoleHierarchy.AdjacentSet subroles
Since:
0.3.0

superroles

private final BasicRoleHierarchy.AdjacentSet superroles
Since:
0.3.0
Constructor Detail

BasicRoleHierarchy

protected BasicRoleHierarchy(SerialNumber serialNumber,
                             URI identity)
Creates a role hierarchy.

Parameters:
serialNumber - the serial number of this part.
Method Detail

fireRoleHierarchyEvent

private void fireRoleHierarchyEvent()
Since:
0.3.0

areRolesEqual

private boolean areRolesEqual(String role1,
                              String role2)
Checks for equal roles.

Parameters:
role1 - the first role
role2 - the second role
Returns:
if roles are equal
Since:
0.3.0

edgeExists

private boolean edgeExists(String parentRole,
                           String childRole)
Returns true if childRole is a child-role of role.

Parameters:
parentRole - the role to start search from..
childRole - the role to find.
Returns:
true if found.
Since:
0.3.0

forceArgumentNotNull

private void forceArgumentNotNull(Object obj)
Checks for null-argument.

Parameters:
obj - the object to check.
Since:
0.3.0

forceEdgeExists

private void forceEdgeExists(String parentRole,
                             String childRole)
Checks for existence.

Parameters:
parentRole - the role to start search from..
childRole - the role to find.
Since:
0.3.0

forceEdgeNotExists

private void forceEdgeNotExists(String parentRole,
                                String childRole)
Checks for existence.

Parameters:
parentRole - the role to start search from..
childRole - the role to find.
Since:
0.3.0

forceRoleExists

private void forceRoleExists(String role)
Checks for existence.

Parameters:
role - the role to check
Since:
0.3.0

forceRolesExist

private void forceRolesExist(Collection<String> checkRoles)
Checks for existence.

Parameters:
checkRoles - the roles to check
Since:
0.3.0

forceRoleNotExists

private void forceRoleNotExists(String role)
Checks for existence.

Parameters:
role - the role to check
Since:
0.3.0

addEdge

private void addEdge(String role,
                     String subrole)
Adds an edge. precondition: edge not yet exists. precondition: edge not exists.

Parameters:
role - the parent role.
subrole - the child role.
Since:
0.3.0

removeEdge

private void removeEdge(String role,
                        String subrole)
Removes an edge. precondition: edge exists. precondition: edge exists.

Parameters:
role - the parent role.
subrole - the child role.
Since:
0.3.0

findNodeWithNoSubNodes

private String findNodeWithNoSubNodes(BasicRoleHierarchy.Direction direction,
                                      BasicRoleHierarchy.RoleSet subsetRoles)
Try to find any node in given subsetRoles with no successors within given subsetRoles. Please note: this code is simple, but not optimized. the determination of successors could easily be done in O(n) holding an additional map with adjacency-size

Parameters:
subsetRoles - the subset to search in.
Since:
0.1.0

treeTopologicallySortable

private boolean treeTopologicallySortable(BasicRoleHierarchy.Direction direction)
Check if role tree is cycle-free in the given direction.

Since:
0.3.0

treeTopologicallySortable

private boolean treeTopologicallySortable()
Check if role tree is cycle-free.

Since:
0.1.0

treeClosed

private boolean treeClosed()
Check if role tree is closed.

Since:
0.1.0

getAdjacentRoles

private BasicRoleHierarchy.RoleSet getAdjacentRoles(String role,
                                                    BasicRoleHierarchy.Direction direction)
Returns a unmodifiable list of all adjacent role.

Parameters:
role - role to search for
direction - {DIRECTION_CHILDREN, DIRECTION_PARENTS}
Returns:
list of adjacent roles.
Since:
0.3.0

getTransitiveClosure

private BasicRoleHierarchy.RoleSet getTransitiveClosure(String role,
                                                        BasicRoleHierarchy.Direction direction)
Since:
0.3.0

inTransitiveClosure

private boolean inTransitiveClosure(String role,
                                    String findRole,
                                    BasicRoleHierarchy.Direction direction)
Returns true if there's a way from "role" to "findrole" using given direction. precondition: role exists and graph is cycle-free

Parameters:
role - the role to start search.
findRole - the role to find
Returns:
true if the findRole could be found.
Since:
0.3.0

getSuperRoles

public Set<String> getSuperRoles(String role)
Returns all superior roles of 'role' including 'role' itself.

Specified by:
getSuperRoles in interface RoleHierarchy
Parameters:
role - identifies a role in the hierarchy.
Returns:
all superior roles of 'role' including 'role' itself.
Since:
0.3.0

getSubRoles

public Set<String> getSubRoles(String role)
Returns all sub roles of 'role' including 'role' itself.

Specified by:
getSubRoles in interface RoleHierarchy
Parameters:
role - identifies a role in the hierarchy.
Returns:
all sub roles of 'role' including 'role' itself.
Since:
0.3.0

roleExists

public boolean roleExists(String role)
Checks if a role exists in this role hierarchy.

Specified by:
roleExists in interface RoleHierarchyBean
Parameters:
role - the role to search.
Returns:
if found * @since 0.3.0

getRoles

public Set<String> getRoles()
Returns a unmodifiable list of all roles in this hierarchy.

Specified by:
getRoles in interface RoleHierarchyBean
Returns:
list of roles in this hierarchy.
Since:
0.1.0

getRootRoles

public Set<String> getRootRoles()
Returns a list of all roles with no parents.

Specified by:
getRootRoles in interface RoleHierarchyBean
Returns:
list of all roles with no parents.
Since:
0.3.0

getLeafRoles

public Set<String> getLeafRoles()
Returns a list of all roles with no children. precondition: role exists.

Specified by:
getLeafRoles in interface RoleHierarchyBean
Returns:
list of all roles with no children.
Since:
0.3.0

getChildRoles

public Set<String> getChildRoles(String role)
Returns a unmodifiable list of all children. precondition: role exists.

Specified by:
getChildRoles in interface RoleHierarchyBean
Returns:
list of children roles.
Since:
0.3.0

getParentRoles

public Set<String> getParentRoles(String role)
Returns a unmodifiable list of all parents. precondition: role exists.

Specified by:
getParentRoles in interface RoleHierarchyBean
Returns:
list of parent roles.
Since:
0.3.0

isRootRole

public boolean isRootRole(String role)
Returns true if role is root, i.e. has no parents. precondition: role exists.

Specified by:
isRootRole in interface RoleHierarchyBean
Parameters:
role - the role to check.
Returns:
true if found.
Since:
0.3.0

isLeafRole

public boolean isLeafRole(String role)
Returns true if role is leaf, i.e. has no children. precondition: role exists.

Specified by:
isLeafRole in interface RoleHierarchyBean
Parameters:
role - the role to check.
Returns:
true if found.
Since:
0.3.0

isSubRole

public boolean isSubRole(String role,
                         String subRole)
Returns true if subRole is a sub-role of role. precondition: both roles exist.

Specified by:
isSubRole in interface RoleHierarchyBean
Parameters:
role - the role to start search from.
subRole - the role to find.
Returns:
true if found.
Since:
0.3.0

isSuperRole

public boolean isSuperRole(String role,
                           String superRole)
Returns true if superRole is a super-role of role. precondition: both roles exist.

Specified by:
isSuperRole in interface RoleHierarchyBean
Parameters:
role - the role to start search from..
superRole - the role to find.
Returns:
true if found.
Since:
0.3.0

isChildRole

public boolean isChildRole(String role,
                           String childRole)
Returns true if childRole is a child-role of role. precondition: both roles exist.

Specified by:
isChildRole in interface RoleHierarchyBean
Parameters:
role - the role to start search from..
childRole - the role to find.
Returns:
true if found.
Since:
0.3.0

isParentRole

public boolean isParentRole(String role,
                            String parentRole)
Returns true if parentRole is a parent-role of role. precondition: both roles exist.

Specified by:
isParentRole in interface RoleHierarchyBean
Parameters:
role - the role to start search from..
parentRole - the role to find.
Returns:
true if found.
Since:
0.3.0

setChildRoles

public void setChildRoles(String role,
                          Set<String> childrenRoles)
Set new children roles of a role. precondition: all roles exist.

Specified by:
setChildRoles in interface RoleHierarchyBean
Parameters:
role - role to set children for.
childrenRoles - children roles to set
Since:
0.3.0

setParentRoles

public void setParentRoles(String role,
                           Set<String> parentRoles)
Set new parent roles of a role. precondition: all roles exist.

Specified by:
setParentRoles in interface RoleHierarchyBean
Parameters:
role - role to set parents for.
parentRoles - parent roles to set
Since:
0.3.0

connectRoles

public boolean connectRoles(String parentRole,
                            String childRole)
Convenience method: add an edge between two roles. Nothing is done if either role is null oder edge already exists.

Specified by:
connectRoles in interface RoleHierarchyBean
Parameters:
parentRole - parent role.
childRole - child role
Returns:
true if edge was added
Since:
0.3.0

disconnectRoles

public boolean disconnectRoles(String parentRole,
                               String childRole)
Convenience method: remove an edge between two roles. Nothing is done if either role is null oder edge not exists.

Specified by:
disconnectRoles in interface RoleHierarchyBean
Parameters:
parentRole - parent role.
childRole - child role
Returns:
true if edge was removed
Since:
0.3.0

addRole

public void addRole(String role)
Adds a new role in this role hierarchy, if not yet exists. precondition: role not yet exists.

Specified by:
addRole in interface RoleHierarchyBean
Parameters:
role - the new role to be added.
Since:
0.3.0

addRole

public void addRole(String role,
                    String parentRole)
Adds a new role in this role hierarchy. precondition: role not yet exists, parentRole exists.

Specified by:
addRole in interface RoleHierarchyBean
Parameters:
role - the new role to be added.
parentRole - the parent where the role is appended.
Since:
0.3.0

addRole

public void addRole(String role,
                    Set<String> parentRoles)
Adds a new role in this role hierarchy. precondition: role not yet exists, parentRoles exist.

Specified by:
addRole in interface RoleHierarchyBean
Parameters:
role - the new role to be added.
parentRoles - the parents where the role is appended.
Since:
0.3.0

removeRole

public void removeRole(String role)
Removes a role from role hierarchy. * precondition: role exists.

Specified by:
removeRole in interface RoleHierarchyBean
Parameters:
role - the role to be removed.
Since:
0.3.0

renameRole

public boolean renameRole(String role,
                          String newName)
Description copied from interface: RoleHierarchyBean
Renames an existing role.

The renamed role will keep its super and sub roles.

Specified by:
renameRole in interface RoleHierarchyBean
Parameters:
role - the role to be renamed.
newName - the new name for the role
Returns:
true if role was renamed.
Since:
0.3.0

findBySerialNumber

public PartBean findBySerialNumber(SerialNumber partSerialNumber)
Description copied from class: BasicPartBean
Returns the part bean corresponding to the specified serial number.

If the part bean contains other part beans, it searches its child beans recursively.

The basic implementation returns this bean if its serial number matches the one passed in or null if not. Subclasses that contain other parts must traverse their children.

Specified by:
findBySerialNumber in interface PartBean
Overrides:
findBySerialNumber in class BasicPartBean
Parameters:
partSerialNumber - the SerialNumber of the part bean to return.
Returns:
the matching PartBean or null if no matching part bean is found.
Since:
0.1.0

isPartValid

public boolean isPartValid(PartProblemReporter reporter)
Description copied from class: BasicPart
Checks if the extended state of this part is valid.

Overrides:
isPartValid in class BasicPart
Parameters:
reporter - the problem reporter to use, may be null.
See Also:
BasicPart, Part.isValid(PartProblemReporter), BasicPart.reportProblem(org.openpermis.policy.PartProblemReporter, org.openpermis.policy.PartProblemReporter.ProblemMessage, java.lang.Object...)
Since:
0.1.0

comparablePart

protected boolean comparablePart(BasicPart part)
Description copied from class: BasicPart
Check if the part specified is comparable to this part.

Specified by:
comparablePart in class BasicPart
Parameters:
part - the part to check.
Returns:
true if the part supplied is comparable to this part.
See Also:
BasicPart
Since:
0.1.0

getSimpleClassName

protected String getSimpleClassName()
Description copied from class: BasicPart
Returns the simple implementation class name of this class.

If your implementation represents an interface implementation return the interface simple class name here. In short: return the instance you are checking against in BasicPart.comparablePart(BasicPart).

Overrides:
getSimpleClassName in class BasicPart
Returns:
the simple implementation class name of this class.
Since:
0.1.0

appendRolePartDetails

private void appendRolePartDetails(StringBuilder sb)
Since:
0.3.0

appendPartDetails

protected void appendPartDetails(StringBuilder sb)
Description copied from class: BasicPart
Appends the details of this extended part for the string representation of this part.

Overrides:
appendPartDetails in class BasicPart
Parameters:
sb - the string builder to add the details to.
See Also:
BasicPart, BasicPart.appendDetails(StringBuilder, String, Object)
Since:
0.1.0


PERMIS Role Based Access Control 0.4.0 (Build 15)
2009/05/20 08:14:59
Copyright (c) 2002-2007 Ergon Informatik AG