Skip to content

Commit

Permalink
JENKINS-32033 Support for multiple domain controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
fbelzunc committed Sep 16, 2016
1 parent 2e79649 commit fbbb85c
Showing 1 changed file with 9 additions and 5 deletions.
Expand Up @@ -518,7 +518,8 @@ public DirContext bind(String principalName, String password, List<SocketInfo> l
newProps.put("java.naming.ldap.attributes.binary","tokenGroups objectSid");
newProps.put("java.naming.ldap.factory.socket",TrustAllSocketFactory.class.getName());
newProps.putAll(props);
NamingException error = null;
NamingException namingException = null;
javax.naming.AuthenticationException authenticationException = null;

for (SocketInfo ldapServer : ldapServers) {
try {
Expand All @@ -537,15 +538,18 @@ public DirContext bind(String principalName, String password, List<SocketInfo> l
// servers can be configured to hide the distinction between "no such user" and "bad password"
// to reveal what user names are available.
LOGGER.log(Level.WARNING, "Failed to authenticate while binding to "+ldapServer, e);
throw new BadCredentialsException("Either no such user '"+principalName+"' or incorrect password",e);
authenticationException = e; // retry
} catch (NamingException e) {
LOGGER.log(Level.WARNING, "Failed to bind to "+ldapServer, e);
error = e; // retry
namingException = e; // retry
}
}

// if all the attempts failed
throw new BadCredentialsException("Either no such user '"+principalName+"' or incorrect password", error);
if (authenticationException !=null ) {
throw new BadCredentialsException("Either no such user '" + principalName + "' or incorrect password", authenticationException);
} else {
throw new BadCredentialsException("Either no such user '" + principalName + "' or incorrect password", namingException);
}
}

/**
Expand Down

0 comments on commit fbbb85c

Please sign in to comment.