Announcement Announcement Module
Collapse
No announcement yet.
Spring and Security 3.1.0.RELEASE with LDAP 1.3.1.RELEASE - SecurityContextHolder Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring and Security 3.1.0.RELEASE with LDAP 1.3.1.RELEASE - SecurityContextHolder

    I tried to generate a new app using ROO and it configured the pom to use the latest and greatest versions. Unfortunately, the same bean definitions I am using in another project with older versions no longer works - when I try to run a main() method as a Java Application, I get the following error:

    Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/security/core/context/SecurityContextHolder
    	at org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource.getPrincipal(SpringSecurityAuthenticationSource.java:32)
    	at org.springframework.ldap.authentication.DefaultValuesAuthenticationSourceDecorator.getPrincipal(DefaultValuesAuthenticationSourceDecorator.java:96)
    	at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:125)
    	at org.springframework.ldap.core.LdapTemplate.executeReadOnly(LdapTemplate.java:792)
    	at org.springframework.ldap.core.LdapTemplate.lookup(LdapTemplate.java:876)
    	at org.springframework.ldap.core.simple.SimpleLdapTemplate.lookup(SimpleLdapTemplate.java:180)
    	at com.qualcomm.corp.isso.cis.ldap.dao.LdapDAOBase.findByPrimaryKey(LdapDAOBase.java:83)
    	at com.qualcomm.corp.isso.cis.ldap.operations.GetPerson.invoke(GetPerson.java:194)
    	at com.qualcomm.corp.isso.cis.ldap.operations.GetPerson.main(GetPerson.java:31)
    Caused by: java.lang.ClassNotFoundException: org.springframework.security.core.context.SecurityContextHolder
    Here are the versions I'm using in the POM:

    Code:
            
            <java.version>1.6</java.version>
    	<org.springframework.ldap-version>1.3.1.RELEASE</org.springframework.ldap-version>
    	<org.springframework.security-version>3.1.0.RELEASE</org.springframework.security-version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <slf4j.version>1.6.2</slf4j.version>
            <spring.version>3.1.0.RELEASE</spring.version>
    And here is the applicationContext-ldap.xml file that is being imported into my primary applicationContext.xml file:
    Code:
    	<!-- http://static.springsource.org/spring-ldap/site/reference/html/configuration.html#context-source-configuration -->
    	<!-- Basic DataSource -->
    	<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"
    		p:url="${ldap.url}"
    		p:base="${ldap.base}"
    		p:authenticationSource-ref="authenticationSource"
    	/>
    
    	<bean id="authenticationSource" class="org.springframework.ldap.authentication.DefaultValuesAuthenticationSourceDecorator"
    		p:target-ref="springSecurityAuthenticationSource"
    		p:defaultUser="${ldap.user}"
    		p:defaultPassword="${ldap.pw}"
    	/>
    
    	<bean id="springSecurityAuthenticationSource"
    		class="org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource" />
    
    	<bean class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
    
    	<bean id="simpleLdapTemplate" class="org.springframework.ldap.core.simple.SimpleLdapTemplate">
    		<constructor-arg ref="contextSource" />
    	</bean>
    For now I'm going to revert to the older versions so that I can get my application to run but I would love to know what is wrong with the configuration for the newer versions -- or is there a bug in the latest and greatest code?

    NOTE: I googled for this error and I saw that this can occur if the app is using another library which is compiled against Spring Security 2. The pom's Dependency Hierarchy does not indicate that any older versions are being used. It may also be useful to note that we are using spring-ldap-core-tiger in the app...

  • #2
    In general a ClassNotFoundException means that the class cannot be found on your classpath. Did you ensure to include spring-security-core in the classpath? If in the future you have trouble figuring out which jar contains the class you are missing try using http://search.maven.org You can use the advanced search to search by class name as shown by this query it would tell you which jar you were missing. Note this would work for any class in maven central.

    Comment


    • #3
      You're awesome! That handled it! I only had spring-security-ldap which excluded spring-seciryt-core. sigh.

      Comment

      Working...
      X