Source:
public AuthenticationResult validateCredentials( String authenticatorName, String authorizerName, String username, char[] password ) { Set<LdapName> groups; LdapName userDn; Map<String, Object> contexMap = new HashMap<>(); BasicAuthenticatorUserPrincipal principal = this.cache.getOrExpire(username); if (principal != null && principal.hasSameCredentials(password)) { contexMap.put(BasicAuthUtils.GROUPS_CONTEXT_KEY, principal.getGroups()); return new AuthenticationResult(username, authorizerName, authenticatorName, contexMap); } else { try { InitialDirContext dirContext = new InitialDirContext(bindProperties(this.ldapConfig)); try { SearchResult userResult = getLdapUserObject(this.ldapConfig, dirContext, username); if (userResult == null) { LOG.debug("User not found: %s", username); return null; } userDn = new LdapName(userResult.getNameInNamespace()); groups = getGroupsFromLdap(this.ldapConfig, userResult); } finally { try { dirContext.close(); } catch (Exception ignored) { } } } catch (NamingException e) { LOG.error(e, "Exception during user lookup"); return null; } if (!validatePassword(this.ldapConfig, userDn, password)) { LOG.debug("Password incorrect for user %s", username); throw new BasicSecurityAuthenticationException("User LDAP authentication failed username[%s].", userDn.toString()); } byte[] salt = BasicAuthUtils.generateSalt(); byte[] hash = BasicAuthUtils.hashPassword(password, salt, this.ldapConfig.getCredentialIterations()); BasicAuthenticatorUserPrincipal newPrincipal = new BasicAuthenticatorUserPrincipal( username, new BasicAuthenticatorCredentials(salt, hash, this.ldapConfig.getCredentialIterations()), groups ); this.cache.put(username, newPrincipal); contexMap.put(BasicAuthUtils.GROUPS_CONTEXT_KEY, groups); return new AuthenticationResult(username, authorizerName, authenticatorName, contexMap); } }

Target:
public AuthenticationResult validateCredentials( String authenticatorName, String authorizerName, String username, char[] password ) { SearchResult userResult; LdapName userDn; Map<String, Object> contextMap = new HashMap<>(); LdapUserPrincipal principal = this.cache.getOrExpire(username); if (principal != null && principal.hasSameCredentials(password)) { contextMap.put(BasicAuthUtils.SEARCH_RESULT_CONTEXT_KEY, principal.getSearchResult()); return new AuthenticationResult(username, authorizerName, authenticatorName, contextMap); } else { try { InitialDirContext dirContext = new InitialDirContext(bindProperties(this.ldapConfig)); try { userResult = getLdapUserObject(this.ldapConfig, dirContext, username); if (userResult == null) { LOG.debug("User not found: %s", username); return null; } userDn = new LdapName(userResult.getNameInNamespace()); } finally { try { dirContext.close(); } catch (Exception ignored) { } } } catch (NamingException e) { LOG.error(e, "Exception during user lookup"); return null; } if (!validatePassword(this.ldapConfig, userDn, password)) { LOG.debug("Password incorrect for LDAP user %s", username); throw new BasicSecurityAuthenticationException("User LDAP authentication failed username[%s].", userDn.toString()); } byte[] salt = BasicAuthUtils.generateSalt(); byte[] hash = BasicAuthUtils.hashPassword(password, salt, this.ldapConfig.getCredentialIterations()); LdapUserPrincipal newPrincipal = new LdapUserPrincipal( username, new BasicAuthenticatorCredentials(salt, hash, this.ldapConfig.getCredentialIterations()), userResult ); this.cache.put(username, newPrincipal); contextMap.put(BasicAuthUtils.SEARCH_RESULT_CONTEXT_KEY, userResult); return new AuthenticationResult(username, authorizerName, authenticatorName, contextMap); } }