com.atlassian.user.impl.cache
Class CachingGroupManager

java.lang.Object
  extended bycom.atlassian.user.impl.cache.CachingGroupManager
All Implemented Interfaces:
EntityManager, GroupManager

public class CachingGroupManager
extends java.lang.Object
implements GroupManager

Uses a generic caching strategy to provide caching for any implementation of GroupManager.

Typically used by putting the 'caching="true"' attribute on the repository in the XML configuration. The default repository loader will then wrap the GroupManager implementation in an instance of this class.

To minimise memory use, except for the direct name->object caches, the underlying caches do not store the actual group or user objects. Instead, they store just the user or group name and methods in this class retrieve the objects as required. The name->object caches will ensure that is relatively efficient.


Field Summary
protected  com.atlassian.cache.CacheFactory cacheFactory
           
protected  EntityRepositoryCache entityRepositoryCache
           
protected  GroupCache groupCache
           
protected  GroupsForUserCache groupsForUserCache
           
protected  MembershipCache membershipCache
           
protected  GroupManager underlyingGroupManager
           
 
Constructor Summary
CachingGroupManager(GroupManager underlyingGroupManager, com.atlassian.cache.CacheFactory cacheFactory)
           
 
Method Summary
 void addMembership(Group group, User user)
          Adds the user to the specified group.
 Group createGroup(java.lang.String groupName)
          Create a new group with the specified name.
 Pager getExternalMemberNames(Group group)
          Retrieves the names of those members of the specified group which are stored in another repository.
 Group getGroup(java.lang.String groupName)
          Retrieves the group with the given name.
 Pager getGroups()
          Retrieves all groups in this repository.
 Pager getGroups(User user)
          Caches the list of groups retrieved for a particular user.
 RepositoryIdentifier getIdentifier()
           
 Pager getLocalMemberNames(Group group)
          Retrieves the names of those members of the specified group which are also stored in this repository.
 Pager getMemberNames(Group group)
          Retrieves the names of all members of the specified group.
 RepositoryIdentifier getRepository(Entity entity)
           
 java.util.List getWritableGroups()
          Gets all editable groups.
 boolean hasMembership(Group group, User user)
          Returns true if the user is a member of the specified group.
 boolean isCreative()
          Used to detemine whether an entity can be created (eg, can call UserManager#createUser(String) or GroupManager.createGroup(String).
 boolean isReadOnly(Group group)
          Returns true if the specified group and membership of the specified group cannot be modified in the repository.
 void removeGroup(Group group)
          Remove the group specified, if it exists in this repository.
 void removeMembership(Group group, 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
 

Field Detail

underlyingGroupManager

protected final GroupManager underlyingGroupManager

cacheFactory

protected final com.atlassian.cache.CacheFactory cacheFactory

groupCache

protected GroupCache groupCache

membershipCache

protected MembershipCache membershipCache

groupsForUserCache

protected GroupsForUserCache groupsForUserCache

entityRepositoryCache

protected EntityRepositoryCache entityRepositoryCache
Constructor Detail

CachingGroupManager

public CachingGroupManager(GroupManager underlyingGroupManager,
                           com.atlassian.cache.CacheFactory cacheFactory)
Method Detail

getGroups

public Pager getGroups(User user)
                throws EntityException
Caches the list of groups retrieved for a particular user. This incurs a performance hit the first time a user's groups are retrieved, because we iterate over the entire pager and cache all groups to which the user belongs. The cached stores only group names to reduce memory usage. Since this method must return Group objects in the Pager, they are retrieved using getGroup(String). This should be relatively fast for subsequent lookups because this method also uses a cache.

Specified by:
getGroups in interface GroupManager
Parameters:
user - the user whose groups will be retrieved. Must not be null.
Returns:
a Pager containing all the groups in the underlying group manager which have this user as a member. Each item in the list is an instance of the Group type used by the underlying manager. Returns an empty pager if no such groups exist.
Throws:
EntityException - if there is an error retrieving the groups.

getWritableGroups

public java.util.List getWritableGroups()
Description copied from interface: GroupManager
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 GroupManager
Returns:
list of Groups that can be edited.

getGroup

public Group getGroup(java.lang.String groupName)
               throws EntityException
Description copied from interface: GroupManager
Retrieves the group with the given name. Returns null if the group does not exist in this repository.

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

createGroup

public Group createGroup(java.lang.String groupName)
                  throws EntityException
Description copied from interface: GroupManager
Create a new group with the specified name.

Specified by:
createGroup in interface GroupManager
Throws:
EntityException - if the Group could not be created.

removeGroup

public void removeGroup(Group group)
                 throws EntityException
Description copied from interface: GroupManager
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 GroupManager
Throws:
EntityException - if the Group could not be removed.

addMembership

public void addMembership(Group group,
                          User user)
                   throws EntityException
Description copied from interface: GroupManager
Adds the user to the specified group.

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

Specified by:
addMembership in interface GroupManager
Throws:
EntityException

hasMembership

public boolean hasMembership(Group group,
                             User user)
                      throws EntityException
Description copied from interface: GroupManager
Returns true if the user is a member of the specified group.

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

If the group is not handled by this manager, returns false.

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

removeMembership

public void removeMembership(Group group,
                             User user)
                      throws EntityException
Description copied from interface: GroupManager
Removes the user from the specified group.

Specified by:
removeMembership in interface GroupManager
Throws:
EntityException - if the membership could not be removed.

getRepository

public RepositoryIdentifier getRepository(Entity entity)
                                   throws EntityException
Specified by:
getRepository in interface EntityManager
Returns:
the RepositoryIdentifier of the repository in which the entity is stored, or null if the entity cannot be found.
Throws:
EntityException - if the entity cannot be found, or trying to retrieve it results in an error

getGroups

public Pager getGroups()
                throws EntityException
Description copied from interface: GroupManager
Retrieves all groups in this repository.

Specified by:
getGroups in interface 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:
EntityException

getMemberNames

public Pager getMemberNames(Group group)
                     throws EntityException
Description copied from interface: GroupManager
Retrieves the names of all members of the specified group. The names are ordered by a Collator for the JVM's default locale (as returned by Collator.getInstance().

Specified by:
getMemberNames in interface 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:
EntityException

getLocalMemberNames

public Pager getLocalMemberNames(Group group)
                          throws EntityException
Description copied from interface: GroupManager
Retrieves the names of those members of the specified group which are also stored in this repository. The names are ordered by a Collator for the JVM's default locale (as returned by Collator.getInstance().

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

Specified by:
getLocalMemberNames in interface GroupManager
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:
EntityException

getExternalMemberNames

public Pager getExternalMemberNames(Group group)
                             throws EntityException
Description copied from interface: GroupManager
Retrieves the names of those members of the specified group which are stored in another repository. For example, an LDAP user which is a member of a Hibernate group is an external member of the Hibernate group.

The names are ordered by a Collator for the JVM's default locale (as returned by Collator.getInstance().

If GroupManager.supportsExternalMembership() returns false, this method throws UnsupportedOperationException.

Specified by:
getExternalMemberNames in interface GroupManager
Returns:
a Pager containing a String with the name of each member of the group which is stored in a different repository. An empty pager will be returned if the group has no external members.
Throws:
EntityException

supportsExternalMembership

public boolean supportsExternalMembership()
                                   throws EntityException
Description copied from interface: GroupManager
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 GroupManager
Returns:
true if users from other repositories can be granted membership to groups in this repository, otherwise false.
Throws:
EntityException

isReadOnly

public boolean isReadOnly(Group group)
                   throws EntityException
Description copied from interface: GroupManager
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 GroupManager
Returns:
true if the group and membership of the group cannot be modified, otherwise false.
Throws:
EntityException

getIdentifier

public RepositoryIdentifier getIdentifier()
Specified by:
getIdentifier in interface EntityManager
Returns:
the RepositoryIdentifier for the repository which is managed by this instance.

isCreative

public boolean isCreative()
Description copied from interface: EntityManager
Used to detemine whether an entity can be created (eg, can call UserManager.createUser(String) or GroupManager.createGroup(String).

Specified by:
isCreative in interface EntityManager
Returns:
true to indicate that Entity objects can be created by this manager, or false to indicate not.


Copyright © 2005-2008 Atlassian Software Systems Pty Ltd. All Rights Reserved.