@PublicApi public interface

UserUtil

com.atlassian.jira.user.util.UserUtil
Known Indirect Subclasses

@PublicApi

This interface is designed for plugins to consume (call its methods).

Clients of @PublicApi can expect that programs compiled against a given version will remain binary compatible with later versions of the @PublicApi as per each product's API policy as long as the client does not implement/extend @PublicApi interfaces or classes (refer to each product's API policy for the exact guarantee---usually binary compatibility is guaranteed at least across minor versions).

Note: since @PublicApi interfaces and classes are not designed to be implemented or extended by clients, we may perform certain types of binary-incompatible changes to these classes and interfaces, but these will not affect well-behaved clients that do not extend/implement these types (in general, only classes and interfaces annotated with @PublicSpi are safe to extend/implement).

Class Overview

This is a back end service level interface that defines an API for user level operations.

In general, appropriate managers or services should be used in preference to this class, as it will be removed in some future revision of JIRA.

Summary

Nested Classes
interface UserUtil.PasswordResetToken  
interface UserUtil.PasswordResetTokenValidation  
Constants
String META_PROPERTY_PREFIX
Public Methods
@Deprecated void addToJiraUsePermission(ApplicationUser user)
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.
@Deprecated boolean canActivateNumberOfUsers(int numUsers)
This method is deprecated. Use hasSeatsAvailable(ApplicationKey, int) instead. Since v7.0
void changePassword(ApplicationUser user, String newPassword)
Can be called to set the password for a user.
@Deprecated void clearActiveUserCount()
This method is deprecated. since 6.5. Use flush() instead.
@Nonnull @Internal @ExperimentalApi @Deprecated ApplicationUser createUser(UserDetails userData, boolean sendEmail, int eventType, Set<ApplicationKey> applicationKeys)
This method is deprecated. Use createUser(CreateUserValidationResult) instead. Since v7.0.
@Deprecated @Nonnull ApplicationUser createUserNoNotification(String username, String password, String emailAddress, String displayName)
This method is deprecated. Use createUser(CreateUserValidationResult) instead. Since v7.0.
@Deprecated @Nonnull ApplicationUser createUserNoNotification(String username, String password, String emailAddress, String displayName, Long directoryId)
This method is deprecated. Use createUser(CreateUserValidationResult) instead. Since v7.0.
@Deprecated @Nonnull ApplicationUser createUserWithNotification(String username, String password, String email, String fullname, Long directoryId, int userEventType)
This method is deprecated. Use createUser(CreateUserValidationResult) instead. Since v7.0.
@Deprecated @Nonnull ApplicationUser createUserWithNotification(String username, String password, String email, String fullname, int userEventType)
This method is deprecated. Use createUser(CreateUserValidationResult) instead. Since v7.0.
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.
@Deprecated int getActiveUserCount()
This method is deprecated. use totalBillableUsers(). since 6.5
@Deprecated Collection<ApplicationUser> getAdministrators()
This method is deprecated. Since v4.3. Use getJiraAdministrators().
@Deprecated @Nonnull Collection<ApplicationUser> getAllApplicationUsers()
This method is deprecated. Use getAllApplicationUsers() instead. Since v6.5.
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.
@Deprecated @Nullable Group getGroup(String groupName)
This method is deprecated. Since v4.3. Use getGroup(java.lang.String) instead.
SortedSet<String> getGroupNamesForUser(String userName)
Returns a collection of the names of the groups that the user belongs to.
@Deprecated @Nullable Group getGroupObject(String groupName)
This method is deprecated. since 6.5. Use getGroup(java.lang.String) instead.
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.
@Deprecated Collection<ApplicationUser> getSystemAdministrators()
This method is deprecated. Since v4.3. Use getJiraSystemAdministrators() .
@Deprecated int getTotalUserCount()
This method is deprecated. Use getTotalUserCount() instead. Since 7.0.
@Deprecated @Nullable ApplicationUser getUser(String userName)
This method is deprecated. Use getUserByKey(String) or getUserByName(String) instead. Since v6.0.
@Deprecated @Nullable ApplicationUser getUserByKey(String userkey)
This method is deprecated. use getUserByKey(String). since 7.0
@Deprecated @Nullable ApplicationUser getUserByName(String username)
This method is deprecated. use getUserByName(String). since 7.0
@Deprecated @Nullable ApplicationUser getUserObject(String userName)
This method is deprecated. Use getUserByKey(String) or getUserByName(String) instead. Since v6.0.
@Deprecated @Nonnull Collection<ApplicationUser> getUsers()
This method is deprecated. Use getAllApplicationUsers() instead. Since v6.5.
@Deprecated SortedSet<ApplicationUser> getUsersInGroupNames(Collection<String> groupNames)
This method is deprecated. Use getAllUsersInGroupNames(java.util.Collection) instead. Since v4.3
@Deprecated SortedSet<ApplicationUser> getUsersInGroups(Collection<Group> groups)
This method is deprecated. Use getAllUsersInGroups(java.util.Collection) instead. Since v4.3
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.

