org.sakaiproject.component.legacy.authzGroup
Class BaseAuthzGroup

java.lang.Object
  extended byorg.sakaiproject.component.legacy.authzGroup.BaseAuthzGroup
All Implemented Interfaces:
AuthzGroup, Comparable, Edit, Entity, Serializable

public class BaseAuthzGroup
extends Object
implements AuthzGroup

BaseAuthzGroup is an implementation of the AuthGroup API AuthzGroup.

Author:
Sakai Software Development Team
See Also:
Serialized Form

Field Summary
protected  boolean m_active
          Active flag.
protected  Time m_createdTime
          The time created.
protected  String m_createdUserId
          The created user id.
protected  String m_event
          The event code for this azGroup.
protected  String m_id
          The azGroup id.
protected  boolean m_isNew
          True if created by the "new" call rather than "add" - it has not yet been stored.
protected  Integer m_key
          The internal 'db' key.
protected  Time m_lastModifiedTime
          The time last modified.
protected  String m_lastModifiedUserId
          The last modified user id.
protected  boolean m_lazy
          Set while the azGroup is not fully loaded from the storage.
protected  String m_maintainRole
          The role to use for maintain users.
protected  ResourcePropertiesEdit m_properties
          The properties.
protected  String m_providerRealmId
          The external azGroup id, or null if not defined.
protected  Map m_roles
          Map of Role id to a Role defined in this AuthzGroup.
protected  Map m_userGrants
          Map of userId to Member
 
Fields inherited from interface org.sakaiproject.service.legacy.entity.Entity
SEPARATOR
 
Constructor Summary
BaseAuthzGroup(AuthzGroup azGroup)
          Construct from another AuthzGroup object.
BaseAuthzGroup(Element el)
          Construct from information in XML.
BaseAuthzGroup(Integer dbid, String id, String providerId, String maintainRole, String createdBy, Time createdOn, String modifiedBy, Time modifiedOn)
          (Re)Construct from parts.
BaseAuthzGroup(String id)
          Construct.
 
Method Summary
protected  void activate()
          Enable editing.
 void addMember(String user, String roleId, boolean active, boolean provided)
          Add a member to the AuthzGroup.
 Role addRole(String id)
          Create a new Role within this AuthzGroup.
 Role addRole(String id, Role other)
          Create a new Role within this AuthzGroup, as a copy of this other role
protected  void closeEdit()
          Close the azGroup object - it cannot be used after this.
 int compareTo(Object obj)
          
 boolean equals(Object obj)
          
 User getCreatedBy()
          
 Time getCreatedTime()
          
 String getDescription()
          
protected  String getEvent()
          Access the event code for this azGroup.
 String getId()
          Access the id of the entity.
 Integer getKey()
          {@inheritDoc}
 String getMaintainRole()
          Access the name of the role to use for giving a user membership with "maintain" access.
 Member getMember(String user)
          Access the user's membership record for this AuthzGroup; the role, and status flags.
 Set getMembers()
          Access all Membership records defined for this AuthzGroup.
 User getModifiedBy()
          
 Time getModifiedTime()
          
 ResourceProperties getProperties()
          Access the entity's properties.
 ResourcePropertiesEdit getPropertiesEdit()
          Access the resource's properties for modification
 String getProviderGroupId()
          Access the group id for the GroupProvider for this AuthzGroup.
 String getReference()
          Access the internal reference which can be used to access the entity from within the system.
 String getReference(String rootProperty)
          Access the alternate internal reference which can be used to access the entity from within the system.
 Role getRole(String id)
          Access a Role defined in this AuthzGroup.
 Set getRoles()
          Access all Roles defined for this AuthzGroup.
 Set getRolesIsAllowed(String function)
          Access all roles that have been granted permission to this function.
 String getUrl()
          Access the URL which can be used to access the entity.
 String getUrl(String rootProperty)
          Access the alternate URL which can be used to access the entity.
 Role getUserRole(String user)
          Access the active role for this user's membership.
 Set getUsers()
          Access all users who have active role membership in the AuthzGroup.
 Set getUsersHasRole(String role)
          Access all users who have an active role membership with this role.
 Set getUsersIsAllowed(String lock)
          Access all users who have an active role membership to a role that is allowed this function.
 int hashCode()
          
 boolean hasRole(String user, String role)
          Test if this user has a membership in this AuthzGroup that has this role and is active.
 boolean isActiveEdit()
          Check to see if the azGroup is still active, or has already been closed.
 boolean isAllowed(String user, String lock)
          Test if this user is allowed to perform the function in this AuthzGroup.
 boolean isEmpty()
          Is this AuthzGroup empty of any roles or membership?
 boolean keepIntersection(AuthzGroup other)
          Adjust membership so that active members are all active in other, and inactive members are all defined in other
 void removeMember(String user)
          Remove membership for for this user from the AuthzGroup.
 void removeMembers()
          Remove all membership from this AuthzGroup.
 void removeRole(String roleId)
          Remove this Role from this AuthzGroup. Any grants of this Role in the AuthzGroup are also removed.
 void removeRoles()
          Remove all Roles from this AuthzGroup.
