Authentication of Active Directory via ssl as an anonymous user

I can authenticate Active Directory with a user configured while using ContextSource using Spring -ldap. My Spring xml configuration looks lilke:

<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"> <property name="contextSource" ref="contextSource" /> </bean> <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> <property name="url" value="ldap://xxx.xxx.xxx.xxx:389" /> <property name="userDn" value=" myName@xxx.xxx " /> <property name="password" value="password" /> </bean> 

Java code for user authentication:

 public boolean login(String username, String password) { AndFilter filter = new AndFilter(); this.ldapTemplate.setIgnorePartialResultException(true); // Active Directory doesn't transparently handle referrals. This fixes that. filter.and(new EqualsFilter("objectCategory","****")); filter.and(new EqualsFilter("objectClass","****")); filter.and(new EqualsFilter("sAMAccountName", username)); return this.ldapTemplate.authenticate("OU=myBaseOu,DC=xyz,DC=def", filter.encode(), password); } 

The same thing works with Linux opening Ldap v3, even if I do not set the userDn property and password inside the contextSource bean.

All I need to do is configure this xml so that I can access Active Directory as an anonymous user (without setting userDn and password).

I also need to go through user authentication through SSL. For this I used

 <property name="url" value="ldaps://xxx.xxx.xxx.xxx:636" /> 

but I got an exception like:

 Exception in thread "main" org.springframework.ldap.CommunicationException: simple bind failed: 192.168.0.13:636; nested exception is javax.naming.CommunicationException: simple bind failed: 192.168.0.13:636 [Root exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target] 

Although I got a solution while searching, I need to specify the keystore where the certificates are stored. Here I am not sure where it is (either in the java class or in the XML file).

Your prompt reply will be appreciated. Thanks.

0
source share
2 answers

I did some research and found other applications that have similar problems.

  • Make sure you import your certificates into the keystore according to Connect to LDAP or other SSL services.
  • Ensure that all certificates have been imported to the correct keystore; You may have several JDKs.
+2
source

Some addition to DevZer0's answer to my SSL issue.

Just follow the instructions in this link to get the certificate and put it in the jre \ lib \ security \ folder.

http://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/

+1
source

Source: https://habr.com/ru/post/947448/


All Articles