Class CrowdDirectoryEntityHelper
java.lang.Object
com.atlassian.confluence.impl.user.crowd.CrowdDirectoryEntityHelper
Utility class for managing users in Crowd directories.
-
Constructor Summary
ConstructorsConstructorDescriptionCrowdDirectoryEntityHelper
(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 newCrowdDirectoryEntityHelper
with the given Crowd services. -
Method Summary
Modifier and TypeMethodDescriptioncom.atlassian.crowd.model.user.User
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 indirectoryId
..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 indirectoryId
..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) Returnstrue
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) Returnstrue
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>
booleanisCanonical
(@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 severaluser 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) Returnstrue
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) Returnstrue
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
-
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 newCrowdDirectoryEntityHelper
with the given Crowd services.- Parameters:
crowdDirectoryService
- the service for interacting with Crowd directoriescrowdDirectoryManager
- 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 severaluser 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 aUser
orGroup
- 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 usernameuserWithNewUsername
- theUser
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. OnlyUser
orGroup
is supported -
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 indirectoryId
.. -
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 indirectoryId
.. -
userExistsInAnyDirectories
Returnstrue
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 userparentGroupName
- the name of the parent group
-
groupExistsInAnyDirectories
Returnstrue
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 groupparentGroupName
- the name of the parent group
-
userExistsInAnyDirectoriesBesidesDirectory
public boolean userExistsInAnyDirectoriesBesidesDirectory(String username, String groupName, String excludedDirectoryName) Returnstrue
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 usergroupName
- the name of the parent groupexcludedDirectoryName
- the name of the directory to exclude
-
groupExistsInAnyDirectoriesBesidesDirectory
public boolean groupExistsInAnyDirectoriesBesidesDirectory(String childGroupName, String parentGroupName, String excludedDirectoryName) Returnstrue
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 groupparentGroupName
- the name of the parent groupexcludedDirectoryName
- 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
-