protected  void set(AuthzGroup azGroup)
          Take all values from this object.
protected  void setAll(AuthzGroup azGroup)
          Take all values from this object.
protected  void setEvent(String event)
          Set the event code for this azGroup.
 void setMaintainRole(String role)
          Set the role name to use for "maintain" access.
 void setProviderGroupId(String id)
          Set the external group id for the GroupProvider for this AuthzGroup (set to null to have none).
 Element toXml(Document doc, Stack stack)
          Serialize the entity into XML, adding an element to the doc under the top of the stack element.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_key

protected Integer m_key
The internal 'db' key.


m_id

protected String m_id
The azGroup id.


m_properties

protected ResourcePropertiesEdit m_properties
The properties.


m_userGrants

protected Map m_userGrants
Map of userId to Member


m_roles

protected Map m_roles
Map of Role id to a Role defined in this AuthzGroup.


m_providerRealmId

protected String m_providerRealmId
The external azGroup id, or null if not defined.


m_maintainRole

protected String m_maintainRole
The role to use for maintain users.


m_createdUserId

protected String m_createdUserId
The created user id.


m_lastModifiedUserId

protected String m_lastModifiedUserId
The last modified user id.


m_createdTime

protected Time m_createdTime
The time created.


m_lastModifiedTime

protected Time m_lastModifiedTime
The time last modified.


m_lazy

protected boolean m_lazy
Set while the azGroup is not fully loaded from the storage.


m_event

protected String m_event
The event code for this azGroup.


m_active

protected boolean m_active
Active flag.


m_isNew

protected boolean m_isNew
True if created by the "new" call rather than "add" - it has not yet been stored.

Constructor Detail

BaseAuthzGroup

public BaseAuthzGroup(String id)
Construct.

Parameters:
id - The azGroup id.

BaseAuthzGroup

public BaseAuthzGroup(AuthzGroup azGroup)
Construct from another AuthzGroup object.

Parameters:
azGroup - The azGroup object to use for values.

BaseAuthzGroup

public BaseAuthzGroup(Integer dbid,
                      String id,
                      String providerId,
                      String maintainRole,
                      String createdBy,
                      Time createdOn,
                      String modifiedBy,
                      Time modifiedOn)
(Re)Construct from parts.

Parameters:
dbid - The database id.
id - The azGroup id.
providerId - The provider id.
maintainRole - The maintain role id.
createdBy - The user created by id.
createdOn - The time created.
modifiedBy - The user modified by id.
modifiedOn - The time modified.

BaseAuthzGroup

public BaseAuthzGroup(Element el)
Construct from information in XML.

Parameters:
el - The XML DOM Element definining the azGroup.
Method Detail

getDescription

public String getDescription()

Specified by:
getDescription in interface AuthzGroup
Returns:
a description of the item this realm applies to.

setAll

protected void setAll(AuthzGroup azGroup)
Take all values from this object.

Parameters:
azGroup - The AuthzGroup to take values from.

toXml

public Element toXml(Document doc,
                     Stack stack)
Serialize the entity into XML, adding an element to the doc under the top of the stack element.

Specified by:
toXml in interface Entity
Parameters:
doc - The DOM doc to contain the XML (or null for a string return).
stack - The DOM elements, the top of which is the containing element of the new "entity" element.
Returns:
The newly added element.

getId

public String getId()
Access the id of the entity.

Specified by:
getId in interface Entity
Returns:
The id.

getKey

public Integer getKey()
{@inheritDoc}


getUrl

public String getUrl()
Access the URL which can be used to access the entity.

