com.atlassian.jira.user.util
Class UserUtilImpl

java.lang.Object
  extended by com.atlassian.jira.user.util.UserUtilImpl
All Implemented Interfaces:
UserUtil

public class UserUtilImpl
extends Object
implements UserUtil

This is the default implementation of the UserUtil interface.


Field Summary
 
Fields inherited from interface com.atlassian.jira.user.util.UserUtil
META_PROPERTY_PREFIX
 
Constructor Summary
UserUtilImpl(IssueSecurityLevelManager issueSecurityLevelManager, GlobalPermissionManager globalPermissionManager, UserManager userManager)
           
 
Method Summary
 void addToJiraUsePermission(User user)
          Takes the given user and adds him/her to all the groups that grant a user the global JIRA use permission.
 void addUserToGroup(Group group, User userToAdd)
          This is used to add a specified user to a specified group.
 void addUserToGroups(Collection groups, User userToAdd)
          This is used to add a user to many groups at once.
 boolean canActivateNumberOfUsers(int numUsers)
          Returns true if, after adding the specified number of users, the number of active users in JIRA does not exceed the user limit allowed by the license.
 boolean canActivateUsers(Collection userNames)
          Returns true if, after adding the specified users, the number of active users in JIRA does not exceed the user limit allowed by the license.
 void clearActiveUserCount()
          Clears the cache of the active user count so that it can be recalculated.
 User createJiraUser(String username, String password, String email, String fullname)
          Create a JIRA user.
 User createJiraUserPreserveCase(String username, String password, String email, String fullname)
          Create a JIRA user.
 int getActiveUserCount()
          Returns the number of users that are currently 'active'.
 Collection getAdministrators()
          Returns a list of JIRA admin Users.
protected  PortalPageService getPortalPageService()
          A Factory method to get the PortalPageService.
protected  SearchRequestService getSearchRequestService()
          A Factory method to get the SearchRequestService.
protected  JiraServiceContext getServiceContext(User user)
          Protected level factory method to allow for better test integration
 Collection getSystemAdministrators()
          Returns a list of JIRA system admin Users.
 User getUser(String userName)
          Returns a user based on user name.
 boolean hasExceededUserLimit()
          Returns true if this JIRA instance has more active users, than allowed by the license.
 void removeUser(User user)
          Deletes the user and removes the user from all the groups.
 void removeUserFromGroup(Group group, User userToRemove)
          This is used to remove a specified user from a specified group.
 void removeUserFromGroups(Collection groups, User userToRemove)
          This is used to remove a user from many groups at once.
 boolean userExists(String userName)
          Returns true if the a user exists with the specified userName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserUtilImpl

public UserUtilImpl(IssueSecurityLevelManager issueSecurityLevelManager,
                    GlobalPermissionManager globalPermissionManager,
                    UserManager userManager)
Method Detail

getSearchRequestService

protected SearchRequestService getSearchRequestService()
A Factory method to get the SearchRequestService. This helps break the cyclic dependency of SearchRequestService to UserUtils AND allows test to override the value used.

Returns:
a SearchRequestService

getPortalPageService

protected PortalPageService getPortalPageService()
A Factory method to get the PortalPageService. This helps break the cyclic dependency of PortalPageService to UserUtils AND allows test to override the value used.

Returns:
a PortalPageService

getServiceContext

protected JiraServiceContext getServiceContext(User user)
Protected level factory method to allow for better test integration

Parameters:
user - the user in action
Returns:
a new JiraServiceContext

addUserToGroup

public void addUserToGroup(Group group,
                           User userToAdd)
Description copied from interface: UserUtil
This is used to add a specified user to a specified group. The user will be added to the group if the user is not already a member of the group.

Specified by:
addUserToGroup in interface UserUtil
Parameters:
group - the group to add the user to.
userToAdd - the user to add to the group.

addUserToGroups

public void addUserToGroups(Collection groups,
                            User userToAdd)
Description copied from interface: UserUtil
This is used to add a user to many groups at once.

Specified by:
addUserToGroups in interface UserUtil
Parameters:
groups - a list containing the groups to add the user to.
userToAdd - the user to add to the group.

removeUserFromGroup

public void removeUserFromGroup(Group group,
                                User userToRemove)
Description copied from interface: UserUtil
This is used to remove a specified user from a specified group. The user will be removed from the group only if the user is already a member of the group.

Specified by:
removeUserFromGroup in interface UserUtil
Parameters:
group - the group to add the user to.
userToRemove - the user to add to the group.

removeUserFromGroups

public void removeUserFromGroups(Collection groups,
                                 User userToRemove)
Description copied from interface: UserUtil
This is used to remove a user from many groups at once.

Specified by:
removeUserFromGroups in interface UserUtil
Parameters:
groups - a list containing the groups to add the user to.
userToRemove - the user to add to the group.

getActiveUserCount

public int getActiveUserCount()
Description copied from interface: UserUtil
Returns the number of users that are currently 'active'. For a user to be active, means that it must belong to a group that has either the JIRA-users, JIRA-administrators or JIRA-Systemadministartors global permission. Implementations of this method should take performance into consideration, and ensure that the value is cached. Use UserUtil.clearActiveUserCount() to clear the cache.

Please note that the calculation will be run if the license does not specify a user limit.

