com.atlassian.crowd.integration.atlassianuser
Class CrowdGroupManager

java.lang.Object
  extended by com.atlassian.crowd.integration.atlassianuser.CrowdGroupManager
All Implemented Interfaces:
com.atlassian.user.EntityManager, com.atlassian.user.GroupManager

public class CrowdGroupManager
extends java.lang.Object
implements com.atlassian.user.GroupManager

Crowd implementation of the atlassian-user group manager.

A group manager is responsible for all CRUD operations on groups and group memberships in a given repository.

Where an operation requires a Group as an argument, calling the method with a group from another repository will typically throw an IllegalArgumentException.

The group manager is responsible for ensuring the consistency of the underlying repository where relevant. For example, if membership information needs to be updated as part of the removeGroup(Group) operation, the group manager is responsible for ensuring it happens.

This interface is an extension of the EntityManager interface which is common to user and group management. The common functionality includes initialisation and access to the repository description.


Constructor Summary
CrowdGroupManager(com.atlassian.user.repository.RepositoryIdentifier repositoryIdentifier)
          Configures to the Crowd client cache for better performance.
CrowdGroupManager(com.atlassian.user.repository.RepositoryIdentifier repositoryIdentifier, GroupManager groupManager, GroupMembershipManager groupMembershipManager)
           
 
Method Summary
 void addMembership(com.atlassian.user.Group group, com.atlassian.user.User user)
          Adds the user to the specified group.
protected  java.util.List convertStringsToGroups(java.util.List groupNames)
          Converts a List to a List.
 com.atlassian.user.Group createGroup(java.lang.String name)
          Create a new group with the specified name.
protected  java.util.List getAllGroups()
           
 com.atlassian.user.search.page.Pager getExternalMemberNames(com.atlassian.user.Group group)
          Sett getLocalMemberNames(com.atlassian.user.Group)}
 com.atlassian.user.Group getGroup(java.lang.String name)
          Retrieves the group with the given name.
protected  java.util.List getGroupMemberships(com.atlassian.user.User user)
          Retrieves the groups to which the given user belongs.
 com.atlassian.user.search.page.Pager getGroups()
          Retrieves all groups in this repository.
 com.atlassian.user.search.page.Pager getGroups(com.atlassian.user.User user)
          Retrieves the groups to which the given user belongs.
 com.atlassian.user.repository.RepositoryIdentifier getIdentifier()
          Returns information about the respository implementation.
 com.atlassian.user.search.page.Pager getLocalMemberNames(com.atlassian.user.Group group)
          Retrieves the names of those members of the specified group which are also stored in this repository.
 com.atlassian.user.search.page.Pager getMemberNames(com.atlassian.user.Group group)
          Retrieves the names of all members of the specified group.
 com.atlassian.user.repository.RepositoryIdentifier getRepository(com.atlassian.user.Entity entity)
          Returns information about the respository for a specific entity.
 java.util.List getWritableGroups()
          Gets all editable groups.
 boolean hasMembership(com.atlassian.user.Group group, com.atlassian.user.User user)
          Returns true if the user is a member of the specified group.
 boolean isCreative()
           
 boolean isReadOnly(com.atlassian.user.Group group)
          Returns true if the specified group and membership of the specified group cannot be modified in the repository.
 void removeGroup(com.atlassian.user.Group group)
          Remove the group specified, if it exists in this repository.
 void removeMembership(com.atlassian.user.Group group, com.atlassian.user.User user)
          Removes the user from the specified group.
 boolean supportsExternalMembership()
          Returns true if the repository supports users in other repositories being members of groups in this repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CrowdGroupManager

public CrowdGroupManager(com.atlassian.user.repository.RepositoryIdentifier repositoryIdentifier)
Configures to the Crowd client cache for better performance.

Parameters:
repositoryIdentifier - repository ID.

CrowdGroupManager

public CrowdGroupManager(com.atlassian.user.repository.RepositoryIdentifier repositoryIdentifier,
                         GroupManager groupManager,
                         GroupMembershipManager groupMembershipManager)
