Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken toke
// Binds using the username and password provided by the user.
LdapContext ctx = null;
try {
ctx = ldapContextFactory.getLdapContext(upToken.getUsername(), String.valueOf(upToken.getPassword()));
ctx = ldapContextFactory.getLdapContext(getUsernameWithSuffix(upToken.getUsername()),
String.valueOf(upToken.getPassword()));
} finally {
LdapUtils.closeContext(ctx);
}
Expand Down Expand Up @@ -166,11 +167,7 @@ protected Set<String> getRoleNamesForUser(String username, LdapContext ldapConte
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

String userPrincipalName = username;
if (principalSuffix != null
&& !userPrincipalName.toLowerCase(Locale.ROOT).endsWith(principalSuffix.toLowerCase(Locale.ROOT))) {
userPrincipalName += principalSuffix;
}
String userPrincipalName = getUsernameWithSuffix(username);

Object[] searchArguments = new Object[] {userPrincipalName};

Expand Down Expand Up @@ -236,4 +233,12 @@ protected Collection<String> getRoleNamesForGroups(Collection<String> groupNames
return roleNames;
}

protected String getUsernameWithSuffix(String username) {
if (principalSuffix != null
&& !username.toLowerCase(Locale.ROOT).endsWith(principalSuffix.toLowerCase(Locale.ROOT))) {
return username + principalSuffix;
}
return username;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ public abstract class AbstractLdapRealm extends AuthorizingRealm {
| M E T H O D S |
============================================*/

/**
* Used when initializing the default {@link LdapContextFactory}. This property is ignored if a custom
* <tt>LdapContextFactory</tt> is specified.
*
* @param principalSuffix the suffix.
*/
public void setPrincipalSuffix(String principalSuffix) {
this.principalSuffix = principalSuffix;
}

/**
* Used when initializing the default {@link LdapContextFactory}. This property is ignored if a custom
Expand Down