Skip to content
Permalink
Browse files

Add a hack to work-around JENKINS-22247

  • Loading branch information
stephenc committed Mar 27, 2014
1 parent df5d37c commit 64fcf64850a2dd3ab668887212264f880f45042b
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/main/java/hudson/security/LDAPSecurityRealm.java
@@ -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".
@@ -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) {
@@ -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();

0 comments on commit 64fcf64

Please sign in to comment.
You can’t perform that action at this time.