com.atlassian.crowd.integration.directory.cache
Class CachingLDAPDirectory

java.lang.Object
  extended by com.atlassian.crowd.integration.directory.cache.CachingLDAPDirectory
All Implemented Interfaces:
LDAPDirectory, RemoteDirectory, AttributeAware

public class CachingLDAPDirectory
extends java.lang.Object
implements LDAPDirectory


Constructor Summary
CachingLDAPDirectory(LDAPDirectory directory, DirectoryCache directoryCache)
           
 
Method Summary
 Group addGroup(GroupTemplate group)
          Adds a group to the directory store.
 void addGroupToGroup(java.lang.String parentGroup, java.lang.String childGroup)
          Adds a group as a member of a parent group.
 User addUser(UserTemplate user, PasswordCredential credential)
          Adds a user to the directory store.
 void addUserToGroup(java.lang.String username, java.lang.String groupName)
          Adds a user as a member of a group.
 User authenticate(java.lang.String name, PasswordCredential credential)
          Authenticates a user with the directory store.
protected  java.util.List<LDAPGroupWithAttributes> findAllGroups()
           
protected  java.util.List<LDAPGroupWithAttributes> findAllGroupsFromDirectory()
           
protected  java.util.List<LDAPUserWithAttributes> findAllUsers()
           
protected  java.util.List<LDAPUserWithAttributes> findAllUsersFromDirectory()
           
<T extends LDAPDirectoryEntity>
T
findEntityByDN(java.lang.String dn, java.lang.Class<T> entityClass)
          Finds a directory entity (principal, group or role) by their distinguished name.
protected  EntityIdentifier findEntityIdentifierFromDN(java.lang.String dn, EntityType entityType)
           
 Group findGroupByName(java.lang.String name)
          Finds the group that matches the supplied name.
 Group findGroupByNameFromServerAndCacheResult(java.lang.String name)
           
protected  java.util.List<LDAPGroupWithAttributes> findGroupMembershipsOfUser(java.lang.String username, int startIndex, int maxResults)
           
 GroupWithAttributes findGroupWithAttributesByName(java.lang.String name)
          Finds the group that matches the supplied name.
 User findUserByName(java.lang.String name)
          Finds the user that matches the supplied name.
 UserWithAttributes findUserWithAttributesByName(java.lang.String name)
          Finds the user that matches the supplied name.
 java.lang.String getAttribute(java.lang.String name)
           
 java.util.Set<java.lang.String> getAttributeNames()
           
 java.util.List<java.lang.String> getAttributes(java.lang.String name)
           
 java.lang.String getDescriptiveName()
          Returns a descriptive name for the type of directory.
 long getDirectoryId()
          Gets the internal unique directoryId of the directory store.
 boolean hasAttribute(java.lang.String name)
           
