com.atlassian.user.impl.hibernate
Class HibernateGroupManager

java.lang.Object
  extended byorg.springframework.dao.support.DaoSupport
      extended byorg.springframework.orm.hibernate.support.HibernateDaoSupport
          extended bycom.atlassian.user.impl.hibernate.HibernateGroupManager
All Implemented Interfaces:
EntityManager, GroupManager, org.springframework.beans.factory.InitializingBean

public class HibernateGroupManager
extends org.springframework.orm.hibernate.support.HibernateDaoSupport
implements GroupManager

A HibernateGroupManager which handles membership for local and external entities.


Field Summary
static java.lang.String ENTITYID_FIELD
           
static java.lang.String EXTERNAL_ENTITY_NAME_FIELD
           
protected  ExternalEntityDAO externalEntityDao
           
static java.lang.String GROUPID_FIELD
           
static java.lang.String GROUPNAME_FIELD
           
protected  HibernateRepository repository
           
protected  UserManager userManager
           
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
HibernateGroupManager(RepositoryIdentifier identifier, HibernateRepository repository, UserManager userManager, ExternalEntityDAO externalEntityDao)
           
 
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.
protected  java.util.Collection getAllGroupsForUser(User user)
           
protected  ExternalEntity getCorrespondingExternalEntity(User user)
           
 Pager getExternalMemberNames(Group group)
          Retrieves the names of those members of the specified group which are stored in another repository.
 Pager getExternalMembers(Group group)
           
 Group getGroup(Group group)
           
 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)
          Retrieves the groups to which the given user belongs.
protected  java.util.List getGroupsForExternalEntity(ExternalEntity externalEntity)
           
protected  java.util.List getGroupsForLocalUser(User 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 getLocalMembers(Group group)
           
 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.
protected  boolean hasExternalMembership(DefaultHibernateGroup defGroup, User user)
           
protected  boolean hasLocalMembership(DefaultHibernateGroup defGroup, DefaultHibernateUser defUser)
           
 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 added (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.
protected  boolean isUserExternal(User user)
          for the time being, lets define an internal user as a hibernate user.
 void removeGroup(Group group)
          Removes the specified group, if it is present.
 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.
protected  void validateGroup(Group group)
           
protected  void validateGroupAndUser(Group group, User user)
           
 
Methods inherited from class org.springframework.orm.hibernate.support.HibernateDaoSupport
checkDaoConfig, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUPNAME_FIELD

public static final java.lang.String GROUPNAME_FIELD
See Also:
Constant Field Values

GROUPID_FIELD

public static final java.lang.String GROUPID_FIELD
See Also:
Constant Field Values

ENTITYID_FIELD

public static final java.lang.String ENTITYID_FIELD
See Also:
Constant Field Values

EXTERNAL_ENTITY_NAME_FIELD

public static final java.lang.String EXTERNAL_ENTITY_NAME_FIELD
See Also:
Constant Field Values

repository

protected final HibernateRepository repository

userManager

protected final UserManager userManager

externalEntityDao

protected final ExternalEntityDAO externalEntityDao
Constructor Detail

HibernateGroupManager

public HibernateGroupManager(RepositoryIdentifier identifier,
                             HibernateRepository repository,
                             UserManager userManager,
                             ExternalEntityDAO externalEntityDao)
Method Detail

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

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.

getGroups

public Pager getGroups(User user)
                throws EntityException
Description copied from interface: GroupManager
Retrieves the groups to which the given user belongs. Only groups which are managed by this repository are included.

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

getAllGroupsForUser

protected java.util.Collection getAllGroupsForUser(User user)
                                            throws RepositoryException
Throws:
RepositoryException

isUserExternal

protected boolean isUserExternal(User user)
for the time being, lets define an internal user as a hibernate user. All other impl's of User are external users.


getGroupsForLocalUser

protected java.util.List getGroupsForLocalUser(User user)
                                        throws RepositoryException
Throws:
RepositoryException

getGroupsForExternalEntity

protected java.util.List getGroupsForExternalEntity(ExternalEntity externalEntity)
                                             throws RepositoryException
Throws:
RepositoryException

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 instance which can hold User and ExternalEntity objects.
Throws:
EntityException

validateGroup

protected void validateGroup(Group group)

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

getLocalMembers

public Pager getLocalMembers(Group group)
                      throws RepositoryException
Throws:
RepositoryException

getExternalMembers

public Pager getExternalMembers(Group group)
                         throws RepositoryException
Throws:
RepositoryException

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

getGroup

public Group getGroup(Group group)
               throws EntityException
Throws:
EntityException

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
Removes the specified group, if it is present.

Specified by:
removeGroup in interface GroupManager
Throws:
EntityException - - representing the exception which prohibited removal

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

getCorrespondingExternalEntity

protected ExternalEntity getCorrespondingExternalEntity(User user)
                                                 throws RepositoryException
Throws:
RepositoryException

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

validateGroupAndUser

protected void validateGroupAndUser(Group group,
                                    User user)
                             throws EntityException
Throws:
EntityException

hasExternalMembership

protected boolean hasExternalMembership(DefaultHibernateGroup defGroup,
                                        User user)
                                 throws EntityException
Throws:
EntityException

hasLocalMembership

protected boolean hasLocalMembership(DefaultHibernateGroup defGroup,
                                     DefaultHibernateUser defUser)
                              throws EntityException
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.

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

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

getIdentifier

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

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

isCreative

public boolean isCreative()
Used to detemine whether an entity can be added (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.