Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use Spring LDAP with Spring Security

I want to authenticate users against our AD so I understand that I need spring security and spring ldap.

Here is what is in my POM:

<groupId>org.springframework.security</groupId>
<artifactId>org.springframework.security.core</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
...
<dependency>
    <groupId>org.springframework.ldap</groupId>
    <artifactId>spring-ldap</artifactId>
    <version>1.3.0.RELEASE</version>
    <type>pom</type>
    <scope>provided</scope>
</dependency>

Here are the respective entries from my secruity-context:

<ldap-authentication-provider user-dn-pattern="CN=0},OU=CAN,OU=NOT,OU=TELL,OU=YOU"/>
    ..  
<!-- LDAP Security Configuration -->
<ldap-server url="ldap://10.9.1.1:389/DC=TELL,DC=YOU"/>

However when I run my application using:

mvn jetty:run

I get following error:

If you are using LDAP with Spring Security, please ensure that you include the spring-ldap jar file in your application; nested exception is java.lang.ClassNotFoundException: org.springframework.ldap.core.support.BaseLdapPathContextSource:
java.lang.ClassNotFoundException: org.springframework.ldap.core.support.BaseLdapPathContextSource
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195)
    at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255)
    at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:274)
    at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:375)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:258)
    at org.springframework.security.config.ldap.ContextSourceSettingPostProcessor.postProcessBeanFactory(ContextSourceSettingPostProcessor.java:33)
like image 391
er4z0r Avatar asked Dec 09 '22 17:12

er4z0r


1 Answers

A dependency of type pom won't provide any classes. Use this dependency instead:

<dependency>
  <groupId>org.springframework.ldap</groupId>
  <artifactId>spring-ldap-core</artifactId>
  <version>1.3.0.RELEASE</version>
</dependency>

This artifact contains the o.s.l.c.s.BaseLdapPathContextSource class which is currently missing.

like image 64
Pascal Thivent Avatar answered Dec 26 '22 02:12

Pascal Thivent