public class

MockUserManager

extends Object
implements UserManager
java.lang.Object
   ↳ com.atlassian.jira.user.util.MockUserManager

Class Overview

Really simple mock implementation

Summary

Public Constructors
MockUserManager()
MockUserManager(MockUserKeyService mockUserKeyService)
MockUserManager(MockCrowdService crowdService)
Public Methods
ApplicationUser addUser(ApplicationUser user)
MockUserManager alwaysReturnUsers()
boolean canDirectoryUpdateUserPassword(Directory directory)
Checks if the given directory is able to update user passwords.
boolean canRenameUser(ApplicationUser user)
Test if this user can be renamed.
boolean canUpdateGroupMembershipForUser(ApplicationUser user)
Test if this user's group membership can be updated, i.e.
boolean canUpdateUser(ApplicationUser user)
Test if this user can be updated, i.e.
boolean canUpdateUserPassword(ApplicationUser user)
Test if this user's password can be updated, i.e.
@Nonnull ApplicationUser createUser(UserDetails userData)
Creates a user in the specified directory (userDirectoryId).
MockUserManager doNotUseCrowdServiceToGetUsers()
ApplicationUser findUserInDirectory(String userName, Long directoryId)
Returns a User based on user name and directoryId
@Nonnull String generateRandomPassword()
Generates a random password that can be used when the admin has entered a blank password.
@Nonnull Collection<ApplicationUser> getAllApplicationUsers()
Returns all users defined in JIRA, regardless of whether they are active or not.
Set<Group> getAllGroups()
Returns all groups defined in JIRA.
@Nonnull Set<ApplicationUser> getAllUsers()
Returns all users defined in JIRA, regardless of whether they are active or not.
@Nonnull Optional<Directory> getDefaultCreateDirectory()
Get the Directory in which users will be created by default
Directory getDirectory(Long directoryId)
Group getGroup(String groupName)
Returns a Group based on user name.
Group getGroupObject(String groupName)
Returns a Group based on user name.
Collection<Group> getGroups()
Returns all groups defined in JIRA.
MockUserKeyService getMockUserKeyService()
int getTotalUserCount()
Returns the total number of users defined in JIRA, regardless of whether they are active or not.
ApplicationUser getUser(String userName)
Returns a User based on user name.
Optional<ApplicationUser> getUserById(Long id)
Returns a user based in id.
ApplicationUser getUserByKey(String userKey)
Returns an ApplicationUser based on user key.
ApplicationUser getUserByKeyEvenWhenUnknown(String userKey)
Returns an ApplicationUser based on user key.
ApplicationUser getUserByName(String userName)
Returns an ApplicationUser based on user name.
ApplicationUser getUserByNameEvenWhenUnknown(String userName)
Returns an ApplicationUser based on user name.
ApplicationUser getUserEvenWhenUnknown(String userName)
Returns a User based on user name.
Optional<UserIdentity> getUserIdentityById(Long id)
Returns an identity of the user with the specified id.
Optional<UserIdentity> getUserIdentityByKey(String key)
Returns an identity of the user with the specified key.
Optional<UserIdentity> getUserIdentityByUsername(String username)
Returns an identity of the user with the specified username.
ApplicationUser getUserObject(String userName)
Returns a User based on user name.
@Nonnull UserManager.UserState getUserState(ApplicationUser user)
This convenience method is equivalent to getUserState(user.getUsername(), user.getDirectoryId()) except that a null user is permitted and returns INVALID_USER.
@Nonnull UserManager.UserState getUserState(String username, long directoryId)
Checks for the existence of this user across all directories to determine whether or not the user exists in the specified directory and whether or not it is shadowing or shadowed by a user with the same username in another active user directory.
@Nonnull Collection<ApplicationUser> getUsers()
Returns all users defined in JIRA, regardless of whether they are active or not.
@Nonnull List<Directory> getWritableDirectories()
Returns an ordered list of directories that have "read-write" permission.
boolean hasGroupWritableDirectory()
Returns true if any of the directories have permission to update groups.
boolean hasPasswordWritableDirectory()
Returns true if any of the directories have permission to update user passwords, false if otherwise.
boolean hasWritableDirectory()
Returns true if at least one User Directory has "read-write" permission.
boolean isUserExisting(ApplicationUser user)
Checks if given user is existing user
void putDirectory(Long directoryId, Directory directory)
void setCrowdService(MockCrowdService crowdService)
void setGroupWritableDirectory(boolean groupWritableDirectory)
void setWritableDirectory(boolean writableDirectory)
void updateUser(ApplicationUser user)
Updates the ApplicationUser.
MockUserManager useCrowdServiceToGetUsers()
boolean userCanUpdateOwnDetails(ApplicationUser user)
Check if this user is allowed to update their own user details.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.user.util.UserManager

Public Constructors

public MockUserManager ()

public MockUserManager (MockUserKeyService mockUserKeyService)

public MockUserManager (MockCrowdService crowdService)

Public Methods

public ApplicationUser addUser (ApplicationUser user)

public MockUserManager alwaysReturnUsers ()

public boolean canDirectoryUpdateUserPassword (Directory directory)

Checks if the given directory is able to update user passwords.

Parameters
directory the Directory
Returns
  • true if the directory can update user passwords, false if otherwise.

public boolean canRenameUser (ApplicationUser user)

Test if this user can be renamed. In addition to the constraints of canUpdateUser(ApplicationUser), renaming a user is only allowed when:

  1. The user is in either an INTERNAL or DELEGATING user directory; AND
  2. Either JIRA is not configured as a crowd server, or JIRA_OPTION_USER_CROWD_ALLOW_RENAME is enabled to bypass this check.

Parameters
user The user to rename.
Returns
  • true if the user is not null and can be renamed.

public boolean canUpdateGroupMembershipForUser (ApplicationUser user)

Test if this user's group membership can be updated, i.e. is in a writable directory or a directory with Local Group support. This relies upon the local directory configuration and does not guarantee that the actual remote directory, e.g. the remote LDAP directory, will actually allow the user membership to be updated.

Parameters
user The user to update.
Returns
  • true if the user is not null and can be updated.

public boolean canUpdateUser (ApplicationUser user)

Test if this user can be updated, i.e. is in a writable directory. This relies upon the local directory configuration and does not guarantee that the actual remote directory, e.g. the remote LDAP directory, will actually allow the user to be updated.

Parameters
user The user to update.
Returns
  • true if the user can be updated.

public boolean canUpdateUserPassword (ApplicationUser user)

Test if this user's password can be updated, i.e. is in a writable directory which is not a Delegated LDAP directory. This relies upon the local directory configuration and does not guarantee that the actual remote directory, e.g. the remote LDAP directory, will actually allow the user to be updated.

If the "External user management", or "External password management" setting is on, then you cannot update the password.

Parameters
user The user to update.
Returns
  • true if the user is not null and the user's password can be updated.

@Nonnull public ApplicationUser createUser (UserDetails userData)

Creates a user in the specified directory (userDirectoryId). If the directory is none(), the user is created in the default directory (usually an Embedded Crowd internal directory).

Parameters
userData the user request containing user details.
Returns
  • the newly created user.

public MockUserManager doNotUseCrowdServiceToGetUsers ()

public ApplicationUser findUserInDirectory (String userName, Long directoryId)

Returns a User based on user name and directoryId

Parameters
userName the user name of the user
directoryId the Directory to look in
Returns
  • the User object, or null if the user cannot be found including null userName.

@Nonnull public String generateRandomPassword ()

Generates a random password that can be used when the admin has entered a blank password.

The password is guaranteed to contain at least one upper-case letter, lower-case letter and number in case the backend user Directory has password restrictions.

Returns
  • a random password.

@Nonnull public Collection<ApplicationUser> getAllApplicationUsers ()

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

Returns
  • the set of all users

public Set<Group> getAllGroups ()

Returns all groups defined in JIRA.

Warning: previous incarnations of this method returned com.opensymphony.user.User. This class has now been removed from the JIRA API, meaning that the 5.0 version is not binary or source compatible with earlier versions.

Returns
  • the set of all groups

@Nonnull public Set<ApplicationUser> getAllUsers ()

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

Returns
  • the set of all users

@Nonnull public Optional<Directory> getDefaultCreateDirectory ()

Get the Directory in which users will be created by default

Returns

public Directory getDirectory (Long directoryId)

public Group getGroup (String groupName)

Returns a Group based on user name.

Warning: previous incarnations of this method returned com.opensymphony.user.User. This class has now been removed from the JIRA API, meaning that the 5.0 version is not binary or source compatible with earlier versions.

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

public Group getGroupObject (String groupName)

Returns a Group based on user name.

Legacy synonym for getGroup(String).

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

public Collection<Group> getGroups ()

Returns all groups defined in JIRA.

Legacy synonym for getAllGroups().

Returns
  • the set of all groups

public MockUserKeyService getMockUserKeyService ()

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)

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 Optional<ApplicationUser> getUserById (Long id)

Returns a user based in id.

Parameters
id user id
Returns
  • user if found or none

public ApplicationUser getUserByKey (String userKey)

Returns an ApplicationUser based on user key.

Parameters
userKey the key of the user
Returns
  • the ApplicationUser object

public ApplicationUser getUserByKeyEvenWhenUnknown (String userKey)

Returns an ApplicationUser based on user key.

If you want to check if given user is known user - please use isUserExisting(com.atlassian.jira.user.ApplicationUser)

Parameters
userKey the key of the user
Returns
  • the ApplicationUser object, or proxy unknown immutable ApplicationUser object (null iff the key is null).

public ApplicationUser getUserByName (String userName)

Returns an ApplicationUser based on user name.

Parameters
userName the user name of the user
Returns
  • the ApplicationUser object

public ApplicationUser getUserByNameEvenWhenUnknown (String userName)

Returns an ApplicationUser based on user name.

If you want to check if given user is known user - please use isUserExisting(com.atlassian.jira.user.ApplicationUser)

Parameters
userName the user name of the user
Returns
  • the ApplicationUser object, or proxy unknown immutable ApplicationUser object (null iff the username is null).

public ApplicationUser getUserEvenWhenUnknown (String userName)

Returns a User based on user name.

If a null username is passed, then a null User object is returned, but it is guaranteed to return a non-null User in all other cases.
If the username is not null, but the User is not found then a proxy unknown immutable User object is returned.

Parameters
userName the user name of the user
Returns
  • the User object, or proxy unknown immutable User object (null iff the username is null).

public Optional<UserIdentity> getUserIdentityById (Long id)

Returns an identity of the user with the specified id.

Parameters
id user id
Returns
  • user identity or none if no user with the specified key exists.

public Optional<UserIdentity> getUserIdentityByKey (String key)

Returns an identity of the user with the specified key.

Parameters
key user key
Returns
  • user identity or none if no user with the specified key exists.

public Optional<UserIdentity> getUserIdentityByUsername (String username)

Returns an identity of the user with the specified username.

Parameters
username user name
Returns
  • user identity or none if no user with the specified username exists.

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 UserManager.UserState getUserState (ApplicationUser user)

This convenience method is equivalent to getUserState(user.getUsername(), user.getDirectoryId()) except that a null user is permitted and returns INVALID_USER.

Parameters
user the user to check
Returns
  • the shadowing state of the specified user

@Nonnull public UserManager.UserState getUserState (String username, long directoryId)

Checks for the existence of this user across all directories to determine whether or not the user exists in the specified directory and whether or not it is shadowing or shadowed by a user with the same username in another active user directory.

Parameters
username the username to check
directoryId the directory ID of the user directory that the user came from
Returns
  • the shadowing state of the specified user

@Nonnull public Collection<ApplicationUser> getUsers ()

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

Legacy synonym for getAllUsers().

Returns
  • the collection of all users

@Nonnull public List<Directory> getWritableDirectories ()

Returns an ordered list of directories that have "read-write" permission. ie those directories that we can add a user to.

Returns
  • an ordered list of directories that have "read-write" permission.

public boolean hasGroupWritableDirectory ()

Returns true if any of the directories have permission to update groups.

Note that this will not always return the same results as hasWritableDirectory() because you can set "Read-Only with Local Groups" to LDAP directories. These directories are generally read-only but you can create local gropus and assign users to them.

Returns
  • true if any of the directories have permission to update groups, false if otherwise.

public boolean hasPasswordWritableDirectory ()

Returns true if any of the directories have permission to update user passwords, false if otherwise.

Note that this is not quite the same as hasWritableDirectory() because of "Internal with LDAP Authentication" directories. These directories are generally read-write but passwords are read-only.

Returns
  • true if any of the directories have permission to update user passwords, false if otherwise.

public boolean hasWritableDirectory ()

Returns true if at least one User Directory has "read-write" permission.

This is equivalent to:
  getWritableDirectories().size() > 0

Returns
  • true if at least one User Directory has "read-write" permission.

public boolean isUserExisting (ApplicationUser user)

Checks if given user is existing user

Parameters
user possible existing user object - i.e. recieved from getUserByKeyEvenWhenUnknown(String) or getUserByNameEvenWhenUnknown(String)
Returns
  • true if given user is real user, false otherwise (also when given object is null)

public void putDirectory (Long directoryId, Directory directory)

public void setCrowdService (MockCrowdService crowdService)

public void setGroupWritableDirectory (boolean groupWritableDirectory)

public void setWritableDirectory (boolean writableDirectory)

public void updateUser (ApplicationUser user)

Updates the ApplicationUser. The user must have non-null names and email address. If the user's name does not match the name that is currently associated with the key, then this is implicitly treated as a request to rename the user.

Parameters
user The user to update.

public MockUserManager useCrowdServiceToGetUsers ()

public boolean userCanUpdateOwnDetails (ApplicationUser user)

Check if this user is allowed to update their own user details.

Returns true if the given user is in a read-write directory AND the "External user management" setting is off.

Parameters
user The user
Returns
  • true if the given user is in a read-write directory AND the "External user management" setting is off.