public class

UserUtilImpl

extends Object
implements UserUtil
java.lang.Object
   ↳ com.atlassian.jira.user.util.UserUtilImpl

Class Overview

This is the default implementation of the UserUtil interface.

Summary

Constants
String DIRECTORY_ID
String DIRECTORY_NAME
String DISPLAY_NAME
String EMAIL
String PASSWORD_HOURS
String PASSWORD_TOKEN
String SEND_EMAIL
String USERNAME
[Expand]
Inherited Constants
From interface com.atlassian.jira.user.util.UserUtil
Public Constructors
UserUtilImpl(IssueSecurityLevelManager issueSecurityLevelManager, GlobalPermissionManager globalPermissionManager, CrowdService crowdService, PermissionManager permissionManager, ApplicationProperties applicationProperties, SearchProvider searchProvider, ProjectManager projectManager, ProjectRoleService projectRoleService, ProjectComponentManager componentManager, SubscriptionManager subscriptionManager, NotificationSchemeManager notificationSchemeManager, UserHistoryManager userHistoryManager, UserManager userManager, LicenseCountService licenseCountService, ApplicationRoleManager applicationRoleManager, JsonEntityPropertyManager jsonEntityPropertyManager)
Public Methods
void addToJiraUsePermission(ApplicationUser 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, ApplicationUser userToAdd)
This is used to add a specified user to a specified group.
void addUserToGroups(Collection<Group> groups, ApplicationUser 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.
void changePassword(ApplicationUser user, 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.
@Nonnull ApplicationUser createUser(UserDetails userData, boolean sendEmailNotification, int eventType, Set<ApplicationKey> applicationKeys)
This method is being removed - Please use UserService.
ApplicationUser createUserNoNotification(String username, String password, String emailAddress, String displayName)
Creates a User from supplied details.
ApplicationUser createUserNoNotification(String username, String password, String emailAddress, String displayName, Long directoryId)
Creates a User from supplied details.
ApplicationUser createUserWithNotification(String username, String password, String email, String fullname, Long directoryId, int userEventType)
Creates a User from supplied details.
ApplicationUser createUserWithNotification(String username, String password, String email, String fullname, int userEventType)
Creates a User from supplied details.
UserUtil.PasswordResetToken generatePasswordResetToken(ApplicationUser 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()
Gets the number of active users who currently count towards the license and should be charged for.
Collection<ApplicationUser> getAdministrators()
Returns a list of JIRA admin Users.
@Nonnull Collection<ApplicationUser> getAllApplicationUsers()
Returns the all users defined in JIRA, regardless of whether they are active or not.
SortedSet<ApplicationUser> getAllUsersInGroupNames(Collection<String> groupNames)
Returns a collection of User objects that belong to any of the passed in collection of group names.
Set<ApplicationUser> getAllUsersInGroupNamesUnsorted(Collection<String> groupNames)
Returns a collection of User objects that belong to any of the passed in collection of group names.
SortedSet<ApplicationUser> getAllUsersInGroups(Collection<Group> groups)
Returns a collection of User objects that are found within the passed in collection of Group objects.
Collection<ProjectComponent> getComponentsUserLeads(ApplicationUser user)
Retrieve a collection of ProjectComponents - where the lead of each component is the specified user.
String getDisplayableNameSafely(ApplicationUser user)
Takes the given user and returns a "displayable name" by cautiously checking the different edge cases for users.
Group getGroup(String groupName)
Get a Group by name.
SortedSet<String> getGroupNamesForUser(String userName)
Returns a collection of the names of the groups that the user belongs to.
Group getGroupObject(String groupName)
Returns a Group based on group name.
SortedSet<Group> getGroupsForUser(String userName)
Returns a collection of Group objects that the user belongs to.
Collection<ApplicationUser> getJiraAdministrators()
Returns a list of JIRA admin Users.
Collection<ApplicationUser> getJiraSystemAdministrators()
Returns a list of JIRA system admin Users.
long getNumberOfAssignedIssuesIgnoreSecurity(ApplicationUser loggedInUser, ApplicationUser user)
Returns number of issues assigned to user
long getNumberOfReportedIssuesIgnoreSecurity(ApplicationUser loggedInUser, ApplicationUser user)
Returns number of issues reported by user
Collection<Project> getProjectsLeadBy(ApplicationUser user)
Returns all the projects that leadUser is the project lead for.
Collection<ApplicationUser> 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.
ApplicationUser getUser(String userName)
Get a User by name.
ApplicationUser getUserByKey(String key)
Returns a user based on key.
ApplicationUser getUserByName(String username)
Returns a user based on user name.
ApplicationUser getUserObject(String userName)
Returns a user based on user name.
@Nonnull Collection<ApplicationUser> getUsers()
Returns the all users defined in JIRA, regardless of whether they are active or not.
SortedSet<ApplicationUser> getUsersInGroupNames(Collection<String> groupNames)
Returns a collection of User objects that are found within the passed in collection of group names.
SortedSet<ApplicationUser> getUsersInGroups(Collection<Group> groups)
Returns a collection of User objects that are found within the passed in collection of Group objects.
boolean isNonSysAdminAttemptingToDeleteSysAdmin(ApplicationUser loggedInUser, ApplicationUser user)
Checking if user without SYSTEM_ADMIN rights tries to remove user with SYSTEM_ADMIN rights.
void removeUser(ApplicationUser loggedInUser, ApplicationUser user)
This will remove the user and removes the user from all the groups.
void removeUserFromGroup(Group group, ApplicationUser userToRemove)
This is used to remove a specified user from a specified group.
void removeUserFromGroups(Collection<Group> groups, ApplicationUser 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
UserUtil.PasswordResetTokenValidation validatePasswordResetToken(ApplicationUser user, String token)
This can be called to validate a token against the user.
Protected Methods
PortalPageService getPortalPageService()
A Factory method to get the PortalPageService.
SearchRequestService getSearchRequestService()
A Factory method to get the SearchRequestService.
JiraServiceContext getServiceContext(ApplicationUser user)
Protected level factory method to allow for better test integration
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.user.util.UserUtil

Constants

public static final String DIRECTORY_ID

Constant Value: "directoryId"

public static final String DIRECTORY_NAME

Constant Value: "directoryName"

public static final String DISPLAY_NAME

Constant Value: "fullname"

public static final String EMAIL

Constant Value: "email"

public static final String PASSWORD_HOURS

Constant Value: "password.hours"

public static final String PASSWORD_TOKEN

Constant Value: "password.token"

public static final String SEND_EMAIL

Constant Value: "sendEmail"

public static final String USERNAME

Constant Value: "username"

Public Constructors

public UserUtilImpl (IssueSecurityLevelManager issueSecurityLevelManager, GlobalPermissionManager globalPermissionManager, CrowdService crowdService, PermissionManager permissionManager, ApplicationProperties applicationProperties, SearchProvider searchProvider, ProjectManager projectManager, ProjectRoleService projectRoleService, ProjectComponentManager componentManager, SubscriptionManager subscriptionManager, NotificationSchemeManager notificationSchemeManager, UserHistoryManager userHistoryManager, UserManager userManager, LicenseCountService licenseCountService, ApplicationRoleManager applicationRoleManager, JsonEntityPropertyManager jsonEntityPropertyManager)

Public Methods

public void addToJiraUsePermission (ApplicationUser user)

Takes the given user and adds him/her to all the groups that grant a user the global JIRA use permission. (see 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)

Parameters
user The user to be added to the USE permission

public void addUserToGroup (Group group, ApplicationUser userToAdd)

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.

Parameters
group the group to add the user to.
userToAdd the user to add to the group.

public void addUserToGroups (Collection<Group> groups, ApplicationUser userToAdd)

This is used to add a user to many groups at once.

Parameters
groups a list containing the groups to add the user to.
userToAdd the user to add to the group.

public 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. If the license does not require a user limit, this method will return true immediately.

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.

public void changePassword (ApplicationUser user, String newPassword)

Can be called to set the password for a user. This will delete any password request tokens associated with that user

Parameters
user the user in play
newPassword their new password

public void clearActiveUserCount ()

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.

@Nonnull public ApplicationUser createUser (UserDetails userData, boolean sendEmailNotification, int eventType, Set<ApplicationKey> applicationKeys)

This method is being removed - Please use UserService. Creates a JIRA user.

Parameters
userData user request containing user details.
sendEmailNotification should send email notification.
eventType notification event type (see to UserEventType).
applicationKeys applications that user should be granted access to, null if instance default applications should be used, empty Set when user does not require access to any applications.
Returns
  • The newly created user.

public ApplicationUser createUserNoNotification (String username, String password, String emailAddress, String displayName)

Creates a User from supplied details.

No email notification will be send to created user.

Parameters
username The username of the new user. Needs to be lowercase and unique.
password The password for the new user.
emailAddress The email for the new user. Needs to be a valid email address.
displayName The display name for the new user
Returns
  • The new user object that was created

public ApplicationUser createUserNoNotification (String username, String password, String emailAddress, String displayName, Long directoryId)

Creates a User from supplied details.

No email notification will be send to created user.

Parameters
username The username of the new user. Needs to be lowercase and unique.
password The password for the new user.
emailAddress The email for the new user. Needs to be a valid email address.
displayName The display name for the new user
directoryId The directory to create the user in. Null means "first writable directory".
Returns
  • The new user object that was created

public ApplicationUser createUserWithNotification (String username, String password, String email, String fullname, Long directoryId, int userEventType)

Creates a User from supplied details.

Email notification will be send to created user.

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
directoryId The directory to create the user in. Null means "first writable directory".
userEventType The event type dispatched on user creation. Either USER_CREATED or USER_SIGNUP
Returns
  • The new user object that was created

public ApplicationUser createUserWithNotification (String username, String password, String email, String fullname, int userEventType)

Creates a User from supplied details.

Email notification will be send to created user.

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. Either USER_CREATED or USER_SIGNUP
Returns
  • The new user object that was created

public UserUtil.PasswordResetToken generatePasswordResetToken (ApplicationUser 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.

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

Parameters
user the user in question. This MUST not be null
Returns
  • a newly generated token that will live for a certain time

public int getActiveUserCount ()

Gets the number of active users who currently count towards the license and should be charged for. This method should be used when determining user counts for billing purposes, such as purchase tier recommendations for plugins, and by plugins who wish to enforce tier-based licenses.

In all cases this method will exclude Connect users from the count. In Cloud this will also exclude users who exist for the purpose of providing support (such as the Atlassian sysadmin user).

Returns
  • the active user count

public Collection<ApplicationUser> getAdministrators ()

Returns a list of JIRA admin Users.

WARNING: This method will be changed in the future to return a Collection of Crowd User objects. Since v4.3.

Returns
  • a list of JIRA admin Users.

@Nonnull public Collection<ApplicationUser> getAllApplicationUsers ()

Returns the all users defined in JIRA, regardless of whether they are active or not.

Returns
  • the set of all users defined in JIRA

public SortedSet<ApplicationUser> getAllUsersInGroupNames (Collection<String> groupNames)

Returns a collection of User objects that belong to any of the passed in collection of group names. Prefer using getAllUsersInGroupNamesUnsorted(java.util.Collection) and sorting the list of users only if absolutely necessary rather than relying on this method to perform the sort.

Parameters
groupNames a collection of group name strings
Returns

public Set<ApplicationUser> getAllUsersInGroupNamesUnsorted (Collection<String> groupNames)

Returns a collection of User objects that belong to any of the passed in collection of group names.

Parameters
groupNames a collection of group name strings
Returns
  • the set of users that are in the named groups

public SortedSet<ApplicationUser> getAllUsersInGroups (Collection<Group> groups)

Returns a collection of User objects that are found within the passed in collection of Group objects.

Parameters
groups a collection of Group objects
Returns

public Collection<ProjectComponent> getComponentsUserLeads (ApplicationUser user)

Retrieve a collection of ProjectComponents - where the lead of each component is the specified user.

Parameters
user User leading components
Returns
  • Collection of project components

public String getDisplayableNameSafely (ApplicationUser user)

Takes the given user and returns a "displayable name" by cautiously checking the different edge cases for users.

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.

public Group getGroup (String groupName)

Get a Group by name.

Parameters
groupName the name of the group
Returns
  • a Group

public SortedSet<String> getGroupNamesForUser (String userName)

Returns a collection of the names of the groups that the user belongs to.

Parameters
userName A User name
Returns
  • the set of groups that the user belongs to

public Group getGroupObject (String groupName)

Returns a Group based on group name.

Parameters
groupName the user name of the group
Returns
  • the Group object, or null if the user cannot be found including null groupName.

public SortedSet<Group> getGroupsForUser (String userName)

Returns a collection of Group objects that the user belongs to.

Parameters
userName A User name
Returns
  • the set of groups that the user belongs to

public Collection<ApplicationUser> getJiraAdministrators ()

Returns a list of JIRA admin Users.

WARNING: This method will be changed in the future to return a Collection of Crowd User objects. Since v4.3.

Returns
  • a list of JIRA admin Users.

public Collection<ApplicationUser> getJiraSystemAdministrators ()

Returns a list of JIRA system admin Users.

WARNING: This method will be changed in the future to return a Collection of Crowd User objects. Since v4.3.

Returns

public long getNumberOfAssignedIssuesIgnoreSecurity (ApplicationUser loggedInUser, ApplicationUser user)

Returns number of issues assigned to user

Parameters
loggedInUser the logged in user
user the user to find the issue count for
Returns
  • number of issues assigned to user

public long getNumberOfReportedIssuesIgnoreSecurity (ApplicationUser loggedInUser, ApplicationUser user)

Returns number of issues reported by user

Parameters
loggedInUser the logged in user
user the user to find the issue count for
Returns
  • number of issues reported by user

public Collection<Project> getProjectsLeadBy (ApplicationUser user)

Returns all the projects that leadUser is the project lead for.

Parameters
user the user in play
Returns
  • A collection of project org.ofbiz.core.entity.GenericValues

public Collection<ApplicationUser> getSystemAdministrators ()

Returns a list of JIRA system admin Users.

WARNING: This method will be changed in the future to return a Collection of Crowd User objects. Since v4.3.

Returns

public int getTotalUserCount ()

Returns the total number of users defined in JIRA, regardless of whether they are active or not.

Returns
  • the total number of users defined in JIRA

public ApplicationUser getUser (String userName)

Get a User by name.

Parameters
userName the name of the user
Returns
  • a User

public ApplicationUser getUserByKey (String key)

Returns a user based on key.

Parameters
key the key of the user
Returns
  • the User object, or null if the user cannot be found including null userkey.

public ApplicationUser getUserByName (String username)

Returns a user based on user name.

Parameters
username the user name of the user
Returns
  • the User object, or null if the user cannot be found including null userName.

public ApplicationUser getUserObject (String userName)

Returns a user based on user name.

Parameters
userName the user name of the user
Returns
  • the User object, or null if the user cannot be found including null userName.

@Nonnull public Collection<ApplicationUser> getUsers ()

Returns the all users defined in JIRA, regardless of whether they are active or not.

Returns
  • the set of all users defined in JIRA

public SortedSet<ApplicationUser> getUsersInGroupNames (Collection<String> groupNames)

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.

Parameters
groupNames a collection of group name strings
Returns
  • the set of users that are in the named groups.

public SortedSet<ApplicationUser> getUsersInGroups (Collection<Group> groups)

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.

Parameters
groups a collection of Group objects
Returns

public boolean isNonSysAdminAttemptingToDeleteSysAdmin (ApplicationUser loggedInUser, ApplicationUser user)

Checking if user without SYSTEM_ADMIN rights tries to remove user with SYSTEM_ADMIN rights.

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

public void removeUser (ApplicationUser loggedInUser, ApplicationUser user)

This will remove the user and removes the user from all the groups. All components lead by user will have lead cleared.

Parameters
loggedInUser the user performing operation
user the user to delete

public void removeUserFromGroup (Group group, ApplicationUser userToRemove)

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.

Parameters
group the group to add the user to.
userToRemove the user to add to the group.

public void removeUserFromGroups (Collection<Group> groups, ApplicationUser userToRemove)

This is used to remove a user from many groups at once.

Parameters
groups a list containing the groups to add the user to.
userToRemove the user to add to the group.

public boolean userExists (String userName)

Returns true if the a user exists with the specified userName

Parameters
userName the name of the user
Returns
  • true if t a user exists with the specified name or false if not

public UserUtil.PasswordResetTokenValidation validatePasswordResetToken (ApplicationUser user, String token)

This can be called to validate a token against the user.

Parameters
user the user in play
token the token they provided
Returns
  • a Validation object that describes how the option went

Protected Methods

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

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

protected JiraServiceContext getServiceContext (ApplicationUser user)

Protected level factory method to allow for better test integration

Parameters
user the user in action
Returns
  • a new JiraServiceContext