public class SimpleLdapAttributeMapper extends Object implements LdapAttributeMapper
AttributeMappingConstants. The strategy for calculating
Sakai user type can be injected as a UserTypeMapper.
This strategy defaults to EmptyStringUserTypeMapper, which
will match <= 2.3.0 OOTB behavior.| Constructor and Description |
|---|
SimpleLdapAttributeMapper() |
| Modifier and Type | Method and Description |
|---|---|
String |
escapeSearchFilterTerm(String term)
Scrubs the given search filter term (i.e. a value to be matched, or not,
in a search predicate) for reserved characters.
|
String |
getAttributeMapping(String key)
Map the given logical attribute name to a physical attribute name.
|
Map<String,String> |
getAttributeMappings()
Returns a direct reference to the currently
cached mappings.
|
String |
getFindUserByAidFilter(String aid)
Output a filter string for searching the directory with
the specified user aid as a key.
|
String |
getFindUserByCrossAttributeSearchFilter(String criteria)
Builds a filter to perform a wildcard search for criteria in uid, email, first name or last name
In order to minimise hitting the limits of searches, this only performs a wildcard match on anything after
the supplied criteria.
|
String |
getFindUserByEidFilter(String eid)
Builds a filter of the form <login-attr>=<
eid> |
String |
getFindUserByEmailFilter(String emailAddr)
Builds a filter of the form <email-attr>=<
emailAddr> |
String |
getManyUsersInOneSearch(Set<String> criteria)
Builds a filter to a uid search against many users at once
For reference, the LDAP search filter is of the form:
"(|(uid=sample.user)(uid=john.doe)(uid=jane.smith))"
|
protected Map<String,Collection<String>> |
getReverseAttributeMap() |
Collection<String> |
getReverseAttributeMappings(String physicalAttrName)
Access the configured logical names associated with the given
physical attribute name.
|
String[] |
getSearchResultAttributes()
Implemented to return the current values of
{link
#getAttributeMappings().values() as
a String array. |
String |
getUserBindDn(LdapUserData userData)
Determine the DN to which to bind when executing an authentication
attempt for the given user.
|
protected String |
getUserDataDn(LdapUserData userData) |
UserTypeMapper |
getUserTypeMapper()
Access the strategy for calculating the Sakai user type given a
LDAPEntry |
Map<String,MessageFormat> |
getValueMappings() |
void |
init()
Completes configuration of this instance.
|
protected void |
mapLdapAttributeOntoUserData(com.novell.ldap.LDAPAttribute attribute,
LdapUserData userData,
Collection<String> logicalAttrNames)
Map the given
LDAPAttribute onto the given
LdapUserData. |
protected void |
mapLdapAttributeOntoUserData(com.novell.ldap.LDAPAttribute attribute,
LdapUserData userData,
String logicalAttrName)
A delegate of
mapLdapAttributeOntoUserData(LDAPAttribute, LdapUserData, Collection)
that allows for discrete handling of each logical attribute name associated with
the given LDAPAttribute |
void |
mapLdapEntryOntoUserData(com.novell.ldap.LDAPEntry ldapEntry,
LdapUserData userData)
Performs
LDAPEntry-to- attribute
mappings. |
protected String |
mapLdapEntryToSakaiUserType(com.novell.ldap.LDAPEntry ldapEntry)
Passes the given
LDAPEntry and a reference to this
SimpleLdapAttributeMapper to
UserTypeMapper.mapLdapEntryToSakaiUserType(LDAPEntry, LdapAttributeMapper). |
void |
mapUserDataOntoUserEdit(LdapUserData userData,
UserEdit userEdit)
Straightforward
LdapUserData to
UserEdit field-to-field mapping, including
properties. |
protected Map<String,Collection<String>> |
reverseAttributeMap(Map<String,String> toReverse)
Creates a reverse lookup map of a given attribute map's values.
|
void |
setAttributeMappings(Map<String,String> attributeMappings)
Caches the given Map reference and takes a
snapshot of the values therein for future
use by
getSearchResultAttributes(). |
protected void |
setUserDataDn(com.novell.ldap.LDAPEntry entry,
LdapUserData targetUserData) |
void |
setUserTypeMapper(UserTypeMapper userTypeMapper)
Assign the strategy for calculating the Sakai user type given a
LDAPEntry |
void |
setValueMappings(Map<String,MessageFormat> valueMappings) |
protected String |
usePreferredFirstName(LdapUserData userData)
Determines if a user has a preferredFirstName set and if so, returns it for use.
|
public void init()
Initializes internal mappings to a copy of
AttributeMappingConstants.DEFAULT_ATTR_MAPPINGS if
the current map is empty. Initializes user
type mapping strategy to a
EmptyStringUserTypeMapper if no strategy
has been specified.
This defaulting enables UDP config forward-compatibility.
init in interface LdapAttributeMapperpublic String getFindUserByEmailFilter(String emailAddr)
emailAddr>getFindUserByEmailFilter in interface LdapAttributeMapperemailAddr - an email address to search onpublic String getFindUserByEidFilter(String eid)
eid>getFindUserByEidFilter in interface LdapAttributeMappereid - a user eid to search onpublic String getFindUserByAidFilter(String aid)
LdapAttributeMappergetFindUserByAidFilter in interface LdapAttributeMapperaid - a user authentication id.public void mapLdapEntryOntoUserData(com.novell.ldap.LDAPEntry ldapEntry,
LdapUserData userData)
LDAPEntry-to- attribute
mappings. Assigns the given LDAPEntry's DN to the
LdapUserData as a property keyed by
AttributeMappingConstants.USER_DN_PROPERTY. Then iterates
over LDAPEntry.getAttributeSet(), handing each attribute
to mapLdapAttributeOntoUserData(LDAPAttribute, LdapUserData, Collection).
Then enforces the preferred first name field, if it exists.
Finally, assigns a "type" to the LdapUserData as defined
by mapLdapEntryToSakaiUserType(LDAPEntry).mapLdapEntryOntoUserData in interface LdapAttributeMapperldapEntry - the user's directory entryuserData - target LdapUserDataUserTypeMapperpublic String getUserBindDn(LdapUserData userData)
LdapAttributeMapperLdapUserData
by this LdapAttributeMapper. For example, the mapper
could have cached the DN in the user's property map, or the bind DN could
be reliably calculated from a combination of the user's eid
and some other configured RDN string.getUserBindDn in interface LdapAttributeMapperuserData - a mapped collection of user attributes from which
to derive a bindable DN. Should not be nulluserData or
null if the DN is not known.protected String getUserDataDn(LdapUserData userData)
protected void setUserDataDn(com.novell.ldap.LDAPEntry entry,
LdapUserData targetUserData)
protected void mapLdapAttributeOntoUserData(com.novell.ldap.LDAPAttribute attribute,
LdapUserData userData,
Collection<String> logicalAttrNames)
LDAPAttribute onto the given
LdapUserData. Client can specify the logical attribute
name(s) which have been configured for the given LDAPAttribute.
This implementation has specific handling for the following
logical attribute names:
AttributeMappingConstants.LOGIN_ATTR_MAPPING_KEY - LdapUserData.setEid(String)AttributeMappingConstants.FIRST_NAME_ATTR_MAPPING_KEY - LdapUserData.setFirstName(String)AttributeMappingConstants.LAST_NAME_ATTR_MAPPING_KEY - LdapUserData.setLastName(String)AttributeMappingConstants.EMAIL_ATTR_MAPPING_KEY - LdapUserData.setEmail(String)logicalAttrNames
will be mapped onto userData as a property using
the logical attribute name as a key.attribute - the LDAPAttribute to mapuserData - the target LdapUserData instancelogicalAttrNames - logical name(s) of the attribute. May
be null or empty, indicating no configured logical name(s).protected void mapLdapAttributeOntoUserData(com.novell.ldap.LDAPAttribute attribute,
LdapUserData userData,
String logicalAttrName)
mapLdapAttributeOntoUserData(LDAPAttribute, LdapUserData, Collection)
that allows for discrete handling of each logical attribute name associated with
the given LDAPAttributeattribute - userData - logicalAttrName - protected String mapLdapEntryToSakaiUserType(com.novell.ldap.LDAPEntry ldapEntry)
LDAPEntry and a reference to this
SimpleLdapAttributeMapper to
UserTypeMapper.mapLdapEntryToSakaiUserType(LDAPEntry, LdapAttributeMapper).
By default, this will just return an empty String.ldapEntry - the LDAPEntry to mapnulls and
empty Strings are possible.public void mapUserDataOntoUserEdit(LdapUserData userData, UserEdit userEdit)
LdapUserData to
UserEdit field-to-field mapping, including
properties.mapUserDataOntoUserEdit in interface LdapAttributeMapperuserData - a non-null user cache entryuserEdit - a non-null user domain objectpublic String escapeSearchFilterTerm(String term)
LdapAttributeMapperescapeSearchFilterTerm in interface LdapAttributeMapperterm - The string value to be scrubbednull if the received String is null, otherwise
a copy of the received String with reserved characters escaped.public String getAttributeMapping(String key)
getAttributeMapping in interface LdapAttributeMapperkey - the logical attribute namepublic Collection<String> getReverseAttributeMappings(String physicalAttrName)
null.physicalAttrName - a physical LDAP attribute name to reverse
map to zero or more logical attribute namesnull
or empty.protected Map<String,Collection<String>> getReverseAttributeMap()
public String[] getSearchResultAttributes()
#getAttributeMappings().values() as
a String array.getSearchResultAttributes in interface LdapAttributeMapperpublic Map<String,String> getAttributeMappings()
getSearchResultAttributes() may
return stale values.getAttributeMappings in interface LdapAttributeMapperpublic void setAttributeMappings(Map<String,String> attributeMappings)
getSearchResultAttributes().setAttributeMappings in interface LdapAttributeMapperattributeMappings - the attribute map.getAttributeMappings()protected Map<String,Collection<String>> reverseAttributeMap(Map<String,String> toReverse)
Collection's.
Protected access control mainly to enable testing
toReverse - public UserTypeMapper getUserTypeMapper()
LDAPEntrypublic void setUserTypeMapper(UserTypeMapper userTypeMapper)
LDAPEntryprotected String usePreferredFirstName(LdapUserData userData)
userData - the LdapUserData for the userpublic String getFindUserByCrossAttributeSearchFilter(String criteria)
LdapAttributeMapperIn order to minimise hitting the limits of searches, this only performs a wildcard match on anything after
the supplied criteria.
For example, a search for 'john' will match 'john' and 'johnson' but not 'gudjohnsen'.
For reference, the LDAP search filter is of the form: "(|(uid=criteria*)(mail=criteria*)(givenName=criteria*)(sn=criteria*))"
getFindUserByCrossAttributeSearchFilter in interface LdapAttributeMapperpublic String getManyUsersInOneSearch(Set<String> criteria)
LdapAttributeMappergetManyUsersInOneSearch in interface LdapAttributeMapperpublic Map<String,MessageFormat> getValueMappings()
public void setValueMappings(Map<String,MessageFormat> valueMappings)
valueMappings - A Map of message formats used for extracting values from LDAP data.Copyright © 2003–2022 Sakai Project. All rights reserved.