Class CrowdDirectoryEntityHelper

java.lang.Object
com.atlassian.confluence.impl.user.crowd.CrowdDirectoryEntityHelper

public final class CrowdDirectoryEntityHelper extends Object
Utility class for managing users in Crowd directories.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CrowdDirectoryEntityHelper(com.atlassian.crowd.embedded.api.CrowdDirectoryService crowdDirectoryService, com.atlassian.crowd.manager.directory.DirectoryManager crowdDirectoryManager, com.atlassian.crowd.manager.application.ApplicationService crowdApplicationService, com.atlassian.crowd.dao.application.ApplicationDAO applicationDAO)
    Constructs a new CrowdDirectoryEntityHelper with the given Crowd services.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.atlassian.crowd.model.user.User
    addUser(com.atlassian.crowd.model.user.UserTemplateWithAttributes userTemplate, String credential)
     
    Optional<com.atlassian.crowd.model.DirectoryEntity>
    findByName(String name, Class<? extends com.atlassian.crowd.model.DirectoryEntity> entityClass)
    Find an entity by its name.
    Optional<com.atlassian.crowd.model.group.Group>
    findGroupByName(long directoryId, String groupName)
    Returns the group matching the supplied groupName in the directory specified by the passed in directoryId..
    Optional<com.atlassian.crowd.model.user.User>
    findUserByName(long directoryId, String username)
    Returns the user matching the supplied username in the directory specified by the passed in directoryId..
    Retrieves a list of usernames of active users across all active directories.
    List<com.atlassian.crowd.model.group.Group>
    getDirectParent(com.atlassian.user.Group group)
     
    boolean
    groupExistsInAnyDirectories(String childGroupName, String parentGroupName)
    Returns true if the child group is a direct member of a group with the same name as the parent group in any active directories.
    boolean
    groupExistsInAnyDirectoriesBesidesDirectory(String childGroupName, String parentGroupName, String excludedDirectoryName)
    Returns true if the child group is a direct member a group with the same name as the parent group in any active directories, excluding the provided directory.
    <T extends com.atlassian.crowd.model.DirectoryEntity>
    boolean
    isCanonical(@Nullable T entity)
    NOTES: This method is stolen from Crowd's ApplicationServiceGeneric as we need to check an entity is canonical in Confluence Given a username is duplicated in several user directories, the entity in the first directory, according to directory ordering is considered to be the canonical entity for the given name, and the other entities are shadowed and thus not to be returned from searches.
    boolean
    userExistsInAnyDirectories(String username, String parentGroupName)
    Returns true if the user is a member of a group with the same name as the parent group in any active directories.
    boolean
    userExistsInAnyDirectoriesBesidesDirectory(String username, String groupName, String excludedDirectoryName)
    Returns true if the user is a member of a group with the same name as the group in any active directories, excluding the provided directory.
    boolean
    wasCanonical(String oldUsername, com.atlassian.crowd.model.user.User userWithNewUsername)
    Check if a user was canonical before renaming to the userWithNewUsername

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CrowdDirectoryEntityHelper

      public CrowdDirectoryEntityHelper(com.atlassian.crowd.embedded.api.CrowdDirectoryService crowdDirectoryService, com.atlassian.crowd.manager.directory.DirectoryManager crowdDirectoryManager, com.atlassian.crowd.manager.application.ApplicationService crowdApplicationService, com.atlassian.crowd.dao.application.ApplicationDAO applicationDAO)
      Constructs a new CrowdDirectoryEntityHelper with the given Crowd services.
      Parameters:
      crowdDirectoryService - the service for interacting with Crowd directories
      crowdDirectoryManager - the manager for performing directory operations
  • Method Details

    • isCanonical

      public <T extends com.atlassian.crowd.model.DirectoryEntity> boolean isCanonical(@Nullable T entity)
      NOTES: This method is stolen from Crowd's ApplicationServiceGeneric as we need to check an entity is canonical in Confluence Given a username is duplicated in several user directories, the entity in the first directory, according to directory ordering is considered to be the canonical entity for the given name, and the other entities are shadowed and thus not to be returned from searches.

      Type Parameters:
      T - the type of the entity
      Parameters:
      entity - to be determined as canonical or not. An entity can be a User or Group
      Returns:
      true; if the passed in user is canonical; otherwise, false is returned
      Since:
      9.2.6
    • wasCanonical

      public boolean wasCanonical(String oldUsername, com.atlassian.crowd.model.user.User userWithNewUsername)
      Check if a user was canonical before renaming to the userWithNewUsername
      Parameters:
      oldUsername - the old username
      userWithNewUsername - the User entity with new username
      Returns:
      true if the user with old username was canonical
      Since:
      9.2.6
    • findByName

      public Optional<com.atlassian.crowd.model.DirectoryEntity> findByName(String name, Class<? extends com.atlassian.crowd.model.DirectoryEntity> entityClass)
      Find an entity by its name. Only User or Group is supported
      Parameters:
      name - the name of the entity
      entityClass - the class of the entity
      Returns:
      an Optional that contains the object or an empty Optional
      Since:
      9.2.6
    • getActiveUserNames

      public List<String> getActiveUserNames()
      Retrieves a list of usernames of active users across all active directories.
      Returns:
      a list of active usernames
    • addUser

      public com.atlassian.crowd.model.user.User addUser(com.atlassian.crowd.model.user.UserTemplateWithAttributes userTemplate, String credential) throws com.atlassian.crowd.manager.directory.DirectoryPermissionException, com.atlassian.crowd.exception.DirectoryNotFoundException, com.atlassian.crowd.exception.OperationFailedException, com.atlassian.crowd.exception.InvalidCredentialException, com.atlassian.crowd.exception.UserAlreadyExistsException, com.atlassian.crowd.exception.InvalidUserException
      Throws:
      com.atlassian.crowd.manager.directory.DirectoryPermissionException
      com.atlassian.crowd.exception.DirectoryNotFoundException
      com.atlassian.crowd.exception.OperationFailedException
      com.atlassian.crowd.exception.InvalidCredentialException
      com.atlassian.crowd.exception.UserAlreadyExistsException
      com.atlassian.crowd.exception.InvalidUserException
    • findUserByName

      public Optional<com.atlassian.crowd.model.user.User> findUserByName(long directoryId, String username)
      Returns the user matching the supplied username in the directory specified by the passed in directoryId..
    • findGroupByName

      public Optional<com.atlassian.crowd.model.group.Group> findGroupByName(long directoryId, String groupName)
      Returns the group matching the supplied groupName in the directory specified by the passed in directoryId..
    • userExistsInAnyDirectories

      public boolean userExistsInAnyDirectories(String username, String parentGroupName)
      Returns true if the user is a member of a group with the same name as the parent group in any active directories.
      Parameters:
      username - the username of the user
      parentGroupName - the name of the parent group
    • groupExistsInAnyDirectories

      public boolean groupExistsInAnyDirectories(String childGroupName, String parentGroupName)
      Returns true if the child group is a direct member of a group with the same name as the parent group in any active directories.
      Parameters:
      childGroupName - the name of the child group
      parentGroupName - the name of the parent group
    • userExistsInAnyDirectoriesBesidesDirectory

      public boolean userExistsInAnyDirectoriesBesidesDirectory(String username, String groupName, String excludedDirectoryName)
      Returns true if the user is a member of a group with the same name as the group in any active directories, excluding the provided directory.
      Parameters:
      username - the username of the user
      groupName - the name of the parent group
      excludedDirectoryName - the name of the directory to exclude
    • groupExistsInAnyDirectoriesBesidesDirectory

      public boolean groupExistsInAnyDirectoriesBesidesDirectory(String childGroupName, String parentGroupName, String excludedDirectoryName)
      Returns true if the child group is a direct member a group with the same name as the parent group in any active directories, excluding the provided directory.
      Parameters:
      childGroupName - the name of the child group
      parentGroupName - the name of the parent group
      excludedDirectoryName - the name of the directory to exclude
    • getDirectParent

      public List<com.atlassian.crowd.model.group.Group> getDirectParent(com.atlassian.user.Group group) throws com.atlassian.crowd.exception.ApplicationNotFoundException
      Throws:
      com.atlassian.crowd.exception.ApplicationNotFoundException