Skip to content

Commit

Permalink
SAK-26150 Support DisplayAdvisorUDP in JLDAPDirectoryProvider
Browse files Browse the repository at this point in the history
Unless there's an attribute mapping for a displayId of displayName then the JLDAPDirectoryProvider just returns null which causes the UserDirectoryService to use the standard values. When a mapping attribute is supplied the value of that attribute is stored as a property on the user object and then used when the provider is asked for a displayId/displayName.

git-svn-id: https://source.sakaiproject.org/svn/providers/trunk@314082 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
buckett committed Oct 7, 2014
1 parent 4ab04d3 commit 9eecfb6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public abstract class AttributeMappingConstants {
* name of a user entry's group membership attribute
*/
public static final String GROUP_MEMBERSHIP_ATTR_MAPPING_KEY = "groupMembership";


public static final String DISPLAY_ID_ATTR_MAPPING_KEY = "displayId";

public static final String DISPLAY_NAME_ATTR_MAPPING_KEY = "displayName";

/** Default value in {@link #DEFAULT_ATTR_MAPPINGS} representing
* the physical name of a user entry's login (aka Sakai "EID") attribute
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.user.api.ExternalUserSearchUDP;
import org.sakaiproject.user.api.DisplayAdvisorUDP;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserDirectoryProvider;
import org.sakaiproject.user.api.UserEdit;
Expand All @@ -57,7 +58,7 @@
* @author David Ross, Albany Medical College
* @author Rishi Pande, Virginia Tech
*/
public class JLDAPDirectoryProvider implements UserDirectoryProvider, LdapConnectionManagerConfig, ExternalUserSearchUDP, UsersShareEmailUDP
public class JLDAPDirectoryProvider implements UserDirectoryProvider, LdapConnectionManagerConfig, ExternalUserSearchUDP, UsersShareEmailUDP, DisplayAdvisorUDP
{
/** Default LDAP connection port */
public static final int DEFAULT_LDAP_PORT = 389;
Expand Down Expand Up @@ -89,6 +90,12 @@ public class JLDAPDirectoryProvider implements UserDirectoryProvider, LdapConnec

/** Default LDAP maximum number of objects to query for */
public static final int DEFAULT_BATCH_SIZE = 200;

/** Property of the user object to store the display ID under */
public static final String DISPLAY_ID_PROPERTY = JLDAPDirectoryProvider.class+"-displayId";

/** Property of the user object to store the display Name under */
public static final String DISPLAY_NAME_PROPERTY = JLDAPDirectoryProvider.class+"-displayName";

public static final boolean DEFAULT_ALLOW_AUTHENTICATION = true;

Expand Down Expand Up @@ -175,7 +182,7 @@ public class JLDAPDirectoryProvider implements UserDirectoryProvider, LdapConnec
/** Currently limited to allowing/disallowing searches for particular user EIDs.
* Implements things like user EID blacklists. */
private EidValidator eidValidator;

/**
* Defaults to an anon-inner class which handles {@link LDAPEntry}(ies)
* by passing them to {@link #mapLdapEntryOntoUserData(LDAPEntry)}, the
Expand Down Expand Up @@ -1503,6 +1510,23 @@ public void setAuthenticateWithProviderFirst(
boolean authenticateWithProviderFirst) {
this.authenticateWithProviderFirst = authenticateWithProviderFirst;
}

public String getDisplayId(User user) {
String displayId = user.getProperties().getProperty(DISPLAY_ID_PROPERTY);
if (displayId != null && displayId.length() > 0) {
return displayId;
}
return null;
}

public String getDisplayName(User user) {
String displayName = user.getProperties().getProperty(DISPLAY_NAME_PROPERTY);
if (displayName != null && displayName.length() > 0) {
return displayName;
}
return null;
}


/**
* Access the configured search scope for all filters executed by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,22 @@ protected void mapLdapAttributeOntoUserData(LDAPAttribute attribute,
"][value = " + attrValue + "]");
}
userData.setEmail(attrValue);
} else if ( logicalAttrName.equals(AttributeMappingConstants.DISPLAY_ID_ATTR_MAPPING_KEY) ) {
if ( M_log.isDebugEnabled() ) {
M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to User display Id: " +
"[logical attr name = " + logicalAttrName +
"][physical attr name = " + attribute.getName() +
"][value = " + attrValue + "]");
}
userData.setProperty(JLDAPDirectoryProvider.DISPLAY_ID_PROPERTY, attrValue);
} else if ( logicalAttrName.equals(AttributeMappingConstants.DISPLAY_NAME_ATTR_MAPPING_KEY) ) {
if ( M_log.isDebugEnabled() ) {
M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to User display name: " +
"[logical attr name = " + logicalAttrName +
"][physical attr name = " + attribute.getName() +
"][value = " + attrValue + "]");
}
userData.setProperty(JLDAPDirectoryProvider.DISPLAY_NAME_PROPERTY, attrValue);
} else {
if ( M_log.isDebugEnabled() ) {
M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to a User property: " +
Expand Down

0 comments on commit 9eecfb6

Please sign in to comment.