Specified by:
getUrl in interface Entity
Returns:
The URL which can be used to access the entity.

getReference

public String getReference()
Access the internal reference which can be used to access the entity from within the system.

Specified by:
getReference in interface Entity
Returns:
The the internal reference which can be used to access the entity from within the system.

getReference

public String getReference(String rootProperty)
Description copied from interface: Entity
Access the alternate internal reference which can be used to access the entity from within the system.

Specified by:
getReference in interface Entity
Parameters:
rootProperty - The name of the entity property whose value controls which alternate reference is requested. If null, the native 'raw' reference is requested.
Returns:
The the alternate internal reference which can be used to access the entity from within the system.

getUrl

public String getUrl(String rootProperty)
Description copied from interface: Entity
Access the alternate URL which can be used to access the entity.

Specified by:
getUrl in interface Entity
Parameters:
rootProperty - The name of the entity property whose value controls which alternate reference URL is requested. If null, the native 'raw' URL is requested.
Returns:
The alternate URL which can be used to access the entity.

getProperties

public ResourceProperties getProperties()
Access the entity's properties.

Specified by:
getProperties in interface Entity
Returns:
The entity's properties.

getCreatedBy

public User getCreatedBy()

Specified by:
getCreatedBy in interface AuthzGroup
Returns:
the user who created this.

getModifiedBy

public User getModifiedBy()

Specified by:
getModifiedBy in interface AuthzGroup
Returns:
the user who last modified this.

getCreatedTime

public Time getCreatedTime()

Specified by:
getCreatedTime in interface AuthzGroup
Returns:
the time created.

getModifiedTime

public Time getModifiedTime()

Specified by:
getModifiedTime in interface AuthzGroup
Returns:
the time last modified.

isAllowed

public boolean isAllowed(String user,
                         String lock)
Test if this user is allowed to perform the function in this AuthzGroup.

Specified by:
isAllowed in interface AuthzGroup
Parameters:
user - The user id.
lock - The function to open.
Returns:
true if this user is allowed to perform the function in this AuthzGroup, false if not.

hasRole

public boolean hasRole(String user,
                       String role)
Test if this user has a membership in this AuthzGroup that has this role and is active.

Specified by:
hasRole in interface AuthzGroup
Parameters:
user - The user id.
role - The role name.
Returns:
true if the User has has a membership in this AuthzGroup that has this role and is active.

getUsers

public Set getUsers()
Access all users who have active role membership in the AuthzGroup.

Specified by:
getUsers in interface AuthzGroup
Returns:
The Set of users ids (String) who have active role membership in the AuthzGroup.

getMembers

public Set getMembers()
Access all Membership records defined for this AuthzGroup.

Specified by:
getMembers in interface AuthzGroup
Returns:
The set of Membership records (Membership) defined for this AuthzGroup.

getUsersIsAllowed

public Set getUsersIsAllowed(String lock)
Access all users who have an active role membership to a role that is allowed this function.

Specified by:
getUsersIsAllowed in interface AuthzGroup
Parameters:
lock - The function to check.
Returns:
The Set of user ids (String) who have an active role membership to a role that is allowed this function.

getUsersHasRole

public Set getUsersHasRole(String role)
Access all users who have an active role membership with this role.

Specified by:
getUsersHasRole in interface AuthzGroup
Returns:
The Set of user ids (String) who have an active role membership with this role.

getUserRole

public Role getUserRole(String user)
Access the active role for this user's membership.

Specified by:
getUserRole in interface AuthzGroup
Parameters:
user - The user id.
Returns:
The Role for this user's membership, or null if the user has no active membership.

getMember

public Member getMember(String user)
Access the user's membership record for this AuthzGroup; the role, and status flags.

Specified by:
getMember in interface AuthzGroup
Parameters:
user - The user id.
Returns:
The Membership record for the user in this AuthzGroup, or null if the use is not a member.

getRoles

public Set getRoles()
Access all Roles defined for this AuthzGroup.

Specified by:
getRoles in interface AuthzGroup
Returns:
The set of roles (Role) defined for this AuthzGroup.

getRolesIsAllowed

public Set getRolesIsAllowed(String function)
Description copied from interface: AuthzGroup
Access all roles that have been granted permission to this function.

Specified by:
getRolesIsAllowed in interface AuthzGroup
Parameters:
function - The function to check.
Returns:
The Set of role names (String) that have been granted permission to this function.

getRole