Specified by:
getActiveUserCount in interface UserUtil
Returns:
the active user count
See Also:
Permissions

clearActiveUserCount

public void clearActiveUserCount()
Description copied from interface: UserUtil
Clears the cache of the active user count so that it can be recalculated. This method should be used when performing operations that will modify the number of active users in the system.

Specified by:
clearActiveUserCount in interface UserUtil

hasExceededUserLimit

public boolean hasExceededUserLimit()
Description copied from interface: UserUtil
Returns true if this JIRA instance has more active users, than allowed by the license. If the license does not require a user limit, this method will return false immediately.

Specified by:
hasExceededUserLimit in interface UserUtil
Returns:
True if the number of active users is greater than the limit enforced by the license. False otherwise.

canActivateNumberOfUsers

public boolean canActivateNumberOfUsers(int numUsers)
Description copied from interface: UserUtil
Returns true if, after adding the specified number of users, the number of active users in JIRA does not exceed the user limit allowed by the license. If the license does not require a user limit, this method will return true immediately.

Specified by:
canActivateNumberOfUsers in interface UserUtil
Parameters:
numUsers - the number of users to add to the JIRA instance. If 0, all things being equal, this method will return true. Must not be negative!
Returns:
False if the number of active users + the number of users to add is greater than the limit enforced by the license. True otherwise.

canActivateUsers

public boolean canActivateUsers(Collection userNames)
Description copied from interface: UserUtil
Returns true if, after adding the specified users, the number of active users in JIRA does not exceed the user limit allowed by the license. If a user specified is already active, or cannot be found, they are not counted towards the user limit. If the limit has already been exceeded, but none of the users specified are inactive, the result will still be true, as these users are already active and thus nothing changes. If the license does not require a user limit, this method will return true immediately.

Specified by:
canActivateUsers in interface UserUtil
Parameters:
userNames - the names of the users to add to the JIRA instance. Must not be null!
Returns:
False if the number of active users + the number of users to add is greater than the limit enforced by the license. True otherwise.

getUser

public User getUser(String userName)
Description copied from interface: UserUtil
Returns a user based on user name.

Specified by:
getUser in interface UserUtil
Parameters:
userName - the user name of the user
Returns:
the User object, or null if the user cannot be found

userExists

public boolean userExists(String userName)
Description copied from interface: UserUtil
Returns true if the a user exists with the specified userName

Specified by:
userExists in interface UserUtil
Parameters:
userName - the name of the user
Returns:
true if t a user exists with the specified name or false if not

getAdministrators

public Collection getAdministrators()
Description copied from interface: UserUtil
Returns a list of JIRA admin Users.

Specified by:
getAdministrators in interface UserUtil
Returns:
a list of JIRA admin Users.

getSystemAdministrators

public Collection getSystemAdministrators()
Description copied from interface: UserUtil
Returns a list of JIRA system admin Users.

Specified by:
getSystemAdministrators in interface UserUtil
Returns:
a collection of Group's that are associated with the Permissions.SYSTEM_ADMIN permission.

createJiraUser

public User createJiraUser(String username,
                           String password,
                           String email,
                           String fullname)
                    throws DuplicateEntityException,
                           ImmutableException
Description copied from interface: UserUtil
Create a JIRA user. This user will be added to all groups with the USE permission.

Note that the username will be converted to lower case.

If password is specified as null, a new password will be generated for the user.

NOTE: This method does not fire any user events, you will need to fire them yourself if you want to.

Specified by:
createJiraUser in interface UserUtil
Parameters:
username - the user name for the user
password - the password. This may be null to generate a new password
email - the email address of the user
fullname - the user's full name
Returns:
the user object created
Throws:
DuplicateEntityException - If the user already exists
ImmutableException - If osuser has been misconfigured
See Also:
UserUtil.createJiraUserPreserveCase(String, String, String, String)

createJiraUserPreserveCase

public User createJiraUserPreserveCase(String username,
                                       String password,
                                       String email,
                                       String fullname)
                                throws DuplicateEntityException,
                                       ImmutableException
Description copied from interface: UserUtil
Create a JIRA user. This user will be added to all groups with the USE permission.

Any upper case in the username is preserved.

If password is specified as null, a new password will be generated for the user.

NOTE: This method does not fire any user events, you will need to fire them yourself if you want to.

Specified by:
createJiraUserPreserveCase in interface UserUtil
Parameters:
username - the user name for the user
password - the password. This may be null to generate a new password
email - the email address of the user
fullname - the user's full name
Returns:
the user object created
Throws:
DuplicateEntityException - If the user already exists
ImmutableException - If osuser has been misconfigured
See Also:
UserUtil.createJiraUser(String, String, String, String)

removeUser

public void removeUser(User user)
Description copied from interface: UserUtil
Deletes the user and removes the user from all the groups.

Specified by:
removeUser in interface UserUtil
Parameters:
user - the user to delete

addToJiraUsePermission

public void addToJiraUsePermission(User user)
Description copied from interface: UserUtil
Takes the given user and adds him/her to all the groups that grant a user the global JIRA use permission. (see Permissions.USE) Note: operation is only performed if by doing so we will not exceed the user limit (if the current license happens to specify a limit)

Specified by:
addToJiraUsePermission in interface UserUtil
Parameters:
user - The user to be added to the USE permission


Copyright © 2002-2008 Atlassian. All Rights Reserved.