Skip to content

Commit

Permalink
Add a hack to work-around JENKINS-22247
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Mar 27, 2014
1 parent df5d37c commit 64fcf64
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/hudson/security/LDAPSecurityRealm.java
Expand Up @@ -226,6 +226,8 @@
public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
private static final String DEFAULT_DISPLAYNAME_ATTRIBUTE_NAME = "displayname";
private static final String DEFAULT_MAILADDRESS_ATTRIBUTE_NAME = "mail";
private static final boolean FORCE_USERNAME_LOWERCASE =
Boolean.getBoolean(LDAPSecurityRealm.class.getName() + ".forceUsernameLowercase");
/**
* LDAP server name(s) separated by spaces, optionally with TCP port number, like "ldap.acme.org"
* or "ldap.acme.org:389" and/or with protcol, like "ldap://ldap.acme.org".
Expand Down Expand Up @@ -561,15 +563,16 @@ public SecurityComponents createSecurityComponents() {
@Override
protected UserDetails authenticate(String username, String password) throws AuthenticationException {
return updateUserDetails((UserDetails) getSecurityComponents().manager.authenticate(
new UsernamePasswordAuthenticationToken(username, password)).getPrincipal());
new UsernamePasswordAuthenticationToken(FORCE_USERNAME_LOWERCASE ? username.toLowerCase() : username, password)).getPrincipal());
}

/**
* {@inheritDoc}
*/
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
return updateUserDetails(getSecurityComponents().userDetails.loadUserByUsername(username));
return updateUserDetails(getSecurityComponents().userDetails.loadUserByUsername(
FORCE_USERNAME_LOWERCASE ? username.toLowerCase() : username));
}

public Authentication updateUserDetails(Authentication authentication) {
Expand All @@ -585,7 +588,8 @@ public UserDetails updateUserDetails(UserDetails userDetails) {
}

public LdapUserDetails updateUserDetails(LdapUserDetails d) {
hudson.model.User u = hudson.model.User.get(d.getUsername());
hudson.model.User u = hudson.model.User.get(
FORCE_USERNAME_LOWERCASE ? d.getUsername().toLowerCase() : d.getUsername());
try {
Attribute attribute = d.getAttributes().get(getDisplayNameAttributeName());
String displayName = attribute == null ? null : (String) attribute.get();
Expand Down

0 comments on commit 64fcf64

Please sign in to comment.