com.atlassian.jira.user.util
Class MockUserManager

java.lang.Object
  extended by com.atlassian.jira.user.util.MockUserManager
All Implemented Interfaces:
UserManager

public class MockUserManager
extends Object
implements UserManager

Really simple mock implementation

Since:
v4.1

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.jira.user.util.UserManager
UserManager.UserState
 
Constructor Summary
MockUserManager()
           
MockUserManager(MockUserKeyService mockUserKeyService)
           
 
Method Summary
 void addUser(ApplicationUser user)
           
 void addUser(com.atlassian.crowd.embedded.api.User user)
           
 boolean canDirectoryUpdateUserPassword(com.atlassian.crowd.embedded.api.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(com.atlassian.crowd.embedded.api.User 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 canUpdateUser(com.atlassian.crowd.embedded.api.User user)
          Test if this user can be updated, i.e.
 boolean canUpdateUserPassword(com.atlassian.crowd.embedded.api.User user)
          Test if this user's password can be updated, i.e.
 com.atlassian.crowd.embedded.api.User findUserInDirectory(String userName, Long directoryId)
          Returns a User based on user name and directoryId
 Collection<ApplicationUser> getAllApplicationUsers()
          Returns all users defined in JIRA, regardless of whether they are active or not.
 Set<com.atlassian.crowd.embedded.api.Group> getAllGroups()
          Returns all groups defined in JIRA.
 Set<com.atlassian.crowd.embedded.api.User> getAllUsers()
          Returns all users defined in JIRA, regardless of whether they are active or not.
 com.atlassian.crowd.embedded.api.Directory getDirectory(Long directoryId)
           
 com.atlassian.crowd.embedded.api.Group getGroup(String groupName)
          Returns a Group based on user name.
 com.atlassian.crowd.embedded.api.Group getGroupObject(String groupName)
          Returns a Group based on user name.
 Collection<com.atlassian.crowd.embedded.api.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.
 com.atlassian.crowd.embedded.api.User getUser(String userName)
          Returns a User based on user name.
 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.
 com.atlassian.crowd.embedded.api.User getUserEvenWhenUnknown(String userName)
          Returns a User based on user name.
 com.atlassian.crowd.embedded.api.User getUserObject(String userName)
          Returns a User based on user name.
 Collection<com.atlassian.crowd.embedded.api.User> getUsers()
          Returns all users defined in JIRA, regardless of whether they are active or not.
 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 UserManager.UserState.INVALID_USER.
 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.
 UserManager.UserState getUserState(com.atlassian.crowd.embedded.api.User user)
          This convenience method is equivalent to getUserState(user.getName(), user.getDirectoryId()) except that a null user is permitted and returns UserManager.UserState.INVALID_USER.
 List<com.atlassian.crowd.embedded.api.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 setGroupWritableDirectory(boolean groupWritableDirectory)
           
 void setWritableDirectory(boolean writableDirectory)
           
 void updateUser(ApplicationUser user)
          Updates the ApplicationUser.
 void updateUser(com.atlassian.crowd.embedded.api.User user)
          Updates the User.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockUserManager

public MockUserManager()

MockUserManager

public MockUserManager(MockUserKeyService mockUserKeyService)
Method Detail

getTotalUserCount

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

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

getAllUsers

@Nonnull
public Set<com.atlassian.crowd.embedded.api.User> getAllUsers()
Description copied from interface: UserManager
Returns all users defined in JIRA, regardless of whether they are active or not.

Specified by:
getAllUsers in interface UserManager
Returns:
the set of all users

getUser

public com.atlassian.crowd.embedded.api.User getUser(@Nullable
                                                     String userName)
Description copied from interface: UserManager
Returns a User based on user name.

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

getUserObject

public com.atlassian.crowd.embedded.api.User getUserObject(@Nullable
                                                           String userName)
Description copied from interface: UserManager
Returns a User based on user name.

Specified by:
getUserObject in interface UserManager
Parameters:
userName - the user name of the user
Returns:
the User object, or null if the user cannot be found including null userName.

getUserByKey

public ApplicationUser getUserByKey(@Nullable
                                    String userKey)
Description copied from interface: UserManager
Returns an ApplicationUser based on user key.

Specified by:
getUserByKey in interface UserManager
Parameters:
userKey - the key of the user
Returns:
the ApplicationUser object

getUserByName

public ApplicationUser getUserByName(@Nullable
                                     String userName)
Description copied from interface: UserManager
Returns an ApplicationUser based on user name.

Specified by:
getUserByName in interface UserManager
Parameters:
userName - the user name of the user
Returns:
the ApplicationUser object

getUserByKeyEvenWhenUnknown

public ApplicationUser getUserByKeyEvenWhenUnknown(@Nullable
                                                   String userKey)
Description copied from interface: UserManager
Returns an ApplicationUser based on user key.

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

Specified by:
getUserByKeyEvenWhenUnknown in interface UserManager
Parameters:
userKey - the key of the user
Returns:
the ApplicationUser object, or proxy unknown immutable ApplicationUser object (null iff the key is null).

getUserByNameEvenWhenUnknown

public ApplicationUser getUserByNameEvenWhenUnknown(@Nullable
                                                    String userName)
Description copied from interface: UserManager
Returns an ApplicationUser based on user name.

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

Specified by:
getUserByNameEvenWhenUnknown in interface UserManager
Parameters:
userName - the user name of the user
Returns:
the ApplicationUser object, or proxy unknown immutable ApplicationUser object (null iff the username is null).

findUserInDirectory

public com.atlassian.crowd.embedded.api.User findUserInDirectory(String userName,
                                                                 Long directoryId)
Description copied from interface: UserManager
Returns a User based on user name and directoryId

Specified by:
findUserInDirectory in interface UserManager
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.

getUserEvenWhenUnknown

public com.atlassian.crowd.embedded.api.User getUserEvenWhenUnknown(String userName)
Description copied from interface: UserManager
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.

Specified by:
getUserEvenWhenUnknown in interface UserManager
Parameters:
userName - the user name of the user
Returns:
the User object, or proxy unknown immutable User object (null iff the username is null).

canUpdateUser

public boolean canUpdateUser(com.atlassian.crowd.embedded.api.User user)
Description copied from interface: UserManager
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.

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

Specified by:
canUpdateUser in interface UserManager
Parameters:
user - The user to update.
Returns:
true if the user is not null and can be updated.

canUpdateUser

public boolean canUpdateUser(ApplicationUser user)
Description copied from interface: UserManager
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.

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

Specified by:
canUpdateUser in interface UserManager
Parameters:
user - The user to update.
Returns:
true if the user is not null and can be updated.

canRenameUser

public boolean canRenameUser(ApplicationUser user)
Description copied from interface: UserManager
Test if this user can be renamed. In addition to the constraints of UserManager.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 APKeys.JIRA_OPTION_USER_CROWD_ALLOW_RENAME is enabled to bypass this check.

Specified by:
canRenameUser in interface UserManager
Parameters:
user - The user to rename.
Returns:
true if the user is not null and can be renamed.

updateUser

public void updateUser(com.atlassian.crowd.embedded.api.User user)
Description copied from interface: UserManager
Updates the User. The user must have non-null names and email address.

Specified by:
updateUser in interface UserManager
Parameters:
user - The user to update.

updateUser

public void updateUser(ApplicationUser user)
Description copied from interface: UserManager
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.

Specified by:
updateUser in interface UserManager
Parameters:
user - The user to update.

canUpdateUserPassword

public boolean canUpdateUserPassword(com.atlassian.crowd.embedded.api.User user)
Description copied from interface: UserManager
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.

Specified by:
canUpdateUserPassword in interface UserManager
Parameters:
user - The user to update.
Returns:
true if the user is not null and the user's password can be updated.

canUpdateGroupMembershipForUser

public boolean canUpdateGroupMembershipForUser(com.atlassian.crowd.embedded.api.User user)
Description copied from interface: UserManager
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.

Specified by:
canUpdateGroupMembershipForUser in interface UserManager
Parameters:
user - The user to update.
Returns:
true if the user is not null and can be updated.

getAllGroups

public Set<com.atlassian.crowd.embedded.api.Group> getAllGroups()
Description copied from interface: UserManager
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.

Specified by:
getAllGroups in interface UserManager
Returns:
the set of all groups

getGroup

public com.atlassian.crowd.embedded.api.Group getGroup(@Nullable
                                                       String groupName)
Description copied from interface: UserManager
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.

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

getGroupObject

public com.atlassian.crowd.embedded.api.Group getGroupObject(@Nullable
                                                             String groupName)
Description copied from interface: UserManager
Returns a Group based on user name.

Legacy synonym for UserManager.getGroup(String).

Specified by:
getGroupObject in interface UserManager
Parameters:
groupName - the user name of the group
Returns:
the Group object, or null if the group cannot be found including null groupName.
See Also:
UserManager.getGroup(String)

getWritableDirectories

@Nonnull
public List<com.atlassian.crowd.embedded.api.Directory> getWritableDirectories()
Description copied from interface: UserManager
Returns an ordered list of directories that have "read-write" permission. ie those directories that we can add a user to.

Specified by:
getWritableDirectories in interface UserManager
Returns:
an ordered list of directories that have "read-write" permission.
See Also:
UserManager.hasWritableDirectory()

hasWritableDirectory

public boolean hasWritableDirectory()
Description copied from interface: UserManager
Returns true if at least one User Directory has "read-write" permission.

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

Specified by:
hasWritableDirectory in interface UserManager
Returns:
true if at least one User Directory has "read-write" permission.
See Also:
UserManager.getWritableDirectories(), UserManager.hasPasswordWritableDirectory(), UserManager.hasGroupWritableDirectory()

setWritableDirectory

public void setWritableDirectory(boolean writableDirectory)

hasPasswordWritableDirectory

public boolean hasPasswordWritableDirectory()
Description copied from interface: UserManager
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 UserManager.hasWritableDirectory() because of "Internal with LDAP Authentication" directories. These directories are generally read-write but passwords are read-only.

Specified by:
hasPasswordWritableDirectory in interface UserManager
Returns:
true if any of the directories have permission to update user passwords, false if otherwise.
See Also:
UserManager.hasWritableDirectory()

hasGroupWritableDirectory

public boolean hasGroupWritableDirectory()
Description copied from interface: UserManager
Returns true if any of the directories have permission to update groups.

Note that this will not always return the same results as UserManager.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.

Specified by:
hasGroupWritableDirectory in interface UserManager
Returns:
true if any of the directories have permission to update groups, false if otherwise.
See Also:
UserManager.hasWritableDirectory()

setGroupWritableDirectory

public void setGroupWritableDirectory(boolean groupWritableDirectory)

canDirectoryUpdateUserPassword

public boolean canDirectoryUpdateUserPassword(com.atlassian.crowd.embedded.api.Directory directory)
Description copied from interface: UserManager
Checks if the given directory is able to update user passwords.

Specified by:
canDirectoryUpdateUserPassword in interface UserManager
Parameters:
directory - the Directory
Returns:
true if the directory can update user passwords, false if otherwise.

getDirectory

public com.atlassian.crowd.embedded.api.Directory getDirectory(Long directoryId)
Specified by:
getDirectory in interface UserManager

isUserExisting

public boolean isUserExisting(@Nullable
                              ApplicationUser user)
Description copied from interface: UserManager
Checks if given user is existing user

Specified by:
isUserExisting in interface UserManager
Parameters:
user - possible existing user object - i.e. recieved from UserManager.getUserByKeyEvenWhenUnknown(String) or UserManager.getUserByNameEvenWhenUnknown(String)
Returns:
true if given user is real user, false otherwise (also when given object is null)
See Also:
UserManager.getUserByKeyEvenWhenUnknown(String), UserManager.getUserByNameEvenWhenUnknown(String)

getUsers

@Nonnull
public Collection<com.atlassian.crowd.embedded.api.User> getUsers()
Description copied from interface: UserManager
Returns all users defined in JIRA, regardless of whether they are active or not.

Legacy synonym for UserManager.getAllUsers().

Specified by:
getUsers in interface UserManager
Returns:
the collection of all users
See Also:
UserManager.getAllUsers()

getAllApplicationUsers

@Nonnull
public Collection<ApplicationUser> getAllApplicationUsers()
Description copied from interface: UserManager
Returns all users defined in JIRA, regardless of whether they are active or not.

Specified by:
getAllApplicationUsers in interface UserManager
Returns:
the set of all users

getGroups

public Collection<com.atlassian.crowd.embedded.api.Group> getGroups()
Description copied from interface: UserManager
Returns all groups defined in JIRA.

Legacy synonym for UserManager.getAllGroups().

Specified by:
getGroups in interface UserManager
Returns:
the set of all groups
See Also:
UserManager.getAllGroups()

addUser

public void addUser(com.atlassian.crowd.embedded.api.User user)

addUser

public void addUser(ApplicationUser user)

getMockUserKeyService

public MockUserKeyService getMockUserKeyService()

getUserState

@Nonnull
public UserManager.UserState getUserState(@Nullable
                                                  com.atlassian.crowd.embedded.api.User user)
Description copied from interface: UserManager
This convenience method is equivalent to getUserState(user.getName(), user.getDirectoryId()) except that a null user is permitted and returns UserManager.UserState.INVALID_USER.

Specified by:
getUserState in interface UserManager
Parameters:
user - the user to check
Returns:
the shadowing state of the specified user

getUserState

@Nonnull
public UserManager.UserState getUserState(@Nullable
                                                  ApplicationUser user)
Description copied from interface: UserManager
This convenience method is equivalent to getUserState(user.getUsername(), user.getDirectoryId()) except that a null user is permitted and returns UserManager.UserState.INVALID_USER.

Specified by:
getUserState in interface UserManager
Parameters:
user - the user to check
Returns:
the shadowing state of the specified user

getUserState

@Nonnull
public UserManager.UserState getUserState(@Nonnull
                                                  String username,
                                                  long directoryId)
Description copied from interface: UserManager
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.

Specified by:
getUserState in interface UserManager
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


Copyright © 2002-2013 Atlassian. All Rights Reserved.