title: Programmatically Authenticate LDAP user in AEM
body: <p>I've set up local LDAP server
  Created user and group.
  Configured LDAP in AEM config manager and synchronized the users and group.</p>
  
  <p>Using, ExternalIdentityProvider as a service reference, I'm able to get list of LDAP users I.e. I am able to validate if the user is present in LDAP or not.</p>
  
  <p>But, I'm not able to validate user credentials using authentic method of the above mentioned API.</p>
  
  <p>Am I missing any configuration specifics or the approach that I'm using is wrong ?</p>
  
  <p>Updated:</p>
  
  <p>Authentication code:</p>
  
  <pre><code>@Reference
  private ExternalIdentityProviderManager externalIdentityProviderManager;
  
  final String externalId = request.getParameter("externalId");
  final String externalPassword = request.getParameter("externalPassword");
  
  final ExternalIdentityProvider idap = externalIdentityProviderManager.getProvider("ldap");
  final SimpleCredentials credentials = new SimpleCredentials(externalId, externalPassword.toCharArray());
  final ExternalUser externalUser = idap.authenticate(credentials);
  </code></pre>
  
  <p>Error thrown - </p>
  
  <pre><code>javax.security.auth.login.LoginException: Unable to authenticate against LDAP server: INVALID_CREDENTIALS: Bind failed: Attempt to lookup non-existant entry: cn=steve+uid=steve+sn=jobs,dc=example,dc=com
  </code></pre>
  
  <p>Update:
  Identity provider config</p>
  
  <pre><code># Configuration created by Apache Sling JCR Installer
  userPool.maxActive=L"8"
  searchTimeout="60s"
  host.name="localhost"
  customattributes=[""]
  adminPool.maxActive=L"8"
  group.makeDnPath=B"false"
  user.baseDN="ou\=Users,dc\=example,dc\=com"
  group.objectclass=["groupOfNames"]
  user.objectclass=["person"]
  userPool.lookupOnValidate=B"true"
  host.noCertCheck=B"false"
  user.makeDnPath=B"true"
  bind.dn="uid\=admin,ou\=system"
  group.baseDN="ou\=Groups,dc\=example,dc\=com"
  group.extraFilter=""
  user.extraFilter=""
  host.port=I"10389"
  bind.password="secret"
  adminPool.lookupOnValidate=B"true"
  useUidForExtId=B"false"
  group.nameAttribute="cn"
  provider.name="ldap"
  host.ssl=B"false"
  host.tls=B"false"
  user.idAttribute="uid"
  group.memberAttribute="member"
  </code></pre>
  
  <p>Sync Handler</p>
  
  <pre><code># Configuration created by Apache Sling JCR Installer
  group.pathPrefix=""
  user.dynamicMembership=B"false"
  group.expirationTime="1d"
  user.membershipExpTime="1h"
  user.pathPrefix=""
  user.propertyMapping=["profile/nt:primaryType\=\"nt:unstructured\"","profile/givenName\=cn","profile/rep:password\=userPassword"]
  handler.name="syncHandlerDefault"
  enableRFC7613UsercaseMappedProfile=B"false"
  user.autoMembership=[""]
  user.expirationTime="1h"
  group.propertyMapping=[""]
  group.autoMembership=[""]
  user.disableMissing=B"false"
  user.membershipNestingDepth=I"3"
  </code></pre>
  
  <p>External login</p>
  
  <pre><code># Configuration created by Apache Sling JCR Installer
  jaas.controlFlag="SUFFICIENT"
  jaas.ranking=I"50"
  sync.handlerName="syncHandlerDefault"
  jaas.realmName=""
  idp.name="ldap"
  </code></pre>
  
  <p>LDIF file for users</p>
  
  <pre><code>version: 1
  
  dn: ou=Users,dc=example,dc=com
  objectClass: organizationalUnit
  objectClass: top
  ou: Users
  
  dn: cn=eden+sn=hazard+uid=eden,ou=Users,dc=example,dc=com
  objectClass: uidObject
  objectClass: person
  objectClass: top
  cn: eden
  sn: hazard
  uid: eden
  userPassword: {SSHA}O/t6ZRnWZTLhHla106Hp5nIWy85b0kgwNmeY3w==
  
  dn: cn=rohit+sn=sharma+uid=rohit,ou=Users,dc=example,dc=com
  objectClass: uidObject
  objectClass: person
  objectClass: top
  cn: rohit
  sn: sharma
  uid: rohit
  userPassword: {SSHA}9fzIkizxYg3LGG8n0jf/tnpv//qiNlxtS6mnWg==
  
  dn: cn=harry+uid=harry+sn=kane,ou=Users,dc=example,dc=com
  objectClass: uidObject
  objectClass: person
  objectClass: top
  cn: harry
  sn: kane
  uid: harry
  userPassword: {SSHA}WjNxB0ZDsmKfpjN0zwgsvDtZ4c/lHrIZXb7T2g==
  
  dn: cn=cristiano+uid=cristiano+sn=ronaldo,ou=Users,dc=example,dc=com
  objectClass: uidObject
  objectClass: person
  objectClass: top
  cn: cristiano
  sn: ronaldo
  uid: cristiano
  userPassword: {SSHA}ykzpMLVAbK99hfbCwwGgmgcDVzDV/Kfl0TlA8Q==
  </code></pre>