Constants

public static final String META_PROPERTY_PREFIX

Constant Value: "jira.meta."

Public Methods

@Deprecated public void addToJiraUsePermission (ApplicationUser user)

This method is deprecated.
Use validateAddUserToApplication(ApplicationUser, ApplicationKey) then addUserToApplication(AddUserToApplicationValidationResult) instead. Since v7.0.

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.

@Deprecated public boolean canActivateNumberOfUsers (int numUsers)

This method is deprecated.
Use hasSeatsAvailable(ApplicationKey, int) instead. Since v7.0

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
Throws
UserNotFoundException if the user does not exist
InvalidCredentialException if the password is invalid
OperationNotPermittedException if the underlying User Directory is read-only
PermissionException

@Deprecated public void clearActiveUserCount ()

This method is deprecated.
since 6.5. Use flush() instead.

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 @Internal @ExperimentalApi @Deprecated public ApplicationUser createUser (UserDetails userData, boolean sendEmail, int eventType, Set<ApplicationKey> applicationKeys)

@Internal

This method is an internal implementation detail and will change without notice.

Clients that depend on @Internal classes and interfaces can not expect to be compatible with any version other than the version they were compiled against (even minor version and milestone releases may break binary compatibility with respect to @Internal elements).

@ExperimentalApi

This method is considered usable by external developers but its contracts have not stabilized.

Experimental APIs may be changed at any time before being marked @Internal or @PublicApi.

This method is deprecated.
Use createUser(CreateUserValidationResult) instead. Since v7.0.

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

Parameters
userData user request containing user details.
sendEmail 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.
Throws
PermissionException If the operation was not permitted.
CreateException Unable to create user.

@Deprecated @Nonnull public ApplicationUser createUserNoNotification (String username, String password, String emailAddress, String displayName)

This method is deprecated.
Use createUser(CreateUserValidationResult) instead. Since v7.0.

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
Throws
PermissionException If the operation was not permitted.
CreateException

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

This method is deprecated.
Use createUser(CreateUserValidationResult) instead. Since v7.0.

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
Throws
PermissionException If the operation was not permitted.
CreateException

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

This method is deprecated.
Use createUser(CreateUserValidationResult) instead. Since v7.0.

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
Throws
PermissionException If the operation was not permitted.
CreateException

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

This method is deprecated.
Use createUser(CreateUserValidationResult) instead. Since v7.0.

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
Throws
PermissionException If the operation was not permitted.
CreateException

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

@Deprecated public int getActiveUserCount ()

This method is deprecated.
use totalBillableUsers(). since 6.5

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
See Also

@Deprecated public Collection<ApplicationUser> getAdministrators ()

This method is deprecated.
Since v4.3. Use 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.

@Deprecated @Nonnull public Collection<ApplicationUser> getAllApplicationUsers ()

This method is deprecated.
Use getAllApplicationUsers() instead. Since v6.5.

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.

@Deprecated @Nullable public Group getGroup (String groupName)

This method is deprecated.
Since v4.3. Use getGroup(java.lang.String) instead.

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<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

@Deprecated @Nullable public Group getGroupObject (String groupName)

This method is deprecated.
since 6.5. Use getGroup(java.lang.String) instead.

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
Throws
SearchException if something goes wrong

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
Throws
SearchException if something goes wrong

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

@Deprecated public Collection<ApplicationUser> getSystemAdministrators ()

This method is deprecated.
Since v4.3. Use 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

@Deprecated public int getTotalUserCount ()

This method is deprecated.
Use getTotalUserCount() instead. Since 7.0.

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

@Deprecated @Nullable public ApplicationUser getUser (String userName)

This method is deprecated.
Use getUserByKey(String) or getUserByName(String) instead. Since v6.0.

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.

@Deprecated @Nullable public ApplicationUser getUserByKey (String userkey)

This method is deprecated.
use getUserByKey(String). since 7.0

Returns a user based on key.

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

@Deprecated @Nullable public ApplicationUser getUserByName (String username)

This method is deprecated.
use getUserByName(String). since 7.0

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.

@Deprecated @Nullable public ApplicationUser getUserObject (String userName)

This method is deprecated.
Use getUserByKey(String) or getUserByName(String) instead. Since v6.0.

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.

@Deprecated @Nonnull public Collection<ApplicationUser> getUsers ()

This method is deprecated.
Use getAllApplicationUsers() instead. Since v6.5.

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

Returns
  • the set of all users defined in JIRA

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

This method is deprecated.
Use getAllUsersInGroupNames(java.util.Collection) instead. Since v4.3

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.

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

This method is deprecated.
Use getAllUsersInGroups(java.util.Collection) instead. Since v4.3

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