public class DbCachingRemoteDirectory extends AbstractForwardingToInternalRemoteDirectory implements InternalRemoteDirectory, SynchronisableDirectory
RemoteDirectory that provides LDAP and Crowd integration plus local storage in an internal directory
for LDAP user and group attributes, and local groups for LDAP and Crowd users with local caching of remote data.
The implementation delegates to an Remote directory for the "source of truth" and an internal directory for caching
and some special local storage.
All the attributes for the directory itself (e.g. base DN, other configuration options) are stored on the directory instance.
Terminology used in this class:
| Modifier and Type | Field and Description |
|---|---|
static String |
INTERNAL_USER_PASSWORD |
| Constructor and Description |
|---|
DbCachingRemoteDirectory(RemoteDirectory remoteDirectory,
InternalRemoteDirectory internalDirectory,
DirectoryCacheFactory directoryCacheFactory,
CacheRefresherFactory cacheRefresherFactory,
AuditService auditService,
AuditLogUserMapper auditLogUserMapper,
String directoryName,
com.atlassian.event.api.EventPublisher eventPublisher,
DirectoryDao directoryDao) |
| Modifier and Type | Method and Description |
|---|---|
Group |
addGroup(GroupTemplate group)
Adds a
group to the directory store. |
void |
addGroupToGroup(String childGroup,
String parentGroup)
Adds a group as a member of a parent group.
|
UserWithAttributes |
addUser(UserTemplateWithAttributes user,
PasswordCredential credential)
Adds a
user to the directory store. |
void |
addUserToGroup(String username,
String groupName)
Adds a user as a member of a group.
|
User |
authenticate(String name,
PasswordCredential credential)
Authenticates a
user with the directory store. |
protected User |
authenticateAndUpdateInternalUser(String name,
PasswordCredential credential)
Authenticates user and ensures that internal directory contains the
authenticated user.
|
void |
expireAllPasswords()
Sets the
UserConstants.REQUIRES_PASSWORD_CHANGE attribute to true for
all users in the directory using bulk operations |
RemoteDirectory |
getAuthoritativeDirectory() |
protected InternalRemoteDirectory |
getDelegate() |
String |
getDescriptiveName()
Returns a descriptive name for the type of directory.
|
long |
getDirectoryId()
Gets the internal unique
directoryId of the directory store. |
Set<String> |
getKeys()
Gets all the keys of the attributes.
|
String |
getValue(String name)
Returns any value associated with the given key, returns
null if there is no value. |
Set<String> |
getValues(String name)
Get all the values associated with a given key.
|
boolean |
isEmpty() |
boolean |
isIncrementalSyncEnabled()
Gets the preferred synchronisation mode for this remote directory.
|
boolean |
isRolesDisabled()
Expose whether the directory has roles disabled.
|
void |
removeGroup(String name)
Removes the
group that matches the supplied name. |
void |
removeGroupAttributes(String groupName,
String attributeName)
Removes all the values for a single attribute key for a group.
|
void |
removeGroupFromGroup(String childGroup,
String parentGroup)
Removes a group as a member of a parent group.
|
void |
removeUser(String name)
Removes the
user that matches the supplied name. |
void |
removeUserAttributes(String username,
String attributeName)
Removes all the values for a single attribute key for a user.
|
void |
removeUserFromGroup(String username,
String groupName)
Removes a user as a member of a group.
|
Group |
renameGroup(String oldName,
String newName)
Renames a
group. |
User |
renameUser(String oldName,
String newName)
Renames a
user. |
void |
setAttributes(Map<String,String> attributes)
When a directory store is loaded, the attributes map will be
set by the Crowd framework.
|
void |
setDirectoryId(long directoryId)
When a directory store is loaded, the
directoryId will be set by the
crowd framework. |
void |
storeGroupAttributes(String groupName,
Map<String,Set<String>> attributes)
Adds or updates a group's attributes with the new Map of attribute values in the directory specified by the passed in
directoryId. |
void |
storeUserAttributes(String username,
Map<String,Set<String>> attributes)
Adds or updates a user's attributes with the new Map of attribute values in the directory specified by the passed in
directoryId. |
boolean |
supportsInactiveAccounts()
This implementation will store the active flag locally in the internal directory if local user status is enabled
and if the active flag cannot be persisted on the underlying remote directory.
|
boolean |
supportsNestedGroups()
Allows us to only display nested-group related UI for directories that support it.
|
boolean |
supportsPasswordExpiration()
Return true if this directory supports manually expiring passwords.
|
boolean |
supportsSettingEncryptedCredential()
If this method returns true, then calling
RemoteDirectory.updateUserCredential(String, PasswordCredential) or
RemoteDirectory.addUser(com.atlassian.crowd.model.user.UserTemplate, com.atlassian.crowd.embedded.api.PasswordCredential)
with a PasswordCredential instance where PasswordCredential.isEncryptedCredential() returns true
and the instance is not equal to PasswordCredential.NONE will succeed; otherwise, it will fail. |
void |
synchroniseCache(SynchronisationMode mode,
SynchronisationStatusManager synchronisationStatusManager)
Requests that this directory should update its cache by synchronising with the remote data.
|
void |
testConnection()
Test if a connection to the directory server can be established.
|
Group |
updateGroup(GroupTemplate group)
Updates the
group. |
protected void |
updateGroupsMembershipOnLogin(User user) |
User |
updateUser(UserTemplate user)
Updates the
user. |
protected User |
updateUserAndSetActiveFlag(User remoteUser,
User internalUser) |
void |
updateUserCredential(String username,
PasswordCredential credential)
|
User |
updateUserFromRemoteDirectory(User remoteUser) |
User |
userAuthenticated(String username) |
addAllGroups, addAllUsers, addAllUsersToGroup, addLocalGroup, findGroupByName, findUserByExternalId, findUserByName, forceRenameUser, getAllUserExternalIds, getGroupCount, getUserCount, isLocalUserStatusEnabled, removeAllGroups, removeAllUsersaddUser, countDirectMembersOfGroup, findGroupWithAttributesByName, findUserWithAttributesByName, getMemberships, getUserAvatarByName, isGroupDirectGroupMember, isUserDirectGroupMember, searchGroupRelationships, searchGroups, searchUsersclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddAllGroups, addAllUsers, addAllUsersToGroup, addLocalGroup, findGroupByName, findUserByExternalId, findUserByName, forceRenameUser, getAllUserExternalIds, getGroupCount, getUserCount, isLocalUserStatusEnabled, removeAllGroups, removeAllUsersaddUser, countDirectMembersOfGroup, findGroupWithAttributesByName, findUserWithAttributesByName, getMemberships, getUserAvatarByName, isGroupDirectGroupMember, isUserDirectGroupMember, searchGroupRelationships, searchGroups, searchUserspublic static final String INTERNAL_USER_PASSWORD
public DbCachingRemoteDirectory(RemoteDirectory remoteDirectory, InternalRemoteDirectory internalDirectory, DirectoryCacheFactory directoryCacheFactory, CacheRefresherFactory cacheRefresherFactory, AuditService auditService, AuditLogUserMapper auditLogUserMapper, String directoryName, com.atlassian.event.api.EventPublisher eventPublisher, DirectoryDao directoryDao)
public long getDirectoryId()
RemoteDirectorydirectoryId of the directory store.getDirectoryId in interface RemoteDirectorygetDirectoryId in class AbstractForwardingToRemoteDirectorydirectoryId.public void setDirectoryId(long directoryId)
RemoteDirectorydirectoryId will be set by the
crowd framework.setDirectoryId in interface RemoteDirectorysetDirectoryId in class AbstractForwardingToRemoteDirectorydirectoryId - The unique directoryId of the DirectoryImpl stored in the database.public String getDescriptiveName()
RemoteDirectorygetDescriptiveName in interface RemoteDirectorygetDescriptiveName in class AbstractForwardingToRemoteDirectorypublic void setAttributes(Map<String,String> attributes)
RemoteDirectoryThe Map is immutable and implementations are required to maintain immutability.
setAttributes in interface RemoteDirectorysetAttributes in class AbstractForwardingToRemoteDirectoryattributes - attributes map.public User authenticate(String name, PasswordCredential credential) throws UserNotFoundException, InactiveAccountException, InvalidAuthenticationException, ExpiredCredentialException, OperationFailedException
RemoteDirectoryuser with the directory store.authenticate in interface RemoteDirectoryauthenticate in class AbstractForwardingToRemoteDirectoryname - The name of the user (username).credential - The supplied credentials (password).UserNotFoundException - The user with the supplied name does not exist.InactiveAccountException - The supplied user is inactive.InvalidAuthenticationException - Authentication with the provided credentials failed.ExpiredCredentialException - The user's credentials have expired. The user must change their credentials in order to successfully authenticate.OperationFailedException - underlying directory implementation failed to execute the operation.protected User authenticateAndUpdateInternalUser(String name, PasswordCredential credential) throws UserNotFoundException, InactiveAccountException, InvalidAuthenticationException, ExpiredCredentialException, OperationFailedException
Updates user data (including groups membership) if the user exists in the internal directory. Renames user if necessary. If user does not exists tries to add the user and the user's memberships in the internal directory.
User might not exist in the internal directory yet because the user was added after the latest synchronisation. This happens for example when the remote directory uses delegated authentication, and creates users on successful authentication.
name - of the usercredential - credential of the userUserNotFoundException - if the user does not existExpiredCredentialException - if the password has expired and the user is required to change their passwordInactiveAccountException - if the user account is not activeInvalidAuthenticationException - if the user name/password combination is invalidOperationFailedException - if the operation failed for any other reasonpublic User updateUserFromRemoteDirectory(@Nonnull User remoteUser) throws OperationFailedException, UserNotFoundException
updateUserFromRemoteDirectory in interface RemoteDirectoryupdateUserFromRemoteDirectory in class AbstractForwardingToRemoteDirectoryOperationFailedExceptionUserNotFoundExceptionpublic User userAuthenticated(String username) throws OperationFailedException, UserNotFoundException, InactiveAccountException
userAuthenticated in interface RemoteDirectoryOperationFailedExceptionUserNotFoundExceptionInactiveAccountExceptionprotected User updateUserAndSetActiveFlag(User remoteUser, User internalUser) throws UserNotFoundException, InvalidUserException, OperationFailedException
protected void updateGroupsMembershipOnLogin(User user) throws OperationFailedException, UserNotFoundException
public UserWithAttributes addUser(UserTemplateWithAttributes user, PasswordCredential credential) throws InvalidUserException, InvalidCredentialException, UserAlreadyExistsException, OperationFailedException
RemoteDirectoryuser to the directory store.addUser in interface RemoteDirectoryaddUser in class AbstractForwardingToRemoteDirectoryuser - template of the user to add.credential - a password, or PasswordCredential.NONE for an account that cannot login with any passwordInvalidUserException - The supplied user is invalid.InvalidCredentialException - The supplied credential is invalid.UserAlreadyExistsException - The user already existsOperationFailedException - underlying directory implementation failed to execute the operation.RemoteDirectory.supportsSettingEncryptedCredential()public User updateUser(UserTemplate user) throws InvalidUserException, UserNotFoundException, OperationFailedException
RemoteDirectoryuser.updateUser in interface RemoteDirectoryupdateUser in class AbstractForwardingToRemoteDirectoryuser - The user to update.InvalidUserException - the supplied user is invalid.UserNotFoundException - the user does not exist in the directory store.OperationFailedException - underlying directory implementation failed to execute the operation.public void updateUserCredential(String username, PasswordCredential credential) throws UserNotFoundException, InvalidCredentialException, OperationFailedException
RemoteDirectoryupdateUserCredential in interface RemoteDirectoryupdateUserCredential in class AbstractForwardingToRemoteDirectoryusername - The name of the user (username).credential - The new credential (password).UserNotFoundException - The user does not exist.InvalidCredentialException - The supplied credential is invalid.OperationFailedException - underlying directory implementation failed to execute the operation.RemoteDirectory.supportsSettingEncryptedCredential()public User renameUser(String oldName, String newName) throws UserNotFoundException, InvalidUserException, OperationFailedException, UserAlreadyExistsException
RemoteDirectoryuser.renameUser in interface RemoteDirectoryrenameUser in class AbstractForwardingToRemoteDirectoryoldName - name of existing user.newName - desired name of user.UserNotFoundException - if the user with the existing name does not exist.InvalidUserException - if the new username is invalid.OperationFailedException - if the underlying directory implementation failed to execute the operation.UserAlreadyExistsException - if the newName already exists.public void storeUserAttributes(String username, Map<String,Set<String>> attributes) throws UserNotFoundException, OperationFailedException
RemoteDirectorydirectoryId.
The attributes map represents new or updated attributes and does not replace existing attributes unless the key of an attribute matches the key of an existing
Attributes with values of empty sets are not added (these attributes are effectively removed).
storeUserAttributes in interface RemoteDirectorystoreUserAttributes in class AbstractForwardingToRemoteDirectoryusername - name of user to update.attributes - new or updated attributes (attributes that don't need changing should not appear in this Map).UserNotFoundException - user with supplied username does not exist.OperationFailedException - underlying directory implementation failed to execute the operation.public void removeUserAttributes(String username, String attributeName) throws UserNotFoundException, OperationFailedException
RemoteDirectoryremoveUserAttributes in interface RemoteDirectoryremoveUserAttributes in class AbstractForwardingToRemoteDirectoryusername - name of the user to update.attributeName - name of attribute to remove.UserNotFoundException - user with supplied username does not exist.OperationFailedException - underlying directory implementation failed to execute the operation.public void removeUser(String name) throws UserNotFoundException, OperationFailedException
RemoteDirectoryuser that matches the supplied name.removeUser in interface RemoteDirectoryremoveUser in class AbstractForwardingToRemoteDirectoryname - The name of the user (username).UserNotFoundException - The user does not exist.OperationFailedException - underlying directory implementation failed to execute the operation.public Group addGroup(GroupTemplate group) throws InvalidGroupException, OperationFailedException
RemoteDirectorygroup to the directory store.addGroup in interface RemoteDirectoryaddGroup in class AbstractForwardingToRemoteDirectorygroup - template of the group to add.InvalidGroupException - The supplied group is invalid or it already exists in the directory.OperationFailedException - underlying directory implementation failed to execute the operation.public Group updateGroup(GroupTemplate group) throws InvalidGroupException, GroupNotFoundException, OperationFailedException, ReadOnlyGroupException
RemoteDirectorygroup.updateGroup in interface RemoteDirectoryupdateGroup in class AbstractForwardingToRemoteDirectorygroup - The group to update.InvalidGroupException - the supplied group is invalid.GroupNotFoundException - the group does not exist in the directory store.OperationFailedException - underlying directory implementation failed to execute the operation.ReadOnlyGroupException - the group is read-onlypublic Group renameGroup(String oldName, String newName) throws GroupNotFoundException, InvalidGroupException
RemoteDirectorygroup.renameGroup in interface RemoteDirectoryrenameGroup in class AbstractForwardingToRemoteDirectoryoldName - name of existing group.newName - desired name of group.GroupNotFoundException - if the group with the existing name does not exist.InvalidGroupException - if the new group name is invalid or already exists in the directory.public void storeGroupAttributes(String groupName, Map<String,Set<String>> attributes) throws GroupNotFoundException, OperationFailedException
RemoteDirectorydirectoryId.
The attributes map represents new or updated attributes and does not replace existing attributes unless the key of an attribute matches the key of an existing
Attributes with values of empty sets are not added (these attributes are effectively removed).
storeGroupAttributes in interface RemoteDirectorystoreGroupAttributes in class AbstractForwardingToRemoteDirectorygroupName - name of group to update.attributes - new or updated attributes (attributes that don't need changing should not appear in this Map).GroupNotFoundException - group with supplied groupName does not exist.OperationFailedException - underlying directory implementation failed to execute the operation.public void removeGroupAttributes(String groupName, String attributeName) throws GroupNotFoundException, OperationFailedException
RemoteDirectoryremoveGroupAttributes in interface RemoteDirectoryremoveGroupAttributes in class AbstractForwardingToRemoteDirectorygroupName - name of the group to update.attributeName - name of attribute to remove.GroupNotFoundException - group with supplied groupName does not exist.OperationFailedException - underlying directory implementation failed to execute the operation.public void removeGroup(String name) throws GroupNotFoundException, OperationFailedException, ReadOnlyGroupException
RemoteDirectorygroup that matches the supplied name.removeGroup in interface RemoteDirectoryremoveGroup in class AbstractForwardingToRemoteDirectoryname - The name of the group.GroupNotFoundException - The group does not exist.OperationFailedException - underlying directory implementation failed to execute the operation.ReadOnlyGroupException - if the group is read-only and not allowed to be deleted.public void addUserToGroup(String username, String groupName) throws GroupNotFoundException, UserNotFoundException, OperationFailedException, ReadOnlyGroupException, MembershipAlreadyExistsException
RemoteDirectorychildGroup will
appear as members of parentGroup to querying applications.addUserToGroup in interface RemoteDirectoryaddUserToGroup in class AbstractForwardingToRemoteDirectoryusername - The user that will become a member of groupNamegroupName - The group that will gain a new member.GroupNotFoundException - If the group cannot be found.UserNotFoundException - If the user cannot be found.OperationFailedException - underlying directory implementation failed to execute the operation.ReadOnlyGroupException - If the group is read-onlyMembershipAlreadyExistsException - if the user is already a member of the grouppublic void addGroupToGroup(String childGroup, String parentGroup) throws GroupNotFoundException, InvalidMembershipException, OperationFailedException, ReadOnlyGroupException, MembershipAlreadyExistsException
RemoteDirectoryaddGroupToGroup in interface RemoteDirectoryaddGroupToGroup in class AbstractForwardingToRemoteDirectorychildGroup - The group that will become a member of parentGroupparentGroup - The group that will gain a new memberGroupNotFoundException - One or both of the groups cannot be found.InvalidMembershipException - if the childGroup and parentGroup exist but are of different GroupTypes.OperationFailedException - underlying directory implementation failed to execute the operation.ReadOnlyGroupException - if either of the groups are read-onlyMembershipAlreadyExistsException - if the child group is already a child of the parent grouppublic void removeUserFromGroup(String username, String groupName) throws GroupNotFoundException, UserNotFoundException, MembershipNotFoundException, OperationFailedException, ReadOnlyGroupException
RemoteDirectoryremoveUserFromGroup in interface RemoteDirectoryremoveUserFromGroup in class AbstractForwardingToRemoteDirectoryusername - The user that will be removed from parentGroupgroupName - The group that will lose the member.GroupNotFoundException - If the group cannot be found.UserNotFoundException - If the user cannot be found.MembershipNotFoundException - if the user is not a direct member of the group.OperationFailedException - underlying directory implementation failed to execute the operation.ReadOnlyGroupException - if the group is read-onlypublic void removeGroupFromGroup(String childGroup, String parentGroup) throws GroupNotFoundException, InvalidMembershipException, MembershipNotFoundException, OperationFailedException, ReadOnlyGroupException
RemoteDirectoryremoveGroupFromGroup in interface RemoteDirectoryremoveGroupFromGroup in class AbstractForwardingToRemoteDirectorychildGroup - The group that will be removed from parentGroupparentGroup - The group that will lose the member.GroupNotFoundException - One or both of the groups cannot be found.InvalidMembershipException - if the childGroup and parentGroup exist but are of different GroupTypes.MembershipNotFoundException - if the childGroup is not a direct member of the parentGroup.OperationFailedException - underlying directory implementation failed to execute the operation.ReadOnlyGroupException - if the groups are read-onlypublic void testConnection()
throws OperationFailedException
RemoteDirectorytestConnection in interface RemoteDirectorytestConnection in class AbstractForwardingToRemoteDirectoryOperationFailedException - underlying directory implementation failed to execute the operation.public boolean supportsInactiveAccounts()
supportsInactiveAccounts in interface RemoteDirectorysupportsInactiveAccounts in class AbstractForwardingToRemoteDirectorypublic boolean supportsNestedGroups()
RemoteDirectorysupportsNestedGroups in interface RemoteDirectorysupportsNestedGroups in class AbstractForwardingToRemoteDirectorypublic boolean supportsPasswordExpiration()
RemoteDirectorysupportsPasswordExpiration in interface RemoteDirectorysupportsPasswordExpiration in class AbstractForwardingToRemoteDirectorypublic boolean supportsSettingEncryptedCredential()
RemoteDirectoryRemoteDirectory.updateUserCredential(String, PasswordCredential) or
RemoteDirectory.addUser(com.atlassian.crowd.model.user.UserTemplate, com.atlassian.crowd.embedded.api.PasswordCredential)
with a PasswordCredential instance where PasswordCredential.isEncryptedCredential() returns true
and the instance is not equal to PasswordCredential.NONE will succeed; otherwise, it will fail.supportsSettingEncryptedCredential in interface RemoteDirectorysupportsSettingEncryptedCredential in class AbstractForwardingToRemoteDirectorypublic boolean isRolesDisabled()
RemoteDirectoryisRolesDisabled in interface RemoteDirectoryisRolesDisabled in class AbstractForwardingToRemoteDirectorypublic Set<String> getValues(String name)
AttributesgetValues in interface AttributesgetValues in class AbstractForwardingToRemoteDirectoryname - the key to retrieve the values forpublic String getValue(String name)
Attributesnull if there is no value.getValue in interface AttributesgetValue in class AbstractForwardingToRemoteDirectoryname - the key to retrieve the value fornull if there is no valuepublic boolean isEmpty()
isEmpty in interface AttributesisEmpty in class AbstractForwardingToRemoteDirectorytrue if there are no attributespublic Set<String> getKeys()
AttributesgetKeys in interface AttributesgetKeys in class AbstractForwardingToRemoteDirectorypublic boolean isIncrementalSyncEnabled()
SynchronisableDirectoryGets the preferred synchronisation mode for this remote directory.
Note: some directory implementation don't support incremental sync and will ignore this preference.
isIncrementalSyncEnabled in interface SynchronisableDirectorytrue if incremental sync is preferred.public void synchroniseCache(SynchronisationMode mode, SynchronisationStatusManager synchronisationStatusManager) throws OperationFailedException
SynchronisableDirectorysynchroniseCache in interface SynchronisableDirectorymode - synchronisation modesynchronisationStatusManager - listener for synchronisation status change notificationsOperationFailedException - underlying directory implementation failed to execute the operation.public RemoteDirectory getAuthoritativeDirectory()
getAuthoritativeDirectory in interface RemoteDirectorygetAuthoritativeDirectory in class AbstractForwardingToRemoteDirectorypublic void expireAllPasswords()
throws OperationFailedException
RemoteDirectoryUserConstants.REQUIRES_PASSWORD_CHANGE attribute to true for
all users in the directory using bulk operationsexpireAllPasswords in interface RemoteDirectoryexpireAllPasswords in class AbstractForwardingToRemoteDirectoryOperationFailedExceptionprotected InternalRemoteDirectory getDelegate()
getDelegate in class AbstractForwardingToInternalRemoteDirectoryCopyright © 2019 Atlassian. All rights reserved.