Announcement Announcement Module
Collapse
No announcement yet.
Authenticating with Spring Security Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Authenticating with Spring Security

    I am trying my first demo using Spring Security via connecting to LDAP.

    Sping version I use is:
    <spring.version>3.1.0.RELEASE</spring.version>

    Here is my security-integration.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:security="http://www.springframework.org/schema/security"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
              http://www.springframework.org/schema/security
              http://www.springframework.org/schema/security/spring-security-3.1.xsd">
    
      <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
          <list>
            <value>classpath:com/demo/spring/security.properties</value>
          </list>
        </property>   </bean>
    
      <security:http auto-config='false' access-denied-page="/accessDenied" use-expressions="true">
    
    
        <!--I've removed login."htm"?error=true-->
        <security:form-login
          login-page="/login"
          authentication-failure-url="/login?error=true"
          login-processing-url="/loginProcess"
          default-target-url="/home"/>
    
        <!--<security:logout-->
          <!--invalidate-session="true"-->
          <!--logout-success-url="/login"-->
          <!--logout-url="/logout"/>-->
    
      </security:http>
    
      <bean id="contextSource"
            class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <constructor-arg value="${securityContextSource.url}"/>
        <property name="userDn" value="${securityContextSource.userDn}"/>
        <property name="password" value="${securityContextSource.password}"/>   </bean>
    
      <bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
        <constructor-arg index="0" value="${filterBasedLdapUserSearch.searchBase}"/>
        <constructor-arg index="1" value="${filterBasedLdapUserSearch.searchFilter}"/>
        <constructor-arg index="2" ref="contextSource"/>   </bean>
    
      <bean id="bindAuthenticator" class="org.springframework.security.ldap.authentication.BindAuthenticator">
        <constructor-arg ref="contextSource"/>
        <property name="userSearch" ref="userSearch"/>   </bean>
    
    
        <bean id="ldapAuthProvider"
              class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
          <constructor-arg  ref="bindAuthenticator"/>
        </bean>
    
        <security:authentication-manager>
            <security:authentication-provider ref="ldapAuthProvider"/>
        </security:authentication-manager>
    
    </beans>
    However, I got this exception whenever I deploy my war:

    HTML Code:
    HTTP Status 500
    javax.servlet.ServletException: Servlet.init() for servlet spring threw exception
    	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    	java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    	java.lang.Thread.run(Thread.java:619)
    root cause
    
    org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [com/itworx/govacation/spring/security-integration.xml]; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.config.SecurityNamespaceHandler]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/security/config/method/InternalInterceptMethodsBeanDefinitionDecorator
    	org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
    	org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    	org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    	org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    	org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    	org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    	org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromImportedResources(ConfigurationClassBeanDefinitionReader.java:293)
    	org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:118)
    	org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:105)
    	org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:261)
    	org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:178)
    	org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:617)
    	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
    	org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
    	org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:495)
    	org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
    	org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
    	javax.servlet.GenericServlet.init(GenericServlet.java:160)
    	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    	java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    	java.lang.Thread.run(Thread.java:619)
    root cause
    
    org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.config.SecurityNamespaceHandler]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/security/config/method/InternalInterceptMethodsBeanDefinitionDecorator
    	org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
    	org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
    	org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:129)
    	org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1414)
    	org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409)
    	org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
    	org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
    	org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
    	
    root cause
    
    java.lang.NoClassDefFoundError: org/springframework/security/config/method/InternalInterceptMethodsBeanDefinitionDecorator
    	org.springframework.security.config.method.InterceptMethodsBeanDefinitionDecorator.<init>(InterceptMethodsBeanDefinitionDecorator.java:30)
    	org.springframework.security.config.SecurityNamespaceHandler.<init>(SecurityNamespaceHandler.java:43)
    	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    	org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
    	org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:129)

  • #2
    I have solved this issue by removing a dependency on AOP at my pom file.
    <!--<groupId>org.springframework</groupId>-->
    <!--<artifactId>spring-aop</artifactId>-->

    Comment

    Working...
    X