Method Detail

getAllGroups

protected java.util.List getAllGroups()
                               throws InvalidAuthorizationTokenException,
                                      java.rmi.RemoteException
Throws:
InvalidAuthorizationTokenException
java.rmi.RemoteException

convertStringsToGroups

protected java.util.List convertStringsToGroups(java.util.List groupNames)
Converts a List to a List. Returns an empty List if groupNames is null or empty. See the contract of GroupManager.getGroups().

Parameters:
groupNames -
Returns:

getGroups

public com.atlassian.user.search.page.Pager getGroups()
                                               throws com.atlassian.user.EntityException
Retrieves all groups in this repository.

Specified by:
getGroups in interface com.atlassian.user.GroupManager
Returns:
a Pager containing a Group for each group managed by the repository. An empty pager will be returned if the repository does not contain any groups.
Throws:
com.atlassian.user.EntityException

getWritableGroups

public java.util.List getWritableGroups()
Gets all editable groups. That is, returns any groups that belong to read/write repositories. Groups in readonly repositories that are ReadOnly are not returned.

Specified by:
getWritableGroups in interface com.atlassian.user.GroupManager
Returns:
list of Groups that can be edited.

getGroups

public com.atlassian.user.search.page.Pager getGroups(com.atlassian.user.User user)
                                               throws com.atlassian.user.EntityException
Retrieves the groups to which the given user belongs. Only groups which are managed by this repository are included.

Specified by:
getGroups in interface com.atlassian.user.GroupManager
Returns:
a Pager containing a Group for each group the user belongs to. An empty pager will be returned if the user does not belong to any groups that this manager knows about.
Throws:
com.atlassian.user.EntityException

getGroupMemberships

protected java.util.List getGroupMemberships(com.atlassian.user.User user)
                                      throws com.atlassian.user.EntityException
Retrieves the groups to which the given user belongs. Only groups which are managed by this repository are included.

Returns:
a List containing a Group for each group the user belongs to. An empty list will be returned if the user does not belong to any groups that this manager knows about.
Throws:
com.atlassian.user.EntityException

getMemberNames

public com.atlassian.user.search.page.Pager getMemberNames(com.atlassian.user.Group group)
                                                    throws com.atlassian.user.EntityException
Retrieves the names of all members of the specified group.

Specified by:
getMemberNames in interface com.atlassian.user.GroupManager
Returns:
a Pager containing a String with the name of each member of the group. An empty pager will be returned if the group has no members.
Throws:
com.atlassian.user.EntityException

getLocalMemberNames

public com.atlassian.user.search.page.Pager getLocalMemberNames(com.atlassian.user.Group group)
                                                         throws com.atlassian.user.EntityException
Retrieves the names of those members of the specified group which are also stored in this repository.

If supportsExternalMembership() returns false, this call is equivalent to getMemberNames(Group).

Specified by:
getLocalMemberNames in interface com.atlassian.user.GroupManager
Parameters:
group - The group to lookup.
Returns:
a Pager containing a String with the name of each member of the group which is stored in the same repository. An empty pager will be returned if the group has no local members.
Throws:
com.atlassian.user.EntityException

getExternalMemberNames

public com.atlassian.user.search.page.Pager getExternalMemberNames(com.atlassian.user.Group group)
                                                            throws com.atlassian.user.EntityException
Sett getLocalMemberNames(com.atlassian.user.Group)}

Specified by:
getExternalMemberNames in interface com.atlassian.user.GroupManager
Parameters:
group - The group to lookup.
Returns:
Search results.
Throws:
com.atlassian.user.EntityException - Search exception.

getGroup

public com.atlassian.user.Group getGroup(java.lang.String name)
                                  throws com.atlassian.user.EntityException
Retrieves the group with the given name. Returns null if the group does not exist in this repository.

Specified by:
getGroup in interface com.atlassian.user.GroupManager
Returns:
a Group or null if the group does not exist.
Throws:
com.atlassian.user.EntityException

createGroup

