|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.atlassian.crowd.integration.directory.connector.SpringLDAPConnector
public abstract class SpringLDAPConnector
Field Summary | |
---|---|
protected org.springframework.context.ApplicationContext |
applicationContext
|
protected AttributeValuesHolder |
attributes
|
protected org.springframework.ldap.core.support.LdapContextSource |
contextSource
|
static int |
DEFAULT_PAGE_SIZE
|
protected com.atlassian.event.EventManager |
eventManager
|
protected LDAPPropertiesMapper |
ldapPropertiesMapper
|
protected LDAPQueryTranslater |
ldapQueryTranslater
|
protected org.springframework.ldap.core.LdapTemplate |
ldapTemplate
|
protected org.apache.log4j.Logger |
logger
|
protected Converter |
nameConverter
|
protected SearchDN |
searchDN
|
Constructor Summary | |
---|---|
SpringLDAPConnector()
|
Method Summary | ||
---|---|---|
protected void |
addDefaultSnToUserAttributes(Attributes attrs,
String defaultSnValue)
A default install of many directory servers (inc. |
|
protected void |
addDefaultValueToUserAttributesForAttribute(String attributeName,
Attributes attrs,
String defaultValue)
|
|
Group |
addGroup(GroupTemplate group)
Adds a group to the directory store. |
|
LDAPUserWithAttributes |
addUser(UserTemplate user,
PasswordCredential credential)
Adds a user to the directory store. |
|
protected LdapName |
asLdapName(String dn,
Class objectType)
This method is required to wrap DN's into LdapNames as spring-ldap doesn't correctly handle operations with String dn arguments. |
|
User |
authenticate(String name,
PasswordCredential credential)
Authenticates a user with the directory store. |
|
protected abstract String |
encodePassword(String unencodedPassword)
Given an plain-text password, encodes/encrypts it according to the settings required by the particular directory connector. |
|
|
findEntityByDN(String dn,
Class<T> entityClass)
Finds a directory entity (principal, group or role) by their distinguished name. |
|
protected
|
findEntityByDN(String dn,
String baseDN,
String filter,
org.springframework.ldap.core.ContextMapper contextMapper,
Class<T> entityClass)
|
|
LDAPGroupWithAttributes |
findGroupByName(String name)
Finds the group that matches the supplied name . |
|
protected LDAPGroupWithAttributes |
findGroupByNameAndType(String name,
GroupType groupType)
|
|
LDAPGroupWithAttributes |
findGroupWithAttributesByName(String name)
Finds the group that matches the supplied name . |
|
LDAPUserWithAttributes |
findUserByName(String name)
Finds the user that matches the supplied name . |
|
LDAPUserWithAttributes |
findUserWithAttributesByName(String name)
Finds the user that matches the supplied name . |
|
String |
getAttribute(String name)
|
|
boolean |
getAttributeAsBoolean(String name,
boolean defaultValue)
|
|
long |
getAttributeAsLong(String name,
long defaultValue)
|
|
Set<String> |
getAttributeNames()
|
|
List<String> |
getAttributes(String name)
|
|
protected Hashtable<String,String> |
getBaseEnvironmentProperties()
Returns the properties used to set up the Ldap ContextSource. |
|
org.springframework.ldap.core.support.LdapContextSource |
getContextSource()
Exposed so that delegated directories can get a handle on the underlying LDAP context. |
|
protected List<AttributeMapper> |
getCustomGroupAttributeMappers()
As a minimum, this SHOULD provide an attribute mapper that maps the group members attribute (if available). |
|
protected List<AttributeMapper> |
getCustomUserAttributeMappers()
|
|
long |
getDirectoryId()
Gets the internal unique directoryId of the directory store. |
|
protected Encoder |
getEncoder()
Returns an Encoder that escapes LDAP special characters for use in object names and in DNs. |
|
org.springframework.ldap.core.ContextMapper |
getGroupContextMapper(GroupType groupType)
Returns a ContextMapper ready to translate LDAP objects into Groups and fetches all member objects |
|
protected String |
getInitialGroupMemberDN()
Returns the default container member DN. |
|
LDAPPropertiesMapper |
getLdapPropertiesMapper()
|
|
protected Attributes |
getNewGroupAttributes(Group group)
|
|
protected void |
getNewGroupDirectorySpecificAttributes(Group group,
Attributes attributes)
|
|
protected Attributes |
getNewUserAttributes(User user,
PasswordCredential credential)
Translates the User into LDAP attributes, in preparation for creating a new user. |
|
protected void |
getNewUserDirectorySpecificAttributes(User user,
Attributes attributes)
Overridden by sub-classes to add any additional attributes they need when creating a new user. |
|
SearchDN |
getSearchDN()
|
|
protected String |
getStandardisedDN(Name dn)
|
|
protected SearchControls |
getSubTreeSearchControl()
|
|
org.springframework.ldap.core.ContextMapper |
getUserContextMapper()
Returns a ContextMapper that can transform a Context into a User. |
|
boolean |
hasAttribute(String name)
|
|
protected org.springframework.ldap.core.CollectingNameClassPairCallbackHandler |
pageSearchResults(Name baseDN,
String filter,
org.springframework.ldap.core.ContextMapper contextMapper,
SearchControls searchControls,
org.springframework.ldap.core.DirContextProcessor ldapRequestControls,
int maxResults)
Performs a paged results search on an LDAP directory server searching using the LDAP paged results control option to fetch results in chunks rather than all at once. |
|
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 |
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. |
|
Group |
renameGroup(String oldName,
String newName)
Renames a group . |
|
User |
renameUser(String oldName,
String newName)
Renames a user . |
|
protected List |
searchEntities(Name baseDN,
String filter,
org.springframework.ldap.core.ContextMapper contextMapper,
int startIndex,
int maxResults)
Executes a search with paging if paged results is supported. |
|
protected List |
searchEntitiesWithRequestControls(Name baseDN,
String filter,
org.springframework.ldap.core.ContextMapper contextMapper,
SearchControls searchControls,
org.springframework.ldap.core.DirContextProcessor ldapRequestControls,
int startIndex,
int maxResults)
|
|
protected List<LDAPGroupWithAttributes> |
searchGroupObjects(EntityQuery query)
|
|
protected List<LDAPGroupWithAttributes> |
searchGroupObjectsOfSpecifiedGroupType(EntityQuery query)
This method expects that the query contains a non-null groupType in the entityDescriptor. |
|
List |
searchGroupRelationships(MembershipQuery query)
Searches for membership information. |
|
protected abstract List |
searchGroupRelationshipsWithGroupTypeSpecified(MembershipQuery query)
Execute the search for group relationships given that a group of type GROUP or LEGACY_ROLE has been specified in the EntityDescriptor for the group(s). |
|
List |
searchGroups(EntityQuery query)
Searches for groups that match the supplied query criteria. |
|
protected List<LDAPUserWithAttributes> |
searchUserObjects(EntityQuery query)
|
|
List |
searchUsers(EntityQuery query)
Searches for users that match the supplied query criteria. |
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
|
|
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 |
setEventManager(com.atlassian.event.EventManager eventManager)
|
|
void |
setLdapQueryTranslater(LDAPQueryTranslater ldapQueryTranslater)
|
|
void |
storeGroupAttributes(String groupName,
Map<String,List<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,List<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(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 |
Methods inherited from interface com.atlassian.crowd.integration.directory.RemoteDirectory |
---|
addGroupToGroup, addUserToGroup, getDescriptiveName, isGroupDirectGroupMember, isUserDirectGroupMember, removeGroupFromGroup, removeUserFromGroup |
Field Detail |
---|
public static final int DEFAULT_PAGE_SIZE
protected final org.apache.log4j.Logger logger
protected AttributeValuesHolder attributes
protected org.springframework.ldap.core.LdapTemplate ldapTemplate
protected LDAPPropertiesMapper ldapPropertiesMapper
protected org.springframework.ldap.core.support.LdapContextSource contextSource
protected Converter nameConverter
protected SearchDN searchDN
protected org.springframework.context.ApplicationContext applicationContext
protected LDAPQueryTranslater ldapQueryTranslater
protected com.atlassian.event.EventManager eventManager
Constructor Detail |
---|
public SpringLDAPConnector()
Method Detail |
---|
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 org.springframework.ldap.core.support.LdapContextSource getContextSource()
public LDAPPropertiesMapper getLdapPropertiesMapper()
public List<String> getAttributes(String name)
getAttributes
in interface AttributeAware
name
- attribute name.
public String getAttribute(String name)
getAttribute
in interface AttributeAware
name
- attribute name.
null
if the attribute with the given name does not exist.
If multiple attribute values exist, any one could be
returned.public long getAttributeAsLong(String name, long defaultValue)
public boolean getAttributeAsBoolean(String name, boolean defaultValue)
public Set<String> getAttributeNames()
getAttributeNames
in interface AttributeAware
public boolean hasAttribute(String name)
hasAttribute
in interface AttributeAware
name
- attribute name.
true
if an only if the
user has an attribute with the supplied name
and has one or more values.public SearchDN getSearchDN()
protected SearchControls getSubTreeSearchControl()
protected Encoder getEncoder()
protected Hashtable<String,String> getBaseEnvironmentProperties()
protected org.springframework.ldap.core.CollectingNameClassPairCallbackHandler pageSearchResults(Name baseDN, String filter, org.springframework.ldap.core.ContextMapper contextMapper, SearchControls searchControls, org.springframework.ldap.core.DirContextProcessor ldapRequestControls, int maxResults)
baseDN
- The DN to beging the search from.filter
- The search filter.contextMapper
- Maps from LDAP search results into objects such as Group
s.searchControls
- The LDAP search scope type.ldapRequestControls
- Any LDAP request controls (set to null
if you do not need additional request controls for the search).maxResults
- maximum number of results to return. Set to -1
if no result limiting is desired (WARNING: doing so is obviously a hazard).
protected List searchEntities(Name baseDN, String filter, org.springframework.ldap.core.ContextMapper contextMapper, int startIndex, int maxResults)
baseDN
- base DN of search.filter
- encoded LDAP search filter.contextMapper
- directory context to object mapper.startIndex
- index to start at. Set to 0
to start from the first result.maxResults
- maximum number of results to return. Set to -1
if no result limiting is desired (WARNING: doing so is obviously a hazard).
protected List searchEntitiesWithRequestControls(Name baseDN, String filter, org.springframework.ldap.core.ContextMapper contextMapper, SearchControls searchControls, org.springframework.ldap.core.DirContextProcessor ldapRequestControls, int startIndex, int maxResults)
public org.springframework.ldap.core.ContextMapper getUserContextMapper()
protected List<AttributeMapper> getCustomUserAttributeMappers()
public org.springframework.ldap.core.ContextMapper getGroupContextMapper(GroupType groupType)
protected List<AttributeMapper> getCustomGroupAttributeMappers()
public LDAPUserWithAttributes findUserByName(String name) throws ObjectNotFoundException
RemoteDirectory
user
that matches the supplied name
.
findUserByName
in interface RemoteDirectory
name
- the name of the user (username).
ObjectNotFoundException
- a user with the supplied name does not exist.public LDAPUserWithAttributes findUserWithAttributesByName(String name) throws ObjectNotFoundException
RemoteDirectory
user
that matches the supplied name
.
findUserWithAttributesByName
in interface RemoteDirectory
name
- the name of the user (username).
ObjectNotFoundException
- a user with the supplied name does not exist.protected List<LDAPUserWithAttributes> searchUserObjects(EntityQuery query)
public void removeUser(String name) throws ObjectNotFoundException
RemoteDirectory
user
that matches the supplied name
.
removeUser
in interface RemoteDirectory
name
- The name of the user (username).
ObjectNotFoundException
- The user does not exist.public void updateUserCredential(String name, PasswordCredential credential) throws ObjectNotFoundException, InvalidCredentialException
RemoteDirectory
password
for a user
.
updateUserCredential
in interface RemoteDirectory
name
- The name of the user (username).credential
- The new credential (password).
ObjectNotFoundException
- The user does not exist.
InvalidCredentialException
- The supplied credential is invalid.public User renameUser(String oldName, String newName) throws ObjectNotFoundException, InvalidUserException
RemoteDirectory
user
.
renameUser
in interface RemoteDirectory
oldName
- name of existing user.newName
- desired name of user.
ObjectNotFoundException
- if the user with the existing name does not exist.
InvalidUserException
- if the new username is invalid or already exists in the directory.public void storeUserAttributes(String username, Map<String,List<String>> attributes) throws ObjectNotFoundException
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
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).
ObjectNotFoundException
- user with supplied username does not exist.public void removeUserAttributes(String username, String attributeName) throws ObjectNotFoundException
RemoteDirectory
removeUserAttributes
in interface RemoteDirectory
username
- name of the user to update.attributeName
- name of attribute to remove.
ObjectNotFoundException
- user with supplied username does not exist.protected Attributes getNewUserAttributes(User user, PasswordCredential credential) throws InvalidCredentialException, org.springframework.ldap.NamingException
User
into LDAP attributes, in preparation for creating a new user.
user
- The user object to translate into LDAP attributescredential
- raw password.
InvalidCredentialException
- The password, if supplied, was invalid in some manner.
org.springframework.ldap.NamingException
- If the User
could not be translated to an Attributes
protected void getNewUserDirectorySpecificAttributes(User user, Attributes attributes)
addBlankSnToUserAttributes
.
user
- The (potential) source of information that needs to be addedattributes
- The attributes to add directory-specific information topublic LDAPUserWithAttributes addUser(UserTemplate user, PasswordCredential credential) throws InvalidUserException, InvalidCredentialException, ObjectNotFoundException
RemoteDirectory
user
to the directory store.
addUser
in interface RemoteDirectory
user
- template of the user to add.credential
- password. May be null, since JIRA creates a user in two steps (user THEN password)
InvalidUserException
- The supplied user is invalid.
InvalidCredentialException
- The supplied credential is invalid.
ObjectNotFoundException
- The user could not be looked up after creation or the directory with the ID of user.directoryId does not exist.protected void addDefaultSnToUserAttributes(Attributes attrs, String defaultSnValue)
sn
if it's not present in the
information provided.
attrs
- The LDAP user attributes to be checked and potentially updated.defaultSnValue
- default lastname/surname valueprotected void addDefaultValueToUserAttributesForAttribute(String attributeName, Attributes attrs, String defaultValue)
public <T extends LDAPDirectoryEntity> T findEntityByDN(String dn, Class<T> entityClass) throws ObjectNotFoundException
LDAPDirectory
findEntityByDN
in interface LDAPDirectory
dn
- standardised disinguished name.entityClass
- class of the entity to find (either LDAPUserWithAttributes
or LDAPGroupWithAttributes
).
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.protected <T extends LDAPDirectoryEntity> T findEntityByDN(String dn, String baseDN, String filter, org.springframework.ldap.core.ContextMapper contextMapper, Class<T> entityClass) throws ObjectNotFoundException, InvalidNameException
ObjectNotFoundException
InvalidNameException
public User updateUser(UserTemplate user) throws ObjectNotFoundException
RemoteDirectory
user
.
updateUser
in interface RemoteDirectory
user
- The user to update.
ObjectNotFoundException
- the user does not exist in the directory store.public List searchUsers(EntityQuery query)
RemoteDirectory
users
that match the supplied query criteria.
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 User authenticate(String name, PasswordCredential credential) throws InvalidAuthenticationException, ObjectNotFoundException
RemoteDirectory
user
with the directory store.
authenticate
in interface RemoteDirectory
name
- The name of the user (username).credential
- The supplied credentials (password).
InvalidAuthenticationException
- Authentication with the provided credentials failed.
ObjectNotFoundException
- The user wth the supplied name does not exist.public LDAPGroupWithAttributes findGroupByName(String name) throws ObjectNotFoundException
RemoteDirectory
group
that matches the supplied name
.
findGroupByName
in interface RemoteDirectory
name
- the name of the group.
ObjectNotFoundException
- a group with the supplied name does not exist.public LDAPGroupWithAttributes findGroupWithAttributesByName(String name) throws ObjectNotFoundException
RemoteDirectory
group
that matches the supplied name
.
findGroupWithAttributesByName
in interface RemoteDirectory
name
- the name of the group.
ObjectNotFoundException
- a group with the supplied name does not exist.protected LDAPGroupWithAttributes findGroupByNameAndType(String name, GroupType groupType) throws ObjectNotFoundException
ObjectNotFoundException
protected List<LDAPGroupWithAttributes> searchGroupObjectsOfSpecifiedGroupType(EntityQuery query)
query
- search query.
protected List<LDAPGroupWithAttributes> searchGroupObjects(EntityQuery query)
public List searchGroups(EntityQuery query)
RemoteDirectory
groups
that match the supplied query criteria.
searchGroups
in interface RemoteDirectory
query
- EntityQuery for Entity.GROUP.
List
or List
of groups/groupnames
matching the search criteria. An empty List
will be returned
if no groups matching the criteria are found.protected Attributes getNewGroupAttributes(Group group) throws org.springframework.ldap.NamingException
org.springframework.ldap.NamingException
protected void getNewGroupDirectorySpecificAttributes(Group group, Attributes attributes)
protected String getInitialGroupMemberDN()
null
, no member
DN will be added.
public Group addGroup(GroupTemplate group) throws InvalidGroupException, ObjectNotFoundException
RemoteDirectory
group
to the directory store.
addGroup
in interface RemoteDirectory
group
- template of the group to add.
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.public Group updateGroup(GroupTemplate group) throws ObjectNotFoundException
RemoteDirectory
group
.
updateGroup
in interface RemoteDirectory
group
- The group to update.
ObjectNotFoundException
- the group does not exist in the directory store.public void removeGroup(String name) throws ObjectNotFoundException
RemoteDirectory
group
that matches the supplied name
.
removeGroup
in interface RemoteDirectory
name
- The name of the group.
ObjectNotFoundException
- The group does not exist.public Group renameGroup(String oldName, String newName) throws ObjectNotFoundException, InvalidGroupException
RemoteDirectory
group
.
renameGroup
in interface RemoteDirectory
oldName
- name of existing group.newName
- desired name of group.
ObjectNotFoundException
- if the group with the existing name does not exist.
InvalidGroupException
- if the new groupname is invalid or already exists in the directory.public void storeGroupAttributes(String groupName, Map<String,List<String>> attributes) throws ObjectNotFoundException
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
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).
ObjectNotFoundException
- group with supplied groupName does not exist.public void removeGroupAttributes(String groupName, String attributeName) throws ObjectNotFoundException
RemoteDirectory
removeGroupAttributes
in interface RemoteDirectory
groupName
- name of the group to update.attributeName
- name of attribute to remove.
ObjectNotFoundException
- group with supplied groupName does not exist.public List searchGroupRelationships(MembershipQuery query)
RemoteDirectory
searchGroupRelationships
in interface RemoteDirectory
query
- query for memberships.
protected abstract List searchGroupRelationshipsWithGroupTypeSpecified(MembershipQuery query)
query
- membership query with all GroupType's not null.
protected abstract String encodePassword(String unencodedPassword) throws InvalidCredentialException
unencodedPassword
- The password to be transformed
InvalidCredentialException
- If the password could not be converted.public boolean supportsNestedGroups()
RemoteDirectory
supportsNestedGroups
in interface RemoteDirectory
public void testConnection() throws DirectoryAccessException
RemoteDirectory
testConnection
in interface RemoteDirectory
DirectoryAccessException
- An unknown wire exception occurred.protected String getStandardisedDN(Name dn)
protected LdapName asLdapName(String dn, Class objectType) throws ObjectNotFoundException
dn
- string version of DN.objectType
- incase there is a problem converting the dn into an LdapName an ONFE with this type will be thrown.
ObjectNotFoundException
- underlying InvalidNameException.public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
public void setEventManager(com.atlassian.event.EventManager eventManager)
public void setLdapQueryTranslater(LDAPQueryTranslater ldapQueryTranslater)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |