File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Connection problem with Active Directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Connection problem with Active Directory " Watch "Connection problem with Active Directory " New topic

Connection problem with Active Directory

Ramesh James

Joined: Jan 12, 2010
Posts: 3
I am bit fresher to Spring-Security/LDAP. Here I am try to connect to my company's Active directory server through Spring Security, but I am getting null for ldapTemplate in my TaxUserAuthenticate class which mean I am not able to connect to AD. Please find the below code. I am sure there must be problem in my configuration file however I am not able to figure out the problem. I have writen the below piece of code in /WEB-INF/tax-servlet.xml which used for my Spring MVC web application.

Thanks for your help.

<bean id="contextSource" class=" ringSecurityContextSource">
<constructor-arg value="ldap://,DC=r1,DC=aig,DC=net"/>
<property name="userDn" value="user@r1-core"/>
<property name="password" value="pwwd11"/>

<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate" >
<constructor-arg ref="contextSource" />

<bean id="myAuthenticator" class="">
<property name="ldapTemplate" ref="ldapTemplate"/>

I also tried to write the code in below way to connect but hard luck.

<!-- LDPA in Spring framework
<bean id="contextSource" class=" ontextSource">
<property name="url" value="ldap://,DC=r1,DC=aig,DC=net?sAMAccountName?sub?(objec tClass=*)" />
<property name="base" value="OU=R1,DC=r1-core,DC=r1,DC=xxx,DC=net" />
<property name="userDn" value="user@r1-core" />
<property name="password" value="pwwd11" />


import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
import org.springframework.ldap.core.DistinguishedName;

public class TaxUserAuthenticate {
private LdapTemplate ldapTemplate;

public void setLdapTemplate(final LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;

public TaxUserAuthenticate() {
// TODO Auto-generated constructor stub

public boolean login(String username, String password){
System.out.println("****username*****"+username+"* ********");
System.out.println("****password*****"+password+"* ********");
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("cn", username));
return ldapTemplate.authenticate(DistinguishedName.EMPTY_ PATH, filter.toString(), password);

Vivek K Singh
Ranch Hand

Joined: Dec 22, 2009
Posts: 85


Please use code tags for code samples. Also can you send the exception you are getting while making this call ?


I agree. Here's the link:
subject: Connection problem with Active Directory