/** * Initialize the handler, setup the authentication entry attributes. */ public void initialize() { /* * Use a set to ensure we ignore duplicates. */ val attributes = new HashSet<String>(); LOGGER.debug("Initializing LDAP attribute configuration..."); if (StringUtils.isNotBlank(this.principalIdAttribute)) { LOGGER.debug("Configured to retrieve principal id attribute [{}]", this.principalIdAttribute); attributes.add(this.principalIdAttribute); } if (this.principalAttributeMap != null && !this.principalAttributeMap.isEmpty()) { val attrs = this.principalAttributeMap.keySet(); attributes.addAll(attrs); LOGGER.debug("Configured to retrieve principal attribute collection of [{}]", attrs); } if (authenticator.getReturnAttributes() != null) { val authenticatorAttributes = CollectionUtils.wrapList(authenticator.getReturnAttributes()); if (!authenticatorAttributes.isEmpty()) { LOGGER.debug("Filtering authentication entry attributes [{}] based on authenticator attributes [{}]", authenticatedEntryAttributes, authenticatorAttributes); attributes.removeIf(authenticatorAttributes::contains); } } this.authenticatedEntryAttributes = attributes.toArray(ArrayUtils.EMPTY_STRING_ARRAY); LOGGER.debug("LDAP authentication entry attributes for the authentication request are [{}]", (Object[]) this.authenticatedEntryAttributes); } }
@Override public String toString() { return String.format( "[%s@%d::dnResolver=%s, authenticationHandler=%s, entryResolver=%s, returnAttributes=%s, " + "authenticationResponseHandlers=%s]", getClass().getName(), hashCode(), getDnResolver(), getAuthenticationHandler(), getEntryResolver(), Arrays.toString(getReturnAttributes()), Arrays.toString(getAuthenticationResponseHandlers())); } }
@Override public String toString() { return String.format( "[%s@%d::dnResolver=%s, authenticationHandler=%s, entryResolver=%s, returnAttributes=%s, " + "authenticationResponseHandlers=%s]", getClass().getName(), hashCode(), getDnResolver(), getAuthenticationHandler(), getEntryResolver(), Arrays.toString(getReturnAttributes()), Arrays.toString(getAuthenticationResponseHandlers())); } }
private AuthenticationResponse getLdapAuthenticationResponse(final UsernamePasswordCredential upc) throws PreventedException { try { LOGGER.debug("Attempting LDAP authentication for [{}]. Authenticator pre-configured attributes are [{}], " + "additional requested attributes for this authentication request are [{}]", upc, authenticator.getReturnAttributes(), authenticatedEntryAttributes); val request = new AuthenticationRequest(upc.getUsername(), new org.ldaptive.Credential(upc.getPassword()), authenticatedEntryAttributes); return authenticator.authenticate(request); } catch (final LdapException e) { LOGGER.trace(e.getMessage(), e); throw new PreventedException("Unexpected LDAP error", e); } }