protected  boolean isFindAllEntities(EntityQuery query)
           
 boolean isGroupDirectGroupMember(java.lang.String childGroup, java.lang.String parentGroup)
          Determines if a group is a direct member of another group.
 boolean isUserDirectGroupMember(java.lang.String userName, java.lang.String groupName)
          Determines if a user is a direct member of a group.
 void removeGroup(java.lang.String name)
          Removes the group that matches the supplied name.
 void removeGroupAttributes(java.lang.String groupName, java.lang.String attributeName)
          Removes all the values for a single attribute key for a group.
 void removeGroupFromGroup(java.lang.String parentGroup, java.lang.String childGroup)
          Removes a group as a member of a parent group.
 void removeUser(java.lang.String name)
          Removes the user that matches the supplied name.
 void removeUserAttributes(java.lang.String username, java.lang.String attributeName)
          Removes all the values for a single attribute key for a user.
 void removeUserFromGroup(java.lang.String username, java.lang.String groupName)
          Removes a user as a member of a group.
 Group renameGroup(java.lang.String oldName, java.lang.String newName)
          Renames a group.
 User renameUser(java.lang.String oldName, java.lang.String newName)
          Renames a user.
 java.util.List searchGroupRelationships(MembershipQuery query)
          Searches for membership information.
 java.util.List searchGroups(EntityQuery query)
          Searches for groups that match the supplied query criteria.
 java.util.List searchUsers(EntityQuery query)
          Searches for users that match the supplied query criteria.
 void setAttributes(java.util.Map<java.lang.String,java.lang.String> attributes)
          When a directory store is loaded, the attributes map will be set by the Crowd framework.
 void setDirectoryId(long ID)
          When a directory store is loaded, the directoryId will be set by the crowd framework.
 void storeGroupAttributes(java.lang.String groupName, java.util.Map<java.lang.String,java.util.List<java.lang.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(java.lang.String username, java.util.Map<java.lang.String,java.util.List<java.lang.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 supportsNestedGroups()
          Allows us to only display nested-group related UI for directories that support it.
 void testConnection()
          Test if a connection to the directory server can be established.
 Group updateGroup(GroupTemplate group)
          Updates the group.
 User updateUser(UserTemplate user)
          Updates the user.
 void updateUserCredential(java.lang.String name, PasswordCredential credential)
          Updates the password for a user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingLDAPDirectory

public CachingLDAPDirectory(LDAPDirectory directory,
                            DirectoryCache directoryCache)
Method Detail

getDirectoryId

public long getDirectoryId()
Description copied from interface: RemoteDirectory
Gets the internal unique directoryId of the directory store.

Specified by:
getDirectoryId in interface RemoteDirectory
Returns:
The directoryId.

setDirectoryId

public void setDirectoryId(long ID)
Description copied from interface: RemoteDirectory
When a directory store is loaded, the directoryId will be set by the crowd framework.

Specified by:
setDirectoryId in interface RemoteDirectory
Parameters:
ID - The unique directoryId of the Directory stored in the database.

getDescriptiveName

public java.lang.String getDescriptiveName()
Description copied from interface: RemoteDirectory
Returns a descriptive name for the type of directory.

Specified by:
getDescriptiveName in interface RemoteDirectory
Returns:
descriptive name.

setAttributes

public void setAttributes(java.util.Map<java.lang.String,java.lang.String> attributes)
Description copied from interface: RemoteDirectory
When a directory store is loaded, the attributes map will be set by the Crowd framework. Implementations may store a reference to this map in order to implement the AttributeAware

The Map is immutable and implementations are required to maintain immutability.

Specified by:
setAttributes in interface RemoteDirectory
Parameters:
attributes - attributes map.

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Specified by:
getAttribute in interface AttributeAware
Parameters:
name - attribute name.
Returns:
single attribute value or null if the attribute with the given name does not exist. If multiple attribute values exist, any one could be returned.

getAttributeNames

public java.util.Set<java.lang.String> getAttributeNames()
Specified by:
getAttributeNames in interface AttributeAware
Returns:
set of attribute names.

getAttributes

public java.util.List<java.lang.String> getAttributes(java.lang.String name)
Specified by:
getAttributes in interface AttributeAware
Parameters:
name - attribute name.
Returns:
collection of attribute values or an empty list if the attribute with the given name does not exist.

hasAttribute

public boolean hasAttribute(java.lang.String name)
Specified by:
hasAttribute in interface AttributeAware
Parameters:
name - attribute name.
Returns:
true if an only if the user has an attribute with the supplied name and has one or more values.

testConnection

public void testConnection()
                    throws DirectoryAccessException
Description copied from interface: RemoteDirectory
Test if a connection to the directory server can be established.

Specified by:
testConnection in interface RemoteDirectory
Throws:
DirectoryAccessException - An unknown wire exception occurred.

authenticate

public User authenticate(java.lang.String name,
                         PasswordCredential credential)
                  throws InactiveAccountException,
                         InvalidAuthenticationException,
                         ObjectNotFoundException
Description copied from interface: RemoteDirectory
Authenticates a user with the directory store.

Specified by:
authenticate in interface RemoteDirectory
Parameters:
name - The name of the user (username).
credential - The supplied credentials (password).
Returns:
The populated user if the authentication is valid.
Throws:
InactiveAccountException - The supplied user is inactive.
InvalidAuthenticationException - Authentication with the provided credentials failed.
ObjectNotFoundException - The user wth the supplied name does not exist.

supportsNestedGroups

public boolean supportsNestedGroups()
Description copied from interface: RemoteDirectory
Allows us to only display nested-group related UI for directories that support it.

Specified by:
supportsNestedGroups in interface RemoteDirectory
Returns:
true if the directory can handle having a group added to a group.

updateUserCredential

public void updateUserCredential(java.lang.String name,
                                 PasswordCredential credential)
                          throws ObjectNotFoundException,
                                 InvalidCredentialException
Description copied from interface: RemoteDirectory
Updates the password for a user.

Specified by:
updateUserCredential in interface RemoteDirectory
Parameters:
name - The name of the user (username).
credential - The new credential (password).
Throws:
ObjectNotFoundException - The user does not exist.
InvalidCredentialException - The supplied credential is invalid.

renameUser

public User renameUser(java.lang.String oldName,
                       java.lang.String newName)
                throws ObjectNotFoundException,
                       InvalidUserException
Description copied from interface: RemoteDirectory
Renames a user.

Specified by:
renameUser in interface RemoteDirectory
Parameters:
oldName - name of existing user.
newName - desired name of user.
Returns:
renamed user.
Throws:
ObjectNotFoundException - if the user with the existing name does not exist.
InvalidUserException - if the new username is invalid or already exists in the directory.

storeUserAttributes

public void storeUserAttributes(java.lang.String username,
                                java.util.Map<java.lang.String,java.util.List<java.lang.String>> attributes)
                         throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Adds or updates a user's attributes with the new Map of attribute values in the directory specified by the passed in 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

Specified by:
storeUserAttributes in interface RemoteDirectory
Parameters:
username - name of user to update.
attributes - new or updated attributes (attributes that don't need changing should not appear in this Map).
Throws:
ObjectNotFoundException - user with supplied username does not exist.

removeUserAttributes

public void removeUserAttributes(java.lang.String username,
                                 java.lang.String attributeName)
                          throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Removes all the values for a single attribute key for a user.

Specified by:
removeUserAttributes in interface RemoteDirectory
Parameters:
username - name of the user to update.
attributeName - name of attribute to remove.
Throws:
ObjectNotFoundException - user with supplied username does not exist.

findUserByName

public User findUserByName(java.lang.String name)
                    throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Finds the user that matches the supplied name.

Specified by:
findUserByName in interface RemoteDirectory
Parameters:
name - the name of the user (username).
Returns:
user entity.
Throws:
ObjectNotFoundException - a user with the supplied name does not exist.

findUserWithAttributesByName

public UserWithAttributes findUserWithAttributesByName(java.lang.String name)
                                                throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Finds the user that matches the supplied name.

Specified by:
findUserWithAttributesByName in interface RemoteDirectory
Parameters:
name - the name of the user (username).
Returns:
user entity with attributes.
Throws:
ObjectNotFoundException - a user with the supplied name does not exist.

findGroupByName

public Group findGroupByName(java.lang.String name)
                      throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Finds the group that matches the supplied name.

Specified by:
findGroupByName in interface RemoteDirectory
Parameters:
name - the name of the group.
Returns:
group entity.
Throws:
ObjectNotFoundException - a group with the supplied name does not exist.

findGroupWithAttributesByName

public GroupWithAttributes findGroupWithAttributesByName(java.lang.String name)
                                                  throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Finds the group that matches the supplied name.

Specified by:
findGroupWithAttributesByName in interface RemoteDirectory
Parameters:
name - the name of the group.
Returns:
group entity with attributes.
Throws:
ObjectNotFoundException - a group with the supplied name does not exist.

findGroupByNameFromServerAndCacheResult

public Group findGroupByNameFromServerAndCacheResult(java.lang.String name)
                                              throws ObjectNotFoundException
Throws:
ObjectNotFoundException

findEntityByDN

public <T extends LDAPDirectoryEntity> T findEntityByDN(java.lang.String dn,
                                                        java.lang.Class<T> entityClass)
                                             throws ObjectNotFoundException
Description copied from interface: LDAPDirectory
Finds a directory entity (principal, group or role) by their distinguished name.

The object class of an entity is used to determine the entity type.

If an object represents both a group and role, then the object is mapped to a group.

No sub-tree restrictions are applied.

Specified by:
findEntityByDN in interface LDAPDirectory
Parameters:
dn - standardised disinguished name.
entityClass - class of the entity to find (either LDAPUserWithAttributes or LDAPGroupWithAttributes).
Returns:
directory entity corresponding to DN.
Throws:
ObjectNotFoundException - if a user/group does not exist at the specified DN or the DN does not exist in the directory. This will also be thrown if the entity DOES exist but does not match the base DN or object filter for the entity type.

findEntityIdentifierFromDN

protected EntityIdentifier findEntityIdentifierFromDN(java.lang.String dn,
                                                      EntityType entityType)
                                               throws ObjectNotFoundException
Throws:
ObjectNotFoundException

isGroupDirectGroupMember

public boolean isGroupDirectGroupMember(java.lang.String childGroup,
                                        java.lang.String parentGroup)
Description copied from interface: RemoteDirectory
Determines if a group is a direct member of another group. The directory is NOT expected to resolve any transitive group relationships.

Specified by:
isGroupDirectGroupMember in interface RemoteDirectory
Parameters:
childGroup - name of child group.
parentGroup - name of parent group.
Returns:
true iff the childGroup is a direct member of the parentGroup.

isUserDirectGroupMember

public boolean isUserDirectGroupMember(java.lang.String userName,
                                       java.lang.String groupName)
Description copied from interface: RemoteDirectory
Determines if a user is a direct member of a group. The directory is NOT expected to resolve any transitive group relationships.

Specified by:
isUserDirectGroupMember in interface RemoteDirectory
Parameters:
userName - name of user.
groupName - name of group.
Returns:
true iff the user is a direct member of the group.

addUserToGroup

public void addUserToGroup(java.lang.String username,
                           java.lang.String groupName)
                    throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Adds a user as a member of a group. This means that all user members of childGroup will appear as members of parentGroup to querying applications.

Specified by:
addUserToGroup in interface RemoteDirectory
Parameters:
username - The user that will become a member of groupName
groupName - The group that will gain a new member.
Throws:
ObjectNotFoundException - If the user or group cannot be found.

addGroupToGroup

public void addGroupToGroup(java.lang.String parentGroup,
                            java.lang.String childGroup)
                     throws ObjectNotFoundException,
                            java.lang.UnsupportedOperationException,
                            InvalidMembershipException
Description copied from interface: RemoteDirectory
Adds a group as a member of a parent group.

Specified by:
addGroupToGroup in interface RemoteDirectory
Parameters:
parentGroup - The group that will become a member of parentGroup
childGroup - The group that will gain a new member
Throws:
ObjectNotFoundException - One or both of the groups cannot be found.
InvalidMembershipException - if the childGroup and parentGroup exist but are of different GroupTypes.
java.lang.UnsupportedOperationException

removeUserFromGroup

public void removeUserFromGroup(java.lang.String username,
                                java.lang.String groupName)
                         throws ObjectNotFoundException,
                                MembershipNotFoundException
Description copied from interface: RemoteDirectory
Removes a user as a member of a group.

Specified by:
removeUserFromGroup in interface RemoteDirectory
Parameters:
username - The user that will be removed from parentGroup
groupName - The group that will lose the member.
Throws:
ObjectNotFoundException - If either the user or group cannot be found.
MembershipNotFoundException - if the user is not a direct member of the group.

removeGroupFromGroup

public void removeGroupFromGroup(java.lang.String parentGroup,
                                 java.lang.String childGroup)
                          throws ObjectNotFoundException,
                                 java.lang.UnsupportedOperationException,
                                 InvalidMembershipException,
                                 MembershipNotFoundException
Description copied from interface: RemoteDirectory
Removes a group as a member of a parent group.

Specified by:
removeGroupFromGroup in interface RemoteDirectory
Parameters:
parentGroup - The group that will be removed from parentGroup
childGroup - The group that will lose the member.
Throws:
ObjectNotFoundException - 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.
java.lang.UnsupportedOperationException

addUser

public User addUser(UserTemplate user,
                    PasswordCredential credential)
             throws InvalidUserException,
                    ObjectNotFoundException,
                    InvalidCredentialException
Description copied from interface: RemoteDirectory
Adds a user to the directory store.

Specified by:
addUser in interface RemoteDirectory
Parameters:
user - template of the user to add.
credential - password. May be null, since JIRA creates a user in two steps (user THEN password)
Returns:
the added user retrieved from the underlying store.
Throws:
InvalidUserException - The supplied user is invalid.
ObjectNotFoundException - The user could not be looked up after creation or the directory with the ID of user.directoryId does not exist.
InvalidCredentialException - The supplied credential is invalid.

updateUser

public User updateUser(UserTemplate user)
                throws ObjectNotFoundException,
                       InvalidUserException
Description copied from interface: RemoteDirectory
Updates the user.

Specified by:
updateUser in interface RemoteDirectory
Parameters:
user - The user to update.
Returns:
the updated user retrieved from the underlying store.
Throws:
ObjectNotFoundException - the user does not exist in the directory store.
InvalidUserException - the supplied user is invalid.

addGroup

public Group addGroup(GroupTemplate group)
               throws InvalidGroupException,
                      ObjectNotFoundException
Description copied from interface: RemoteDirectory
Adds a group to the directory store.

Specified by:
addGroup in interface RemoteDirectory
Parameters:
group - template of the group to add.
Returns:
the added group retrieved from the underlying store.
Throws:
InvalidGroupException - The supplied group is invalid.
ObjectNotFoundException - The group could not be looked up after creation or the directory with the ID of group.directoryId does not exist.

updateGroup

public Group updateGroup(GroupTemplate group)
                  throws ObjectNotFoundException,
                         InvalidGroupException
Description copied from interface: RemoteDirectory
Updates the group.

Specified by:
updateGroup in interface RemoteDirectory
Parameters:
group - The group to update.
Returns:
the updated group retrieved from the underlying store.
Throws:
ObjectNotFoundException - the group does not exist in the directory store.
InvalidGroupException - the supplied group is invalid.

renameGroup

public Group renameGroup(java.lang.String oldName,
                         java.lang.String newName)
                  throws ObjectNotFoundException,
                         InvalidGroupException
Description copied from interface: RemoteDirectory
Renames a group.

Specified by:
renameGroup in interface RemoteDirectory
Parameters:
oldName - name of existing group.
newName - desired name of group.
Returns:
renamed group.
Throws:
ObjectNotFoundException - if the group with the existing name does not exist.
InvalidGroupException - if the new groupname is invalid or already exists in the directory.

storeGroupAttributes

public void storeGroupAttributes(java.lang.String groupName,
                                 java.util.Map<java.lang.String,java.util.List<java.lang.String>> attributes)
                          throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Adds or updates a group's attributes with the new Map of attribute values in the directory specified by the passed in 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

Specified by:
storeGroupAttributes in interface RemoteDirectory
Parameters:
groupName - name of group to update.
attributes - new or updated attributes (attributes that don't need changing should not appear in this Map).
Throws:
ObjectNotFoundException - group with supplied groupName does not exist.

removeGroupAttributes

public void removeGroupAttributes(java.lang.String groupName,
                                  java.lang.String attributeName)
                           throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Removes all the values for a single attribute key for a group.

Specified by:
removeGroupAttributes in interface RemoteDirectory
Parameters:
groupName - name of the group to update.
attributeName - name of attribute to remove.
Throws:
ObjectNotFoundException - group with supplied groupName does not exist.

removeUser

public void removeUser(java.lang.String name)
                throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Removes the user that matches the supplied name.

Specified by:
removeUser in interface RemoteDirectory
Parameters:
name - The name of the user (username).
Throws:
ObjectNotFoundException - The user does not exist.

removeGroup

public void removeGroup(java.lang.String name)
                 throws ObjectNotFoundException
Description copied from interface: RemoteDirectory
Removes the group that matches the supplied name.

Specified by:
removeGroup in interface RemoteDirectory
Parameters:
name - The name of the group.
Throws:
ObjectNotFoundException - The group does not exist.

searchGroupRelationships

public java.util.List searchGroupRelationships(MembershipQuery query)
Description copied from interface: RemoteDirectory
Searches for membership information.

Specified by:
searchGroupRelationships in interface RemoteDirectory
Parameters:
query - query for memberships.
Returns:
a List of Users or Groups or Strings depending on the query criteria. An empty List if there are no results.

findGroupMembershipsOfUser

protected java.util.List<LDAPGroupWithAttributes> findGroupMembershipsOfUser(java.lang.String username,
                                                                             int startIndex,
                                                                             int maxResults)
                                                                      throws ObjectNotFoundException
Throws:
ObjectNotFoundException

isFindAllEntities

protected boolean isFindAllEntities(EntityQuery query)

findAllUsersFromDirectory

protected java.util.List<LDAPUserWithAttributes> findAllUsersFromDirectory()

findAllGroupsFromDirectory

protected java.util.List<LDAPGroupWithAttributes> findAllGroupsFromDirectory()

findAllUsers

protected java.util.List<LDAPUserWithAttributes> findAllUsers()

findAllGroups

protected java.util.List<LDAPGroupWithAttributes> findAllGroups()

searchGroups

public java.util.List searchGroups(EntityQuery query)
Description copied from interface: RemoteDirectory
Searches for groups that match the supplied query criteria.

Specified by:
searchGroups in interface RemoteDirectory
Parameters:
query - EntityQuery for Entity.GROUP.
Returns:
List or List of groups/groupnames matching the search criteria. An empty List will be returned if no groups matching the criteria are found.

searchUsers

public java.util.List searchUsers(EntityQuery query)
Description copied from interface: RemoteDirectory
Searches for users that match the supplied query criteria.

Specified by:
searchUsers in interface RemoteDirectory
Parameters:
query - EntityQuery for Entity.USER.
Returns:
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.


Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.