aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Connection problem with Active Directory " Watch "Connection problem with Active Directory " New topic
Author

Connection problem with Active Directory

Ramesh James
Greenhorn

Joined: Jan 12, 2010
Posts: 3
Hello,
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="org.springframework.security.ldap.DefaultSp ringSecurityContextSource">
<constructor-arg value="ldap://servername.r1-core.r1.xxx.net:389/DC=r1-core,DC=r1,DC=aig,DC=net"/>
<property name="userDn" value="user@r1-core"/>
<property name="password" value="pwwd11"/>
</bean>

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

<bean id="myAuthenticator" class="com.xxx.tax.util.TaxUserAuthenticate">
<property name="ldapTemplate" ref="ldapTemplate"/>
</bean>


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

<!-- LDPA in Spring framework
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapC ontextSource">
<property name="url" value="ldap://servername.r1-core.r1.xxx.net:389/DC=r1-core,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" />
</bean>
-->

/**
*
*/
package com.xxx.tax.util;

import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
import java.io.UnsupportedEncodingException;
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

Hi,

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

thanks.
vivek


SCJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection problem with Active Directory