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 newCrowdDirectoryEntityHelperwith the given Crowd services. -
Method Summary
Modifier and TypeMethodDescriptioncom.atlassian.crowd.model.user.UserOptional<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) booleangroupExistsInAnyDirectories(String childGroupName, String parentGroupName) Returnstrueif the child group is a direct member of a group with the same name as the parent group in any active directories.booleangroupExistsInAnyDirectoriesBesidesDirectory(String childGroupName, String parentGroupName, String excludedDirectoryName) Returnstrueif 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.booleanuserExistsInAnyDirectories(String username, String parentGroupName) Returnstrueif the user is a member of a group with the same name as the parent group in any active directories.booleanuserExistsInAnyDirectoriesBesidesDirectory(String username, String groupName, String excludedDirectoryName) Returnstrueif the user is a member of a group with the same name as the group in any active directories, excluding the provided directory.booleanwasCanonical(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 newCrowdDirectoryEntityHelperwith 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 aUserorGroup- Returns:
true; if the passed in user is canonical; otherwise,falseis 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- theUserentity with new username- Returns:
trueif 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. OnlyUserorGroupis 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.DirectoryPermissionExceptioncom.atlassian.crowd.exception.DirectoryNotFoundExceptioncom.atlassian.crowd.exception.OperationFailedExceptioncom.atlassian.crowd.exception.InvalidCredentialExceptioncom.atlassian.crowd.exception.UserAlreadyExistsExceptioncom.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
Returnstrueif 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
Returnstrueif 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) Returnstrueif 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) Returnstrueif 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
-