• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Connection problem with Active Directory

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}

}
 
Ranch Hand
Posts: 85
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

thanks.
vivek
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic