Class DefaultUserManager

java.lang.Object
com.atlassian.jira.user.util.DefaultUserManager
All Implemented Interfaces:
UserManager

public class DefaultUserManager extends Object implements UserManager
  • Field Details

  • Constructor Details

    • DefaultUserManager

      public DefaultUserManager(com.atlassian.crowd.embedded.api.CrowdService crowdService, com.atlassian.crowd.embedded.api.CrowdDirectoryService crowdDirectoryService, com.atlassian.crowd.manager.directory.DirectoryManager directoryManager, UserKeyStore userKeyStore, com.atlassian.crowd.manager.application.ApplicationManager applicationManager, ApplicationProperties applicationProperties, ExtendedUserDao userDao, DuplicatedUsersService duplicatedUsersService)
  • Method Details

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

      public ApplicationUser 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.
    • getUserById

      public Optional<ApplicationUser> getUserById(Long id)
      Description copied from interface: UserManager
      Returns a user based in id.
      Specified by:
      getUserById in interface UserManager
      Parameters:
      id - user id
      Returns:
      user if found or none
    • getUserByKey

      public ApplicationUser getUserByKey(String key)
      Description copied from interface: UserManager
      Returns an ApplicationUser based on user key.
      Specified by:
      getUserByKey in interface UserManager
      Parameters:
      key - the key of the user
      Returns:
      the ApplicationUser object
    • getUserByName

      public ApplicationUser getUserByName(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 if 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).
    • 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.
      Specified by:
      canUpdateUser in interface UserManager
      Parameters:
      user - The user to update.
      Returns:
      true if the user can be updated.
    • userCanUpdateOwnDetails

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

      Specified by:
      userCanUpdateOwnDetails in interface UserManager
      Parameters:
      user - The user
      Returns:
      true if the given user is in a read-write directory AND the "External user management" setting is off.
    • 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(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(ApplicationUser 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(ApplicationUser 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.
    • getGroup

      public com.atlassian.crowd.embedded.api.Group getGroup(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:
    • 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:
    • getDefaultCreateDirectory

      @Nonnull public Optional<com.atlassian.crowd.embedded.api.Directory> getDefaultCreateDirectory()
      Description copied from interface: UserManager
      Get the Directory in which users will be created by default
      Specified by:
      getDefaultCreateDirectory in interface UserManager
      Returns:
      Directory or Option.none() in case there is no writable directories
    • 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:
    • 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:
    • 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:
    • getDirectory

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

      public boolean isUserExisting(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. received 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:
    • isUserDeleted

      public boolean isUserDeleted(@Nullable ApplicationUser user)
      Description copied from interface: UserManager
      Checks if given user is deleted user. Deleted user exists in jira app_users DB table (has user key and username) but does not exist in crowd (no user data eg. Full name, email etc.).
      Specified by:
      isUserDeleted in interface UserManager
      Parameters:
      user - possible deleted user object - i.e. received from UserManager.getUserByKeyEvenWhenUnknown(String) or UserManager.getUserByNameEvenWhenUnknown(String)
      Returns:
      true if given user is user existing in app_users DB table but does not exist in crowd, false otherwise (also when given object is null)
      See Also:
    • generateRandomPassword

      @Nonnull public String generateRandomPassword()
      Description copied from interface: UserManager
      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.

      Specified by:
      generateRandomPassword in interface UserManager
      Returns:
      a random password.
    • 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.
    • 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 queryDirectoryId)
      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
      queryDirectoryId - the directory ID of the user directory that the user came from
      Returns:
      the shadowing state of the specified user
    • createUser

      @Nonnull public ApplicationUser createUser(@Nonnull UserDetails userData) throws CreateException, PermissionException
      Description copied from interface: UserManager
      Creates a user in the specified directory (userDirectoryId). If the directory is Option.none(), the user is created in the default directory (usually an Embedded Crowd internal directory).
      Specified by:
      createUser in interface UserManager
      Parameters:
      userData - the user request containing user details.
      Returns:
      the newly created user.
      Throws:
      CreateException - unable to create user.
      PermissionException - unable to create user due to permission error.
    • getUserIdentityById

      public Optional<UserIdentity> getUserIdentityById(Long id)
      Description copied from interface: UserManager
      Returns an identity of the user with the specified id.
      Specified by:
      getUserIdentityById in interface UserManager
      Parameters:
      id - user id
      Returns:
      user identity or none if no user with the specified key exists.
    • getUserIdentityByKey

      public Optional<UserIdentity> getUserIdentityByKey(String key)
      Description copied from interface: UserManager
      Returns an identity of the user with the specified key.
      Specified by:
      getUserIdentityByKey in interface UserManager
      Parameters:
      key - user key
      Returns:
      user identity or none if no user with the specified key exists.
    • getUserIdentityByUsername

      public Optional<UserIdentity> getUserIdentityByUsername(String username)
      Description copied from interface: UserManager
      Returns an identity of the user with the specified username.
      Specified by:
      getUserIdentityByUsername in interface UserManager
      Parameters:
      username - user name
      Returns:
      user identity or none if no user with the specified username exists.
    • getDuplicatedUserMapping

      @Nonnull public DuplicatedUsersToDirectoriesMapping getDuplicatedUserMapping()
      Description copied from interface: UserManager
      This method returns a mapping of duplicated users to the directories they have their accounts in together with information on whether the accounts are active. Duplicated means that the user has an account in more than one directory and either more than one account is active or the only active account does not belong to the directory with the highest priority.
      Specified by:
      getDuplicatedUserMapping in interface UserManager
      Returns:
      map of users who have duplicated accounts and their directories.