Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for LDAP to pull all attributes for user entry #259

Merged
merged 2 commits into from Jun 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/main/java/org/mamute/auth/LDAPApi.java
Expand Up @@ -13,6 +13,7 @@
import javax.inject.Inject;
import javax.naming.directory.InvalidAttributeValueException;

import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.cursor.EntryCursor;
import org.apache.directory.api.ldap.model.entry.Attribute;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class LDAPApi {
public static final String LDAP_USER_OBJECTCLASS = "ldap.userObjectClass";
public static final String LDAP_LOOKUP = "ldap.lookupAttr";
public static final String LDAP_MODERATOR_GROUP = "ldap.moderatorGroup";
public static final String LDAP_LOOKUP_ALL_ATTR = "ldap.lookupAllAttr";
public static final String LDAP_SSO = "ldap.sso";
public static final String PLACHOLDER_PASSWORD = "ldap-password-ignore-me";
public static final String LDAP_USE_SSL = "ldap.useSSL";
Expand All @@ -79,6 +81,14 @@ public class LDAPApi {
private String[] lookupAttrs;
private String userObjectClass;
private String moderatorGroup;

/**
* If set to true, then all attributes are pulled for the LDAP entry associated with the user.
* This uses the <code>SchemaConstants.ALL_ATTRIBUTES_ARRAY</code> constant. If false, the
* normal lookup is performed, which will bring back user attributes but not necessarily
* operational attributes from the LDAP server.
*/
private Boolean lookupAllAttr;
private Boolean useSsl;
private String avatarImageAttr;

Expand All @@ -102,6 +112,7 @@ public void init() {
surnameAttr = env.get(LDAP_SURNAME, "");
groupAttr = env.get(LDAP_GROUP, "");
moderatorGroup = env.get(LDAP_MODERATOR_GROUP, "");
lookupAllAttr = env.supports(LDAP_LOOKUP_ALL_ATTR);
lookupAttrs = env.get(LDAP_LOOKUP, "").split(",");
userObjectClass = env.get(LDAP_USER_OBJECTCLASS, "user");
useSsl = env.supports(LDAP_USE_SSL);
Expand Down Expand Up @@ -302,7 +313,11 @@ private List<String> getGroups(Entry user) {
}

private Entry getUser(String cn) throws LdapException {
return connection.lookup(cn);
if (lookupAllAttr) {
return connection.lookup(cn, SchemaConstants.ALL_ATTRIBUTES_ARRAY);
} else {
return connection.lookup(cn);
}
}

private Entry lookupUser(String username) throws LdapException {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/mamute.properties
Expand Up @@ -129,6 +129,8 @@ ldap.nameAttr=givenName
ldap.surnameAttr=sn
ldap.userDn=OU=Users,DC=company,DC=com
ldap.moderatorGroup=CN=Moderators,OU=Groups,DC=company,DC=com
ldap.lookupAllAttr=false
#ldap.userObjectClass=inetOrgPerson
#ldap.lookupAttr=mail
ldap.useSSL=false

Expand Down