com.atlassian.jira.user.util
Class UserUtilImpl

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

public class UserUtilImpl
extends java.lang.Object
implements UserUtil, Startable

This is the default implementation of the UserUtil interface.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.jira.user.util.UserUtil
UserUtil.PasswordResetToken, UserUtil.PasswordResetTokenValidation
 
Field Summary
 
Fields inherited from interface com.atlassian.jira.user.util.UserUtil
META_PROPERTY_PREFIX
 
Constructor Summary
UserUtilImpl(ComponentLocator componentLocator, IssueSecurityLevelManager issueSecurityLevelManager, GlobalPermissionManager globalPermissionManager, UserManager userManager, PermissionManager permissionManager, ApplicationProperties applicationProperties, SearchProvider searchProvider, ProjectManager projectManager, ProjectRoleService projectRoleService, ProjectComponentManager componentManager, SubscriptionManager subscriptionManager, NotificationSchemeManager notificationSchemeManager, UserHistoryManager userHistoryManager, com.atlassian.event.api.EventPublisher eventPublisher)
           
 
Method Summary
 void addToJiraUsePermission(com.opensymphony.user.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(com.opensymphony.user.Group group, com.opensymphony.user.User userToAdd)
          This is used to add a specified user to a specified group.
 void addUserToGroups(java.util.Collection<com.opensymphony.user.Group> groups, com.opensymphony.user.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(java.util.Collection<java.lang.String> 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 changePassword(com.opensymphony.user.User user, java.lang.String newPassword)
          Can be called to set the password for a user.
 void clearActiveUserCount()
          Clears the cache of the active user count so that it can be recalculated.
 com.opensymphony.user.User createUserNoEvent(java.lang.String username, java.lang.String password, java.lang.String email, java.lang.String fullname)
          Given a valid validation result, this will create the user using the details provided in the validation result.
 com.opensymphony.user.User createUserWithEvent(java.lang.String username, java.lang.String password, java.lang.String email, java.lang.String fullname, int userEventType)
          Given a valid validation result, this will create the user using the details provided in the validation result.
protected  void dispatchEvent(com.opensymphony.user.User user, int userEventType, java.util.Map<?,?> args)
           
 UserUtil.PasswordResetToken generatePasswordResetToken(com.opensymphony.user.User user)
          This is used to generate a reset password token that last a certain time and allows a person to access a page anonymously so they can reset their password.
 int getActiveUserCount()
          Returns the number of users that are currently 'active'.
 java.util.Collection<com.opensymphony.user.User> getAdministrators()
          Returns a list of JIRA admin Users.
 java.util.Set<com.opensymphony.user.User> getAllUsers()
          Returns the all user-names defined in JIRA, regardless of whether they are active or not.
 java.util.Collection<ProjectComponent> getComponentsUserLeads(com.opensymphony.user.User user)
          Retrieve a collection of ProjectComponents - where the lead of each component is the specified user.
 java.lang.String getDisplayableNameSafely(com.opensymphony.user.User user)
          Takes the given user and returns a "displayable name" by cautiously checking the different edge cases for users.
 com.opensymphony.user.Group getGroup(java.lang.String groupName)
          Returns a Group based on user name.
 long getNumberOfAssignedIssuesIgnoreSecurity(com.opensymphony.user.User loggedInUser, com.opensymphony.user.User user)
          Returns number of issues assigned to user
 long getNumberOfReportedIssuesIgnoreSecurity(com.opensymphony.user.User loggedInUser, com.opensymphony.user.User user)
          Returns number of issues reported by user
protected  PortalPageService getPortalPageService()
          A Factory method to get the PortalPageService.
 java.util.Collection<org.ofbiz.core.entity.GenericValue> getProjectsUserLeads(com.opensymphony.user.User user)
          Returns all the projects that leadUser is the project lead for.
protected  SearchRequestService getSearchRequestService()
          A Factory method to get the SearchRequestService.
protected  JiraServiceContext getServiceContext(com.opensymphony.user.User user)
          Protected level factory method to allow for better test integration
 java.util.Collection<com.opensymphony.user.User> getSystemAdministrators()
          Returns a list of JIRA system admin Users.
 int getTotalUserCount()
          Returns the total number of users defined in JIRA, regardless of whether they are active or not.
 com.opensymphony.user.User getUser(java.lang.String userName)
          Returns a user based on user name.
 java.util.SortedSet<com.opensymphony.user.User> getUsersInGroupNames(java.util.Collection<java.lang.String> groupNames)
          Returns a collection of User objects that are found within the passed in collection of group names.
 java.util.SortedSet<com.opensymphony.user.User> getUsersInGroups(java.util.Collection<com.opensymphony.user.Group> groups)
          Returns a collection of User objects that are found within the passed in collection of Group objects.
 boolean hasExceededUserLimit()
          Returns true if this JIRA instance has more active users, than allowed by the license.
 boolean isNonSysAdminAttemptingToDeleteSysAdmin(com.opensymphony.user.User loggedInUser, com.opensymphony.user.User user)
          Checking if user without SYSTEM_ADMIN rights tries to remove user with SYSTEM_ADMIN rights.
 void onClearCache(ClearCacheEvent event)
           
 void removeUser(com.opensymphony.user.User loggedInUser, com.opensymphony.user.User user, I18nHelper i18nBean)
          Given a valid validation result, this will remove the user and removes the user from all the groups.
 void removeUserFromGroup(com.opensymphony.user.Group group, com.opensymphony.user.User userToRemove)
          This is used to remove a specified user from a specified group.
 void removeUserFromGroups(java.util.Collection<com.opensymphony.user.Group> groups, com.opensymphony.user.User userToRemove)
          This is used to remove a user from many groups at once.
 void start()
          This method wil be called after the plugin system is fully initialised and all components added to the dependency injection framework.
 boolean userExists(java.lang.String userName)
          Returns true if the a user exists with the specified userName
 UserUtil.PasswordResetTokenValidation validatePasswordResetToken(com.opensymphony.user.User user, java.lang.String token)
          This can be called to validate a token against the user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserUtilImpl

public UserUtilImpl(ComponentLocator componentLocator,
                    IssueSecurityLevelManager issueSecurityLevelManager,
                    GlobalPermissionManager globalPermissionManager,
                    UserManager userManager,
                    PermissionManager permissionManager,
                    ApplicationProperties applicationProperties,
                    SearchProvider searchProvider,
                    ProjectManager projectManager,
                    ProjectRoleService projectRoleService,
                    ProjectComponentManager componentManager,
                    SubscriptionManager subscriptionManager,
                    NotificationSchemeManager notificationSchemeManager,
                    UserHistoryManager userHistoryManager,
                    com.atlassian.event.api.EventPublisher eventPublisher)
Method Detail

start

public void start()
           throws java.lang.Exception
Description copied from interface: Startable
This method wil be called after the plugin system is fully initialised and all components added to the dependency injection framework.

Specified by:
start in interface Startable
Throws:
java.lang.Exception - Allows implementations to throw an Exception.

onClearCache

@EventListener
public void onClearCache(ClearCacheEvent event)

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(com.opensymphony.user.User user)
Protected level factory method to allow for better test integration

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

createUserNoEvent

public com.opensymphony.user.User createUserNoEvent(java.lang.String username,
                                                    java.lang.String password,
                                                    java.lang.String email,
                                                    java.lang.String fullname)
                                             throws com.opensymphony.user.ImmutableException,
                                                    com.opensymphony.user.DuplicateEntityException
Description copied from interface: UserUtil
Given a valid validation result, this will create the user using the details provided in the validation result. No email notification will be send to created user.

Specified by:
createUserNoEvent in interface UserUtil
Parameters:
username - The username of the new user. Needs to be lowercase and unique.
password - The password for the new user.
email - The email for the new user. Needs to be a valid email address.
fullname - The full name for the new user
Returns:
The new user object that was created
Throws:
com.opensymphony.user.ImmutableException - Generic exception ocurred when creating the user
com.opensymphony.user.DuplicateEntityException - User with this username alread exists

createUserWithEvent

public com.opensymphony.user.User createUserWithEvent(java.lang.String username,
                                                      java.lang.String password,
                                                      java.lang.String email,
                                                      java.lang.String fullname,
                                                      int userEventType)
                                               throws com.opensymphony.user.ImmutableException,
                                                      com.opensymphony.user.DuplicateEntityException
Description copied from interface: UserUtil
Given a valid validation result, this will create the user using the details provided in the validation result. Email notification will be send to created user.

Specified by:
createUserWithEvent in interface UserUtil
Parameters:
username - The username of the new user. Needs to be lowercase and unique.
password - The password for the new user.
email - The email for the new user. Needs to be a valid email address.
fullname - The full name for the new user
userEventType - The event type dispatched on user creation
Returns:
The new user object that was created
Throws:
com.opensymphony.user.ImmutableException - Generic exception ocurred when creating the user
com.opensymphony.user.DuplicateEntityException - User with this username alread exists

dispatchEvent

protected void dispatchEvent(com.opensymphony.user.User user,
                             int userEventType,
                             java.util.Map<?,?> args)

removeUser

public void removeUser(com.opensymphony.user.User loggedInUser,
                       com.opensymphony.user.User user,
                       I18nHelper i18nBean)
Description copied from interface: UserUtil
Given a valid validation result, this will remove the user and removes the user from all the groups. All components lead by user will have lead cleared.

Specified by:
removeUser in interface UserUtil
Parameters:
loggedInUser - username of the user performing operation
user - the user to delete
i18nBean - unused may as well be null

getNumberOfReportedIssuesIgnoreSecurity

public long getNumberOfReportedIssuesIgnoreSecurity(com.opensymphony.user.User loggedInUser,
                                                    com.opensymphony.user.User user)
                                             throws SearchException
Description copied from interface: UserUtil
Returns number of issues reported by user

Specified by:
getNumberOfReportedIssuesIgnoreSecurity in interface UserUtil
Parameters:
loggedInUser - the logged in user
user - the user to find the issue count for
Returns:
number of issues reported by user
Throws:
SearchException - if something goes wrong

getNumberOfAssignedIssuesIgnoreSecurity

public long getNumberOfAssignedIssuesIgnoreSecurity(com.opensymphony.user.User loggedInUser,
                                                    com.opensymphony.user.User user)
                                             throws SearchException
Description copied from interface: UserUtil
Returns number of issues assigned to user

Specified by:
getNumberOfAssignedIssuesIgnoreSecurity in interface UserUtil
Parameters:
loggedInUser - the logged in user
user - the user to find the issue count for
Returns:
number of issues assigned to user
Throws:
SearchException - if something goes wrong

getComponentsUserLeads

public java.util.Collection<ProjectComponent> getComponentsUserLeads(com.opensymphony.user.User user)
Description copied from interface: UserUtil
Retrieve a collection of ProjectComponents - where the lead of each component is the specified user.

Specified by:
getComponentsUserLeads in interface UserUtil
Parameters:
user - User leading components
Returns:
Collection of project components

getProjectsUserLeads

public java.util.Collection<org.ofbiz.core.entity.GenericValue> getProjectsUserLeads(com.opensymphony.user.User user)
Description copied from interface: UserUtil
Returns all the projects that leadUser is the project lead for.

Specified by:
getProjectsUserLeads in interface UserUtil
Parameters:
user - the user in play
Returns:
A collection of project GenericValues

isNonSysAdminAttemptingToDeleteSysAdmin

public boolean isNonSysAdminAttemptingToDeleteSysAdmin(com.opensymphony.user.User loggedInUser,
                                                       com.opensymphony.user.User user)
Description copied from interface: UserUtil
Checking if user without SYSTEM_ADMIN rights tries to remove user with SYSTEM_ADMIN rights.

Specified by:
isNonSysAdminAttemptingToDeleteSysAdmin in interface UserUtil
Parameters:
loggedInUser - User performing operation
user - User for remove
Returns:
true if user without SYSTEM_ADMIN rights tries to remove user with SYSTEM_ADMIN rights

addUserToGroup

public void addUserToGroup(com.opensymphony.user.Group group,
                           com.opensymphony.user.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(java.util.Collection<com.opensymphony.user.Group> groups,
                            com.opensymphony.user.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(com.opensymphony.user.Group group,
                                com.opensymphony.user.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(java.util.Collection<com.opensymphony.user.Group> groups,
                                 com.opensymphony.user.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.

generatePasswordResetToken

public UserUtil.PasswordResetToken generatePasswordResetToken(com.opensymphony.user.User user)
Description copied from interface: UserUtil
This is used to generate a reset password token that last a certain time and allows a person to access a page anonymously so they can reset their password.

The generated token will be associated with the named user so that that this information can be verified at a later time.

Specified by:
generatePasswordResetToken in interface UserUtil
Parameters:
user - the user in question. This MUST not be null
Returns:
a newly generated token that will live for a certain time

validatePasswordResetToken

public UserUtil.PasswordResetTokenValidation validatePasswordResetToken(com.opensymphony.user.User user,
                                                                        java.lang.String token)
Description copied from interface: UserUtil
This can be called to validate a token against the user.

Specified by:
validatePasswordResetToken in interface UserUtil
Parameters:
user - the user in play
token - the token they provided
Returns:
a Validation object that describes how the option went

changePassword

public void changePassword(com.opensymphony.user.User user,
                           java.lang.String newPassword)
                    throws com.opensymphony.user.ImmutableException
Description copied from interface: UserUtil
Can be called to set the password for a user. This will delete any password request tokens associated with that user

Specified by:
changePassword in interface UserUtil
Parameters:
user - the user in play
newPassword - their new password
Throws:
com.opensymphony.user.ImmutableException - because the underlying user provider does not allow password change

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(java.util.Collection<java.lang.String> 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.

getAllUsers

public java.util.Set<com.opensymphony.user.User> getAllUsers()
Description copied from interface: UserUtil
Returns the all user-names defined in JIRA, regardless of whether they are active or not.

Specified by:
getAllUsers in interface UserUtil
Returns:
the set of all user names defined in JIRA

getTotalUserCount

public int getTotalUserCount()
Description copied from interface: UserUtil
Returns the total number of users defined in JIRA, regardless of whether they are active or not.

Specified by:
getTotalUserCount in interface UserUtil
Returns:
the total number of users defined in JIRA

getUser

public com.opensymphony.user.User getUser(java.lang.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 including null userName.

userExists

public boolean userExists(java.lang.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 java.util.Collection<com.opensymphony.user.User> 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 java.util.Collection<com.opensymphony.user.User> 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.

addToJiraUsePermission

public void addToJiraUsePermission(com.opensymphony.user.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

getDisplayableNameSafely

public java.lang.String getDisplayableNameSafely(com.opensymphony.user.User user)
Description copied from interface: UserUtil
Takes the given user and returns a "displayable name" by cautiously checking the different edge cases for users.

Specified by:
getDisplayableNameSafely in interface UserUtil
Parameters:
user - the user. May be null.
Returns:
The user's full name if present and not blank, the username if present, or null otherwise.

getUsersInGroups

public java.util.SortedSet<com.opensymphony.user.User> getUsersInGroups(java.util.Collection<com.opensymphony.user.Group> groups)
Description copied from interface: UserUtil
Returns a collection of User objects that are found within the passed in collection of Group objects. Null users are excluded even if they exist in the underlying data.

Specified by:
getUsersInGroups in interface UserUtil
Parameters:
groups - a collection of Group objects
Returns:
the set of users that are in the groups, sorted in BestNameComparator order

getUsersInGroupNames

public java.util.SortedSet<com.opensymphony.user.User> getUsersInGroupNames(java.util.Collection<java.lang.String> groupNames)
Description copied from interface: UserUtil
Returns a collection of User objects that are found within the passed in collection of group names. Null users are excluded even if they exist in the underlying data.

Specified by:
getUsersInGroupNames in interface UserUtil
Parameters:
groupNames - a collection of group name strings
Returns:
the set of users that are in the named groups, sorted in BestNameComparator order

getGroup

public com.opensymphony.user.Group getGroup(java.lang.String groupName)
Description copied from interface: UserUtil
Returns a Group based on user name.

Specified by:
getGroup in interface UserUtil
Parameters:
groupName - the user name of the group
Returns:
the Group object, or null if the user cannot be found including null groupName.


Copyright © 2002-2010 Atlassian. All Rights Reserved.