public com.atlassian.user.Group createGroup(java.lang.String name)
                                     throws com.atlassian.user.EntityException
Create a new group with the specified name.

Specified by:
createGroup in interface com.atlassian.user.GroupManager
Throws:
com.atlassian.user.EntityException - if the Group could not be created.
java.lang.UnsupportedOperationException - if isCreative() returns false

removeGroup

public void removeGroup(com.atlassian.user.Group group)
                 throws com.atlassian.user.EntityException
Remove the group specified, if it exists in this repository. If the group does not belong to this repository, an IllegalArgumentException will be thrown.

If required to maintain the consistency of the repository, the group manager should remove users from the group before removing the group itself.

Specified by:
removeGroup in interface com.atlassian.user.GroupManager
Throws:
com.atlassian.user.EntityException - if the Group could not be removed.
java.lang.UnsupportedOperationException - if isReadOnly(Group) returns true.

addMembership

public void addMembership(com.atlassian.user.Group group,
                          com.atlassian.user.User user)
                   throws com.atlassian.user.EntityException
Adds the user to the specified group.

If the user is not in this repository, and supportsExternalMembership() returns true, the user will be added as an external user.

Specified by:
addMembership in interface com.atlassian.user.GroupManager
Throws:
java.lang.UnsupportedOperationException - if isReadOnly(Group) returns true.
com.atlassian.user.EntityException

hasMembership

public boolean hasMembership(com.atlassian.user.Group group,
                             com.atlassian.user.User user)
                      throws com.atlassian.user.EntityException
Returns true if the user is a member of the specified group.

If the user is not in this repository, and supportsExternalMembership() returns true, external members will be checked as well.

Specified by:
hasMembership in interface com.atlassian.user.GroupManager
Returns:
true if the user is a member of the specified group, otherwise false.
Throws:
com.atlassian.user.EntityException

removeMembership

public void removeMembership(com.atlassian.user.Group group,
                             com.atlassian.user.User user)
                      throws com.atlassian.user.EntityException
Removes the user from the specified group.

Specified by:
removeMembership in interface com.atlassian.user.GroupManager
Throws:
com.atlassian.user.EntityException - if the membership could not be removed.
java.lang.UnsupportedOperationException - if GroupManager.isReadOnly(Group) returns true.

supportsExternalMembership

public boolean supportsExternalMembership()
                                   throws com.atlassian.user.EntityException
Returns true if the repository supports users in other repositories being members of groups in this repository.

Typically this is true of an application-specific Hibernate repository, but not of a company's LDAP server. It is designed to allow the LDAP users to be members of the application's groups for flexible application-level security.

Specified by:
supportsExternalMembership in interface com.atlassian.user.GroupManager
Returns:
true if users from other repositories can be granted membership to groups in this repository, otherwise false.
Throws:
com.atlassian.user.EntityException

isReadOnly

public boolean isReadOnly(com.atlassian.user.Group group)
                   throws com.atlassian.user.EntityException
Returns true if the specified group and membership of the specified group cannot be modified in the repository.

If this returns true, invoking methods which attempt to modify the group or membership of the group will fail with UnsupportedOperationException.

Specified by:
isReadOnly in interface com.atlassian.user.GroupManager
Returns:
true if the group and membership of the group cannot be modified, otherwise false.
Throws:
com.atlassian.user.EntityException

getIdentifier

public com.atlassian.user.repository.RepositoryIdentifier getIdentifier()
Returns information about the respository implementation.

Specified by:
getIdentifier in interface com.atlassian.user.EntityManager
Returns:
The repository configuration.

getRepository

public com.atlassian.user.repository.RepositoryIdentifier getRepository(com.atlassian.user.Entity entity)
                                                                 throws com.atlassian.user.EntityException
Returns information about the respository for a specific entity.

Specified by:
getRepository in interface com.atlassian.user.EntityManager
Parameters:
entity - The entity.
Returns:
The repository configuration.
Throws:
com.atlassian.user.EntityException

isCreative

public boolean isCreative()
Specified by:
isCreative in interface com.atlassian.user.EntityManager


Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.