CAS Server
  1. CAS Server
  2. CAS-1030

FastBindLdapAuthenticationHandler spring config fails without ldapTemplate which is required, but isn't used

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.4.9
    • Fix Version/s: 3.4.10
    • Component/s: LDAP
    • Labels:
      None

      Description

      for this spring config:

      <bean id="ldap.auth.handler" class="org.jasig.cas.adaptors.ldap.FastBindLdapAuthenticationHandler">
      <property name="filter" value="$

      {ldap.dn.authenticate}

      " />
      <property name="contextSource">
      <bean class="org.springframework.ldap.core.support.LdapContextSource">
      <property name="urls">
      <bean class="org.apache.commons.lang.StringUtils" factory-method="split">
      <constructor-arg value="$

      {ldap.url}

      " />
      <constructor-arg value="," />
      </bean>
      </property>
      <property name="userDn" value="$

      {ldap.userdn}

      " />
      <property name="password" value="$

      {ldap.password}

      " />
      <property name="baseEnvironmentProperties">
      <map>
      <entry key="java.naming.security.authentication" value="simple" />
      <entry key="com.sun.jndi.ldap.connect.timeout" value="2000" />
      <entry key="com.sun.jndi.ldap.read.timeout" value="2000" />
      </map>
      </property>
      <property name="pooled" value="false" />
      </bean>
      </property>
      </bean>

      I get the following error:

      2011-08-09 14:56:28,437 ERROR [org.apache.struts2.spring.StrutsSpringObjectFactory] - <Error creating bean with name 'ldap.auth.handler' defined in ServletContext resource [/WEB-INF/spring-configuration/thekey-ldap.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Bean state is invalid: ldapTemplate - may not be null>
      2011-08-09 14:56:28,449 ERROR [org.apache.struts2.dispatcher.Dispatcher] - <Dispatcher initialization failed>
      java.lang.NullPointerException
      at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:220)
      at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType(XmlConfigurationProvider.java:530)
      at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addResultTypes(XmlConfigurationProvider.java:501)
      at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:457)
      at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:275)
      at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
      at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
      at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
      at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:380)
      at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:424)
      at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:195)
      at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:273)
      at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:254)
      at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
      at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
      at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4542)
      at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5220)
      at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5215)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:680)

      The actual code for FastBindLdapAuthenticationHandler never utilizes the ldapTemplate set in the Abstract class. And it looks like there is code in afterPropertiesSet that should set it if it isn't set already, javax.validation must run before the spring afterPropertiesSet method. removing the @NotNull annotation from ldapTemplate should fix the bug.

        Activity

        Hide
        Daniel Frett added a comment -

        By default validation is performed before bean init, it can be changed by setting afterInitialization on the validationAnnotationBeanPostProcessor. This patch makes that change, this may have side effects because it does change the initialization/validation flow for all beans.

        http://static.springsource.org/spring/docs/3.0.5.RELEASE/javadoc-api/org/springframework/validation/beanvalidation/BeanValidationPostProcessor.html#setAfterInitialization(boolean)

        Show
        Daniel Frett added a comment - By default validation is performed before bean init, it can be changed by setting afterInitialization on the validationAnnotationBeanPostProcessor. This patch makes that change, this may have side effects because it does change the initialization/validation flow for all beans. http://static.springsource.org/spring/docs/3.0.5.RELEASE/javadoc-api/org/springframework/validation/beanvalidation/BeanValidationPostProcessor.html#setAfterInitialization(boolean )

          People

          • Assignee:
            Scott Battaglia
            Reporter:
            Daniel Frett
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: