public abstract class AbstractInternalDirectory extends Object implements InternalRemoteDirectory
InternalDirectory
and CachingDirectory
.Constructor and Description |
---|
AbstractInternalDirectory(InternalDirectoryUtils internalDirectoryUtils,
PasswordEncoderFactory passwordEncoderFactory,
DirectoryDao directoryDao,
UserDao userDao,
GroupDao groupDao,
MembershipDao membershipDao,
TombstoneDao tombstoneDao,
PasswordConstraintsLoader passwordConstraints) |
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.
|
abstract Group |
addLocalGroup(GroupTemplate group)
Adds a "local" group to the directory.
|
abstract 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 static Map<String,Set<String>> |
calculatePostPasswordUpdateAttributes()
Generate the list of default attributes and values relating to passwords, for use when creating or resetting a password
|
BoundedCount |
countDirectMembersOfGroup(String groupName,
int querySizeHint)
Count the direct members of a group in the remote directory.
|
protected long |
currentPrincipalInvalidPasswordAttempts(UserWithAttributes user) |
protected PasswordCredential |
encryptedCredential(PasswordCredential passwordCredential) |
void |
expireAllPasswords()
Sets the
UserConstants.REQUIRES_PASSWORD_CHANGE attribute to true for
all users in the directory using bulk operations |
InternalDirectoryGroup |
findGroupByName(String name)
Finds the
group that matches the supplied name . |
GroupWithAttributes |
findGroupWithAttributesByName(String name)
Finds the
group that matches the supplied name . |
TimestampedUser |
findUserByExternalId(String externalId)
Finds the user that matches the supplied
externalId . |
TimestampedUser |
findUserByName(String name)
Finds the
user that matches the supplied name . |
UserWithAttributes |
findUserWithAttributesByName(String name)
Finds the
user that matches the supplied name . |
User |
forceRenameUser(User oldUser,
String newName)
Forces a rename on the given user in this directory.
|
Set<String> |
getAllUserExternalIds()
Retrieves all users externalIds found in this directory.
|
RemoteDirectory |
getAuthoritativeDirectory() |
String |
getDescriptiveName()
Returns a descriptive name for the type of directory.
|
long |
getDirectoryId()
Gets the internal unique
directoryId of the directory store. |
protected PasswordEncoder |
getEncoder() |
Set<String> |
getKeys()
Gets all the keys of the attributes.
|
Iterable<Membership> |
getMemberships()
Get an iterable view of the available group memberships.
|
protected Set<PasswordConstraint> |
getPasswordConstraints() |
AvatarReference |
getUserAvatarByName(String username,
int sizeHint)
Return an avatar, if available, for the named user.
|
long |
getUserCount() |
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 |
isGroupDirectGroupMember(String childGroup,
String parentGroup)
Determines if a group is a direct member of another group.
|
boolean |
isRolesDisabled()
Expose whether the directory has roles disabled.
|
boolean |
isUserDirectGroupMember(String username,
String groupName)
Determines if a user is a direct member of a group.
|
BatchResult<String> |
removeAllGroups(Set<String> groupNames)
Removes all groups from the directory.
|
BatchResult<String> |
removeAllUsers(Set<String> userNames)
Removes all users from the directory.
|
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 . |
protected boolean |
requiresPasswordChange(UserWithAttributes user) |
<T> List<T> |
searchGroupRelationships(MembershipQuery<T> query)
Searches for membership information.
|
<T> List<T> |
searchGroups(EntityQuery<T> query)
Searches for
groups that match the supplied query criteria. |
<T> List<T> |
searchUsers(EntityQuery<T> query)
Searches for
users that match the supplied query criteria. |
void |
setAttributes(Map<String,String> attributes)
Called by the
DirectoryInstanceLoader after
constructing an InternalDirectory. |
void |
setDirectoryId(long id)
Called by the
DirectoryInstanceLoader after
constructing an InternalDirectory. |
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()
Internal directories always support inactive accounts.
|
boolean |
supportsNestedGroups()
Allows us to only display nested-group related UI for directories that support it.
|
boolean |
supportsPasswordExpiration()
Internal Directories always support expiring passwords
|
boolean |
supportsSettingEncryptedCredential()
Internal directories always support setting passwords by hash.
|
void |
testConnection()
Does nothing, connection is determined by the ability to communicate with the database.
|
Group |
updateGroup(GroupTemplate group)
Updates the
group . |
void |
updateUserCredential(String name,
PasswordCredential newCredential)
|
User |
userAuthenticated(String username) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addAllGroups, addAllUsers, addAllUsersToGroup, isLocalUserStatusEnabled
addUser, updateUser, updateUserFromRemoteDirectory
public static final String DESCRIPTIVE_NAME
public static final String ATTRIBUTE_PASSWORD_REGEX
public static final String ATTRIBUTE_PASSWORD_COMPLEXITY_MESSAGE
public static final String ATTRIBUTE_PASSWORD_MAX_ATTEMPTS
public static final String ATTRIBUTE_PASSWORD_HISTORY_COUNT
public static final String ATTRIBUTE_USER_ENCRYPTION_METHOD
public static final String ATTRIBUTE_PASSWORD_MAX_CHANGE_TIME
public static final String ATTRIBUTE_PASSWORD_EXPIRATION_NOTIFICATION_PERIODS
public static final String ATTRIBUTE_PASSWORD_MINIMUM_LENGTH
public static final String ATTRIBUTE_PASSWORD_MINIMUM_SCORE
PasswordScore.getRanking()
.protected long directoryId
protected AttributeValuesHolder attributes
protected final PasswordEncoderFactory passwordEncoderFactory
protected final DirectoryDao directoryDao
protected final UserDao userDao
protected final GroupDao groupDao
protected final MembershipDao membershipDao
protected final TombstoneDao tombstoneDao
protected final InternalDirectoryUtils internalDirectoryUtils
public AbstractInternalDirectory(InternalDirectoryUtils internalDirectoryUtils, PasswordEncoderFactory passwordEncoderFactory, DirectoryDao directoryDao, UserDao userDao, GroupDao groupDao, MembershipDao membershipDao, TombstoneDao tombstoneDao, PasswordConstraintsLoader passwordConstraints)
public long getDirectoryId()
RemoteDirectory
directoryId
of the directory store.getDirectoryId
in interface RemoteDirectory
directoryId
.public void setDirectoryId(long id)
DirectoryInstanceLoader
after
constructing an InternalDirectory.setDirectoryId
in interface RemoteDirectory
id
- The unique id
of the Directory stored in the database.public void setAttributes(Map<String,String> attributes)
DirectoryInstanceLoader
after
constructing an InternalDirectory.setAttributes
in interface RemoteDirectory
attributes
- attributes map.public Set<String> getValues(String name)
Attributes
getValues
in interface Attributes
name
- the key to retrieve the values forpublic String getValue(String name)
Attributes
null
if there is no value.getValue
in interface Attributes
name
- the key to retrieve the value fornull
if there is no valuepublic Set<String> getKeys()
Attributes
getKeys
in interface Attributes
public boolean isEmpty()
isEmpty
in interface Attributes
true
if there are no attributespublic String getDescriptiveName()
RemoteDirectory
getDescriptiveName
in interface RemoteDirectory
public TimestampedUser findUserByName(String name) throws UserNotFoundException
RemoteDirectory
user
that matches the supplied name
.findUserByName
in interface InternalRemoteDirectory
findUserByName
in interface RemoteDirectory
name
- the name of the user (username).TimestampedUser
entity.UserNotFoundException
- a user with the supplied name does not exist.public TimestampedUser findUserByExternalId(String externalId) throws UserNotFoundException
RemoteDirectory
externalId
.
This is an optional method that may not be implemented on all directory types.
Currently it is implemented for LDAP and Internal directories but not Crowd directories.findUserByExternalId
in interface InternalRemoteDirectory
findUserByExternalId
in interface RemoteDirectory
externalId
- the externalId of the userTimestampedUser
entity.UserNotFoundException
- a user with the supplied externalId does not exist.RemoteDirectory.findUserByName(String)
public UserWithAttributes findUserWithAttributesByName(String name) throws UserNotFoundException
RemoteDirectory
user
that matches the supplied name
.findUserWithAttributesByName
in interface RemoteDirectory
name
- the name of the user (username).UserNotFoundException
- a user with the supplied name does not exist.public User authenticate(String name, PasswordCredential credential) throws InactiveAccountException, InvalidAuthenticationException, ExpiredCredentialException, UserNotFoundException
RemoteDirectory
user
with the directory store.authenticate
in interface RemoteDirectory
name
- The name of the user (username).credential
- The supplied credentials (password).InactiveAccountException
- The supplied user is inactive.InvalidAuthenticationException
- Authentication with the provided credentials failed OR the user has exceeded the maximum number of failed authentication attempts.UserNotFoundException
- The user wth the supplied name does not exist.ExpiredCredentialException
- The user's credentials have expired. The user must change their credentials in order to successfully authenticate.public User userAuthenticated(String username) throws OperationFailedException, UserNotFoundException, InactiveAccountException
userAuthenticated
in interface RemoteDirectory
OperationFailedException
UserNotFoundException
InactiveAccountException
protected long currentPrincipalInvalidPasswordAttempts(UserWithAttributes user)
user
- user with attributes.protected boolean requiresPasswordChange(UserWithAttributes user)
user
- user with attributes.true
if the requires password change attribute on the user is set to true, or if
the password last changed attribute on the user exceeds the password max change time attribute on the
directory (ie. password timeout).public abstract UserWithAttributes addUser(UserTemplateWithAttributes user, PasswordCredential credential) throws InvalidCredentialException, InvalidUserException, UserAlreadyExistsException, OperationFailedException
RemoteDirectory
user
to the directory store.addUser
in interface RemoteDirectory
user
- template of the user to add.credential
- a password, or PasswordCredential.NONE
for an account that cannot login with any passwordInvalidCredentialException
- The supplied credential is invalid.InvalidUserException
- The supplied user is invalid.UserAlreadyExistsException
- The user already existsOperationFailedException
- underlying directory implementation failed to execute the operation.RemoteDirectory.supportsSettingEncryptedCredential()
protected PasswordCredential encryptedCredential(PasswordCredential passwordCredential)
protected PasswordEncoder getEncoder()
public void updateUserCredential(String name, PasswordCredential newCredential) throws InvalidCredentialException, UserNotFoundException
RemoteDirectory
updateUserCredential
in interface RemoteDirectory
name
- The name of the user (username).newCredential
- The new credential (password).InvalidCredentialException
- The supplied credential is invalid.UserNotFoundException
- The user does not exist.RemoteDirectory.supportsSettingEncryptedCredential()
protected static Map<String,Set<String>> calculatePostPasswordUpdateAttributes()
public User renameUser(String oldName, String newName) throws InvalidUserException, UserNotFoundException, UserAlreadyExistsException
RemoteDirectory
user
.renameUser
in interface RemoteDirectory
oldName
- name of existing user.newName
- desired name of user.InvalidUserException
- if the new username is invalid.UserNotFoundException
- if the user with the existing name does not exist.UserAlreadyExistsException
- if the newName already exists.public User forceRenameUser(@Nonnull User oldUser, @Nonnull String newName) throws UserNotFoundException
InternalRemoteDirectory
RemoteDirectory.renameUser(String, String)
, except it will still do the rename even if there is an
existing user under the newName. In this case, it will first rename that existing user to a name that is known
not to exist in this directory.forceRenameUser
in interface InternalRemoteDirectory
oldUser
- the existing user.newName
- desired name of user.UserNotFoundException
- if the "oldUser" does not exist.RemoteDirectory.renameUser(String, String)
protected final Set<PasswordConstraint> getPasswordConstraints()
@Nonnull public Set<String> getAllUserExternalIds() throws OperationFailedException
InternalRemoteDirectory
getAllUserExternalIds
in interface InternalRemoteDirectory
OperationFailedException
- underlying directory implementation failed to execute the operation.public long getUserCount() throws OperationFailedException
getUserCount
in interface InternalRemoteDirectory
OperationFailedException
- underlying directory implementation failed to execute the operation.public void storeUserAttributes(String username, Map<String,Set<String>> attributes) throws UserNotFoundException, OperationFailedException
RemoteDirectory
directoryId
.
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 RemoteDirectory
username
- 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
RemoteDirectory
removeUserAttributes
in interface RemoteDirectory
username
- name of the user to update.attributeName
- name of attribute to remove.UserNotFoundException
- user with supplied username does not exist.public void removeUser(String name) throws UserNotFoundException
RemoteDirectory
user
that matches the supplied name
.removeUser
in interface RemoteDirectory
name
- The name of the user (username).UserNotFoundException
- The user does not exist.public BatchResult<String> removeAllUsers(Set<String> userNames)
InternalRemoteDirectory
If a user with the supplied username does not exist in the directory, the username will be ignored.
removeAllUsers
in interface InternalRemoteDirectory
userNames
- usernames of users to remove.public BatchResult<String> removeAllGroups(Set<String> groupNames)
InternalRemoteDirectory
If a group with the supplied group name does not exist in the directory, the group name will be ignored.
removeAllGroups
in interface InternalRemoteDirectory
groupNames
- names of groups to remove.public <T> List<T> searchUsers(EntityQuery<T> query)
RemoteDirectory
users
that match the supplied query criteria.
The users will be returned in a stable order including across pagination boundaries (excluding modification).
searchUsers
in interface RemoteDirectory
query
- EntityQuery for Entity.USER.List<User
>
or List<String
>
of users/usernames
matching the search criteria. An empty List
will be returned
if no users matching the criteria are found.public InternalDirectoryGroup findGroupByName(String name) throws GroupNotFoundException
RemoteDirectory
group
that matches the supplied name
.findGroupByName
in interface InternalRemoteDirectory
findGroupByName
in interface RemoteDirectory
name
- the name of the group.InternalDirectoryGroup
entity.GroupNotFoundException
- a group with the supplied name does not exist.public GroupWithAttributes findGroupWithAttributesByName(String name) throws GroupNotFoundException
RemoteDirectory
group
that matches the supplied name
.findGroupWithAttributesByName
in interface RemoteDirectory
name
- the name of the group.GroupNotFoundException
- a group with the supplied name does not exist.public Group addGroup(GroupTemplate group) throws InvalidGroupException, OperationFailedException
RemoteDirectory
group
to the directory store.addGroup
in interface RemoteDirectory
group
- 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 abstract Group addLocalGroup(GroupTemplate group) throws InvalidGroupException, OperationFailedException
InternalRemoteDirectory
This method can be used to store groups that aren't clones of "external" groups. For example, if an LDAP directory is cloned in an internal directory, it's possible to define "local" groups that exist internally but not in LDAP.
This functionality was added to meet the functionality that Confluence provided.
addLocalGroup
in interface InternalRemoteDirectory
group
- template of the group to add.InvalidGroupException
- The supplied group is invalid.OperationFailedException
- underlying directory implementation failed to execute the operation.public Group updateGroup(GroupTemplate group) throws InvalidGroupException, GroupNotFoundException
RemoteDirectory
group
.updateGroup
in interface RemoteDirectory
group
- The group to update.InvalidGroupException
- the supplied group is invalid.GroupNotFoundException
- the group does not exist in the directory store.public Group renameGroup(String oldName, String newName) throws InvalidGroupException, GroupNotFoundException
RemoteDirectory
group
.renameGroup
in interface RemoteDirectory
oldName
- name of existing group.newName
- desired name of group.InvalidGroupException
- if the new group name is invalid or already exists in the directory.GroupNotFoundException
- if the group with the existing name does not exist.public void storeGroupAttributes(String groupName, Map<String,Set<String>> attributes) throws GroupNotFoundException
RemoteDirectory
directoryId
.
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 RemoteDirectory
groupName
- 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.public void removeGroupAttributes(String groupName, String attributeName) throws GroupNotFoundException
RemoteDirectory
removeGroupAttributes
in interface RemoteDirectory
groupName
- name of the group to update.attributeName
- name of attribute to remove.GroupNotFoundException
- group with supplied groupName does not exist.public void removeGroup(String name) throws GroupNotFoundException
RemoteDirectory
group
that matches the supplied name
.removeGroup
in interface RemoteDirectory
name
- The name of the group.GroupNotFoundException
- The group does not exist.public <T> List<T> searchGroups(EntityQuery<T> query)
RemoteDirectory
groups
that match the supplied query criteria.
The groups will be returned in a stable order including across pagination boundaries (excluding modification).
searchGroups
in interface RemoteDirectory
query
- EntityQuery for Entity.GROUP.List<Group>
or List<String>
of groups/groupnames
matching the search criteria. An empty List
will be returned
if no groups matching the criteria are found.public boolean isUserDirectGroupMember(String username, String groupName)
RemoteDirectory
isUserDirectGroupMember
in interface RemoteDirectory
username
- name of user.groupName
- name of group.true
iff the user is a direct member of the group.public boolean isGroupDirectGroupMember(String childGroup, String parentGroup)
RemoteDirectory
isGroupDirectGroupMember
in interface RemoteDirectory
childGroup
- name of child group.parentGroup
- name of parent group.true
iff the childGroup is a direct member of the parentGroup.public void addUserToGroup(String username, String groupName) throws UserNotFoundException, GroupNotFoundException, MembershipAlreadyExistsException
RemoteDirectory
childGroup
will
appear as members of parentGroup
to querying applications.addUserToGroup
in interface RemoteDirectory
username
- The user that will become a member of groupName
groupName
- The group that will gain a new member.UserNotFoundException
- If the user cannot be found.GroupNotFoundException
- If the group cannot be found.MembershipAlreadyExistsException
- if the user is already a member of the grouppublic void addGroupToGroup(String childGroup, String parentGroup) throws InvalidMembershipException, GroupNotFoundException, MembershipAlreadyExistsException
RemoteDirectory
addGroupToGroup
in interface RemoteDirectory
childGroup
- The group that will become a member of parentGroup
parentGroup
- The group that will gain a new memberInvalidMembershipException
- if the childGroup and parentGroup exist but are of different GroupTypes.GroupNotFoundException
- One or both of the groups cannot be found.MembershipAlreadyExistsException
- if the child group is already a child of the parent grouppublic void removeUserFromGroup(String username, String groupName) throws MembershipNotFoundException, GroupNotFoundException, UserNotFoundException
RemoteDirectory
removeUserFromGroup
in interface RemoteDirectory
username
- The user that will be removed from parentGroup
groupName
- The group that will lose the member.MembershipNotFoundException
- if the user is not a direct member of the group.GroupNotFoundException
- If the group cannot be found.UserNotFoundException
- If the user cannot be found.public void removeGroupFromGroup(String childGroup, String parentGroup) throws InvalidMembershipException, MembershipNotFoundException, GroupNotFoundException
RemoteDirectory
removeGroupFromGroup
in interface RemoteDirectory
childGroup
- The group that will be removed from parentGroup
parentGroup
- The group that will lose the member.InvalidMembershipException
- if the childGroup and parentGroup exist but are of different GroupTypes.MembershipNotFoundException
- if the childGroup is not a direct member of the parentGroup.GroupNotFoundException
- One or both of the groups cannot be found.public BoundedCount countDirectMembersOfGroup(String groupName, int querySizeHint)
RemoteDirectory
countDirectMembersOfGroup
in interface RemoteDirectory
groupName
- the name of the group to search forquerySizeHint
- hinting at the maximum number of memberships that should be counted. The directory that
implements this may choose to count less or more. This is a user provided suggestion for potential efficiency.public <T> List<T> searchGroupRelationships(MembershipQuery<T> query)
RemoteDirectory
searchGroupRelationships
in interface RemoteDirectory
query
- query for memberships.public void testConnection() throws OperationFailedException
testConnection
in interface RemoteDirectory
OperationFailedException
- underlying directory implementation failed to execute the operation.public boolean supportsInactiveAccounts()
supportsInactiveAccounts
in interface RemoteDirectory
true
, alwayspublic boolean supportsNestedGroups()
RemoteDirectory
supportsNestedGroups
in interface RemoteDirectory
true
because Internal Directories support nested groups as of Crowd 2.0.public boolean supportsPasswordExpiration()
supportsPasswordExpiration
in interface RemoteDirectory
true
, always.public boolean supportsSettingEncryptedCredential()
supportsSettingEncryptedCredential
in interface RemoteDirectory
true
, always.public boolean isRolesDisabled()
RemoteDirectory
isRolesDisabled
in interface RemoteDirectory
public Iterable<Membership> getMemberships() throws OperationFailedException
RemoteDirectory
Get an iterable view of the available group memberships. This may be implemented as a single remote call or separate calls, depending on the directory.
If there is a failure in the underlying retrieval, the iterator may throw
Membership.MembershipIterationException
at runtime.
If the directory does not have a bulk call interface then a typical implementation would be:
return new DirectoryMembershipsIterable(this);
getMemberships
in interface RemoteDirectory
OperationFailedException
- if the underlying directory implementation failed to execute the operationpublic RemoteDirectory getAuthoritativeDirectory()
getAuthoritativeDirectory
in interface RemoteDirectory
public void expireAllPasswords()
RemoteDirectory
UserConstants.REQUIRES_PASSWORD_CHANGE
attribute to true for
all users in the directory using bulk operationsexpireAllPasswords
in interface RemoteDirectory
public AvatarReference getUserAvatarByName(String username, int sizeHint) throws OperationFailedException
RemoteDirectory
getUserAvatarByName
in interface RemoteDirectory
sizeHint
- a hint in pixels for the context in which this will be usednull
if none is availableOperationFailedException
Copyright © 2019 Atlassian. All rights reserved.