|
|
|
@ -65,7 +65,7 @@ public class BindAuthenticator extends AbstractLdapAuthenticator { |
|
|
|
String username = authentication.getName(); |
|
|
|
String username = authentication.getName(); |
|
|
|
String password = (String) authentication.getCredentials(); |
|
|
|
String password = (String) authentication.getCredentials(); |
|
|
|
if (!StringUtils.hasLength(password)) { |
|
|
|
if (!StringUtils.hasLength(password)) { |
|
|
|
logger.debug(LogMessage.format("Rejecting empty password for user %s", username)); |
|
|
|
logger.debug(LogMessage.format("Failed to authenticate since no credentials provided")); |
|
|
|
throw new BadCredentialsException( |
|
|
|
throw new BadCredentialsException( |
|
|
|
this.messages.getMessage("BindAuthenticator.emptyPassword", "Empty Password")); |
|
|
|
this.messages.getMessage("BindAuthenticator.emptyPassword", "Empty Password")); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -76,11 +76,18 @@ public class BindAuthenticator extends AbstractLdapAuthenticator { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (user == null) { |
|
|
|
|
|
|
|
logger.debug(LogMessage.of(() -> "Failed to bind with any user DNs " + getUserDns(username))); |
|
|
|
|
|
|
|
} |
|
|
|
// Otherwise use the configured search object to find the user and authenticate
|
|
|
|
// Otherwise use the configured search object to find the user and authenticate
|
|
|
|
// with the returned DN.
|
|
|
|
// with the returned DN.
|
|
|
|
if (user == null && getUserSearch() != null) { |
|
|
|
if (user == null && getUserSearch() != null) { |
|
|
|
|
|
|
|
logger.trace("Searching for user using " + getUserSearch()); |
|
|
|
DirContextOperations userFromSearch = getUserSearch().searchForUser(username); |
|
|
|
DirContextOperations userFromSearch = getUserSearch().searchForUser(username); |
|
|
|
user = bindWithDn(userFromSearch.getDn().toString(), username, password, userFromSearch.getAttributes()); |
|
|
|
user = bindWithDn(userFromSearch.getDn().toString(), username, password, userFromSearch.getAttributes()); |
|
|
|
|
|
|
|
if (user == null) { |
|
|
|
|
|
|
|
logger.debug("Failed to find user using " + getUserSearch()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (user == null) { |
|
|
|
if (user == null) { |
|
|
|
throw new BadCredentialsException( |
|
|
|
throw new BadCredentialsException( |
|
|
|
@ -98,13 +105,12 @@ public class BindAuthenticator extends AbstractLdapAuthenticator { |
|
|
|
DistinguishedName userDn = new DistinguishedName(userDnStr); |
|
|
|
DistinguishedName userDn = new DistinguishedName(userDnStr); |
|
|
|
DistinguishedName fullDn = new DistinguishedName(userDn); |
|
|
|
DistinguishedName fullDn = new DistinguishedName(userDn); |
|
|
|
fullDn.prepend(ctxSource.getBaseLdapPath()); |
|
|
|
fullDn.prepend(ctxSource.getBaseLdapPath()); |
|
|
|
logger.debug(LogMessage.format("Attempting to bind as %s", fullDn)); |
|
|
|
logger.trace(LogMessage.format("Attempting to bind as %s", fullDn)); |
|
|
|
DirContext ctx = null; |
|
|
|
DirContext ctx = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
ctx = getContextSource().getContext(fullDn.toString(), password); |
|
|
|
ctx = getContextSource().getContext(fullDn.toString(), password); |
|
|
|
// Check for password policy control
|
|
|
|
// Check for password policy control
|
|
|
|
PasswordPolicyControl ppolicy = PasswordPolicyControlExtractor.extractControl(ctx); |
|
|
|
PasswordPolicyControl ppolicy = PasswordPolicyControlExtractor.extractControl(ctx); |
|
|
|
logger.debug("Retrieving attributes..."); |
|
|
|
|
|
|
|
if (attrs == null || attrs.size() == 0) { |
|
|
|
if (attrs == null || attrs.size() == 0) { |
|
|
|
attrs = ctx.getAttributes(userDn, getUserAttributes()); |
|
|
|
attrs = ctx.getAttributes(userDn, getUserAttributes()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -112,6 +118,7 @@ public class BindAuthenticator extends AbstractLdapAuthenticator { |
|
|
|
if (ppolicy != null) { |
|
|
|
if (ppolicy != null) { |
|
|
|
result.setAttributeValue(ppolicy.getID(), ppolicy); |
|
|
|
result.setAttributeValue(ppolicy.getID(), ppolicy); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
logger.debug(LogMessage.format("Bound %s", fullDn)); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (NamingException ex) { |
|
|
|
catch (NamingException ex) { |
|
|
|
@ -141,7 +148,7 @@ public class BindAuthenticator extends AbstractLdapAuthenticator { |
|
|
|
* logger. |
|
|
|
* logger. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void handleBindException(String userDn, String username, Throwable cause) { |
|
|
|
protected void handleBindException(String userDn, String username, Throwable cause) { |
|
|
|
logger.debug(LogMessage.format("Failed to bind as %s: %s", userDn, cause)); |
|
|
|
logger.trace(LogMessage.format("Failed to bind as %s", userDn), cause); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|