public Role getRole(String id)
Access a Role defined in this AuthzGroup.

Specified by:
getRole in interface AuthzGroup
Parameters:
id - The role id.
Returns:
The Role, if found, or null, if not.

getProviderGroupId

public String getProviderGroupId()
Access the group id for the GroupProvider for this AuthzGroup.

Specified by:
getProviderGroupId in interface AuthzGroup
Returns:
The the group id for the GroupProvider for this AuthzGroup, or null if none defined.

isEmpty

public boolean isEmpty()
Is this AuthzGroup empty of any roles or membership?

Specified by:
isEmpty in interface AuthzGroup
Returns:
true if the AuthzGroup is empty, false if not.

getMaintainRole

public String getMaintainRole()
Access the name of the role to use for giving a user membership with "maintain" access.

Specified by:
getMaintainRole in interface AuthzGroup
Returns:
The name of the "maintain" role.

equals

public boolean equals(Object obj)


hashCode

public int hashCode()


compareTo

public int compareTo(Object obj)

Specified by:
compareTo in interface Comparable

addMember

public void addMember(String user,
                      String roleId,
                      boolean active,
                      boolean provided)
Add a member to the AuthzGroup.

Specified by:
addMember in interface AuthzGroup
Parameters:
user - The user.
active - The active flag.
provided - If true, from an external provider.

removeMember

public void removeMember(String user)
Remove membership for for this user from the AuthzGroup.

Specified by:
removeMember in interface AuthzGroup
Parameters:
user - The user.

set

protected void set(AuthzGroup azGroup)
Take all values from this object.

Parameters:
azGroup - The AuthzGroup object to take values from.

removeMembers

public void removeMembers()
Remove all membership from this AuthzGroup.

Specified by:
removeMembers in interface AuthzGroup

addRole

public Role addRole(String id)
             throws IdUsedException
Create a new Role within this AuthzGroup.

Specified by:
addRole in interface AuthzGroup
Parameters:
id - The role id.
Returns:
the new Role.
Throws:
IdUsedException - if the id is already a Role in this AuthzGroup.

addRole

public Role addRole(String id,
                    Role other)
             throws IdUsedException
Create a new Role within this AuthzGroup, as a copy of this other role

Specified by:
addRole in interface AuthzGroup
Parameters:
id - The role id.
other - The role to copy.
Returns:
the new Role.
Throws:
IdUsedException - if the id is already a Role in this AuthzGroup.

removeRole

public void removeRole(String roleId)
Remove this Role from this AuthzGroup. Any grants of this Role in the AuthzGroup are also removed.

Specified by:
removeRole in interface AuthzGroup
Parameters:
roleId - The role name.

removeRoles

public void removeRoles()
Remove all Roles from this AuthzGroup.

Specified by:
removeRoles in interface AuthzGroup

setProviderGroupId

public void setProviderGroupId(String id)
Set the external group id for the GroupProvider for this AuthzGroup (set to null to have none).

Specified by:
setProviderGroupId in interface AuthzGroup
Parameters:
id - The external group id for the GroupProvider, or null if there is to be none.

setMaintainRole

public void setMaintainRole(String role)
Set the role name to use for "maintain" access.

Specified by:
setMaintainRole in interface AuthzGroup
Parameters:
role - The name of the "maintain" role.

getEvent

protected String getEvent()
Access the event code for this azGroup.

Returns:
The event code for this azGroup.

setEvent

protected void setEvent(String event)
Set the event code for this azGroup.

Parameters:
event - The event code for this azGroup.

getPropertiesEdit

public ResourcePropertiesEdit getPropertiesEdit()
Access the resource's properties for modification

Specified by:
getPropertiesEdit in interface Edit
Returns:
The resource's properties.

keepIntersection

public boolean keepIntersection(AuthzGroup other)
Adjust membership so that active members are all active in other, and inactive members are all defined in other

Specified by:
keepIntersection in interface AuthzGroup
Parameters:
other - The other azg to adjust to.
Returns:
true if any changes were made, false if not.

activate

protected void activate()
Enable editing.


isActiveEdit

public boolean isActiveEdit()
Check to see if the azGroup is still active, or has already been closed.

Specified by:
isActiveEdit in interface Edit
Returns:
true if the azGroup is active, false if it's been closed.

closeEdit

protected void closeEdit()
Close the azGroup object - it cannot be used after this.