title: Moving Spring Web Project using LDAP Authentication and Authorities to Spring and CAS
body: <p>I am trying to move a Spring Web Project using LDAP for Authentication and Authorities to Spring and CAS. My project was working great using LDAP but now I have to use CAS.. Once I changed the XML file everything stopped.</p>
  
  <p>XML using LDAP:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
      xmlns:jee="http://www.springframework.org/schema/jee"
  
      xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
             http://www.springframework.org/schema/jdbc
             http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
             http://www.springframework.org/schema/security
             http://www.springframework.org/schema/security/spring-security-3.1.xsd
             http://www.springframework.org/schema/jee 
             http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
             "
      xmlns="http://www.springframework.org/schema/security"&gt;
  
      &lt;http auto-config="true" use-expressions="true"&gt;
  
  
  
          &lt;intercept-url access="hasRole('ROLE_MEMBER_INQUIRY')"
              pattern="/requests/**" /&gt;
  
          &lt;form-login default-target-url="/requests/add.html" /&gt;
  
      &lt;/http&gt;
  
      &lt;authentication-manager&gt;
  
          &lt;ldap-authentication-provider
              user-search-base="ou=webusers" user-search-filter="(uid={0})"&gt;
  
              &lt;password-compare&gt;
  
                  &lt;password-encoder ref="passwordEncoder"&gt;
                  &lt;/password-encoder&gt;
              &lt;/password-compare&gt;
          &lt;/ldap-authentication-provider&gt;
      &lt;/authentication-manager&gt;
  
      &lt;beans:bean id="passwordEncoder"
          class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="contextSource"
          class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"&gt;
  
          &lt;beans:constructor-arg
              value="ldaps://dvldap01.uftwf.dev:636/dc=uftwf,dc=dev" /&gt;
  
          &lt;beans:property name="userDn" value="cn=Manager,dc=uftwf,dc=dev" /&gt;
  
          &lt;beans:property name="password" value="uftwf" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="ldapAuthProvider"
          class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"&gt;
  
          &lt;beans:constructor-arg&gt;
  
              &lt;beans:bean
                  class="org.springframework.security.ldap.authentication.BindAuthenticator"&gt;
                  &lt;beans:constructor-arg ref="contextSource" /&gt;
                  &lt;beans:property name="userDnPatterns"&gt;
                      &lt;beans:list&gt;
                          &lt;beans:value&gt;
                              uid={0},ou=webusers
                          &lt;/beans:value&gt;
                      &lt;/beans:list&gt;
                  &lt;/beans:property&gt;
              &lt;/beans:bean&gt;
          &lt;/beans:constructor-arg&gt;
          &lt;beans:constructor-arg&gt;
              &lt;beans:bean
                  class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator"&gt;
                  &lt;beans:constructor-arg ref="contextSource" /&gt;
                  &lt;beans:constructor-arg value="ou=groups" /&gt;
                  &lt;beans:property name="groupRoleAttribute" value="ou" /&gt;
              &lt;/beans:bean&gt;
          &lt;/beans:constructor-arg&gt;
      &lt;/beans:bean&gt;
      &lt;ldap-server url="ldaps://dvldap01.uftwf.dev:636/dc=uftwf,dc=dev" /&gt;
      &lt;beans:bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;beans:property name="location" value="classpath:jdbc.properties2" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
          &gt; &lt;beans:property name="driverClassName" value="${database.driver}" /&gt; &lt;beans:property 
          name="url" value="${database.url}" /&gt; &lt;beans:property name="username" value="${database.user}" 
          /&gt; &lt;beans:property name="password" value="${database.password}" /&gt; &lt;beans:property 
          name="initialSize" value="5" /&gt; &lt;beans:property name="maxActive" value="10" 
          /&gt; &lt;/beans:bean&gt;
  
      &lt;!-- 
          &lt;beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
          &gt; &lt;beans:property name="driverClassName" value="${database.driver}" /&gt; &lt;beans:property 
          name="url" value="${database.url}" /&gt; &lt;beans:property name="username" value="${database.user}" 
          /&gt; &lt;beans:property name="password" value="${database.password}" /&gt; &lt;beans:property 
          name="initialSize" value="5" /&gt; &lt;beans:property name="maxActive" value="10" 
          /&gt; &lt;/beans:bean&gt; 
  
  
  
      &lt;jee:jndi-lookup id="dataSourcejndi" jndi-name="dataSourcejndi"
          lookup-on-startup="false" proxy-interface="javax.sql.DataSource"
          cache="true" resource-ref="true" /&gt;
  
  
  
      &lt;beans:bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
          lazy-init="true"&gt;
          &lt;beans:property name="dataSource" ref="dataSourcejndi" /&gt;
      &lt;/beans:bean&gt;
  
  
  
  
      &lt;beans:bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
    &lt;beans:property name="jndiName" value="java:dataSourcejndi" /&gt; 
  &lt;/beans:bean&gt;   
  
  
  
      &lt;beans:bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
          &lt;beans:property name="jndiName" value="java:comp/env/jdbc/mi"/&gt;
      &lt;/beans:bean&gt;
  
          &lt;mvc:annotation-driven /&gt;
  
  --&gt;
  
  
      &lt;!-- &lt;beans:bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
    &lt;beans:property name="jndiName" value="java:dataSourcejndi" /&gt; 
  &lt;/beans:bean&gt;   
   --&gt;
  
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>XML using CAS:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:sec="http://www.springframework.org/schema/security"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:util="http://www.springframework.org/schema/util"
         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
                          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"&gt;
  
  
                          &lt;http auto-config="true" use-expressions="true"&gt;
  
  
  
          &lt;intercept-url access="hasRole('ROLE_MEMBER_INQUIRY')"
              pattern="/requests/**" /&gt;
  
          &lt;form-login default-target-url="/requests/add.html" /&gt;
  
      &lt;/http&gt;
  
      &lt;bean id="securityFilter" class="org.springframework.security.util.FilterChainProxy"&gt;
          &lt;sec:filter-chain-map path-type="ant"&gt;
              &lt;sec:filter-chain pattern="/images/**" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/css/**" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/js/**" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/403.jsp" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/404.jsp" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/error.jsp" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/**/cas/changePassword.htm*" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/**/cas/login.htm*" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/**/cas/passwordExpired.htm*" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/**/*.html*" filters="channelProcessingFilter"/&gt;
              &lt;sec:filter-chain pattern="/**"
                                filters="channelProcessingFilter,httpSessionContextIntegrationFilter,logoutFilter,casSingleSignOutFilter,casProcessingFilter,securityContextHolderAwareRequestFilter,exceptionTranslationFilter,filterInvocationInterceptor"/&gt;
          &lt;/sec:filter-chain-map&gt;
      &lt;/bean&gt;
  
      &lt;!-- this is what hooks up the CAS entry point --&gt;
      &lt;bean id="exceptionTranslationFilter" class="org.springframework.security.ui.ExceptionTranslationFilter"&gt;
          &lt;property name="authenticationEntryPoint"&gt;
              &lt;ref local="casProcessingFilterEntryPoint"/&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- where do I go when I need authentication from CAS--&gt;
      &lt;bean id="casProcessingFilterEntryPoint" class="org.springframework.security.ui.cas.CasProcessingFilterEntryPoint"&gt;
          &lt;property name="loginUrl" value="https://dvjvm11.uftwf.dev:8443/cas-server-webapp/login"/&gt;
          &lt;property name="serviceProperties" ref="serviceProperties"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- defines which roles are allowed to access http resources --&gt;
      &lt;bean id="filterInvocationInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor"&gt;
          &lt;property name="authenticationManager" ref="authenticationManager"/&gt;
          &lt;property name="accessDecisionManager" ref="accessDecisionManager"/&gt;
          &lt;property name="objectDefinitionSource"&gt;
              &lt;value&gt;
                  PATTERN_TYPE_APACHE_ANT
                  **=ROLE_ALLOWED_ROLES_HERE
              &lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- hooks up CAS ticket validator and user details loader --&gt;
      &lt;bean id="authenticationManager" class="org.springframework.security.providers.ProviderManager"&gt;
          &lt;property name="providers"&gt;
              &lt;list&gt;
                  &lt;ref bean="casAuthenticationProvider"/&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- supporting class for filterInvocationInterceptor --&gt;
      &lt;bean id="accessDecisionManager" class="org.springframework.security.vote.AffirmativeBased"&gt;
          &lt;property name="allowIfAllAbstainDecisions" value="false"/&gt;
          &lt;property name="decisionVoters"&gt;
              &lt;list&gt;
                  &lt;ref local="roleVoter"/&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="roleVoter" class="org.springframework.security.vote.RoleVoter"&gt;
          &lt;property name="rolePrefix" value=""/&gt;
      &lt;/bean&gt;
  
      &lt;!-- setup method level security using annotations --&gt;
      &lt;sec:global-method-security jsr250-annotations="enabled" secured-annotations="enabled"/&gt;
      &lt;alias name="authenticationManager" alias="_authenticationManager"/&gt;
  
      &lt;bean id="passwordEncoder" class="org.springframework.security.providers.encoding.ShaPasswordEncoder"/&gt;
  
      &lt;!-- which service (application) am I authenticating --&gt;
      &lt;bean id="serviceProperties" class="org.springframework.security.ui.cas.ServiceProperties"&gt;
          &lt;property name="service" value="https://dvjvm11.uftwf.dev:8443/cas-server-webapp/j_spring_cas_security_check"/&gt;
          &lt;property name="sendRenew" value="false"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- handles a logout request from the CAS server --&gt;
      &lt;bean id="casSingleSignOutFilter" class="org.jasig.cas.client.session.SingleSignOutFilter"/&gt;
  
      &lt;!-- performs CAS authentication --&gt;
      &lt;bean id="casProcessingFilter" class="org.springframework.security.ui.cas.CasProcessingFilter"&gt;
          &lt;property name="authenticationManager" ref="authenticationManager"/&gt;
          &lt;property name="authenticationFailureUrl" value="/403.jsp"/&gt;
          &lt;property name="alwaysUseDefaultTargetUrl" value="false"/&gt;
          &lt;property name="defaultTargetUrl" value="/"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Does the CAS ticket validation and user details loading --&gt;
      &lt;bean id="casAuthenticationProvider" class="org.springframework.security.providers.cas.CasAuthenticationProvider"&gt;
          &lt;property name="userDetailsService" ref="pickYourUserDetailsServiceImplementation"/&gt;
          &lt;property name="serviceProperties" ref="serviceProperties"/&gt;
          &lt;property name="ticketValidator"&gt;
              &lt;bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator"&gt;
                  &lt;constructor-arg index="0" value="https://dvjvm11.uftwf.dev:8443/cas-server-webapp/"/&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
          &lt;property name="key" value="my_password_for_this_auth_provider_only"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Log failed authentication attempts to commons-logging --&gt;
      &lt;bean id="loggerListener" class="org.springframework.security.event.authentication.LoggerListener"/&gt;
  
      &lt;bean id="httpSessionContextIntegrationFilter"
            class="org.springframework.security.context.HttpSessionContextIntegrationFilter"/&gt;
  
      &lt;bean id="securityContextHolderAwareRequestFilter"
            class="org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter"/&gt;
  
      &lt;!-- ===================== SSL SWITCHING ==================== --&gt;
      &lt;bean id="channelProcessingFilter" class="org.springframework.security.securechannel.ChannelProcessingFilter"&gt;
          &lt;property name="channelDecisionManager" ref="channelDecisionManager"/&gt;
          &lt;property name="filterInvocationDefinitionSource"&gt;
              &lt;value&gt;
                  PATTERN_TYPE_APACHE_ANT
                  **=REQUIRES_SECURE_CHANNEL
              &lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="channelDecisionManager" class="org.springframework.security.securechannel.ChannelDecisionManagerImpl"&gt;
          &lt;property name="channelProcessors"&gt;
              &lt;list&gt;
                  &lt;bean class="org.springframework.security.securechannel.SecureChannelProcessor"&gt;
                      &lt;property name="entryPoint" ref="channelEntryPoint"/&gt;
                  &lt;/bean&gt;
                  &lt;bean class="org.springframework.security.securechannel.InsecureChannelProcessor"&gt;
                      &lt;property name="entryPoint" ref="channelEntryPoint"/&gt;
                  &lt;/bean&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="channelEntryPoint" class="org.springframework.security.securechannel.RetryWithHttpsEntryPoint"&gt;
          &lt;property name="portMapper" ref="portMapper"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="portMapper" class="org.springframework.security.util.PortMapperImpl"&gt;
          &lt;property name="portMappings"&gt;
              &lt;map&gt;
                  &lt;entry key="80" value="443"/&gt;
                  &lt;entry key="8080" value="8443"/&gt;
                  &lt;entry key="5580" value="5543"/&gt;
              &lt;/map&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- Invoked when the user clicks logout --&gt;
      &lt;bean id="logoutFilter" class="org.springframework.security.ui.logout.LogoutFilter"&gt;
          &lt;!-- URL redirected to after logout success --&gt;
          &lt;constructor-arg value="https://dvjvm11.uftwf.dev:8443/cas-server-webapp/logout"/&gt;
          &lt;constructor-arg&gt;
              &lt;list&gt;
                  &lt;bean class="org.springframework.security.ui.logout.SecurityContextLogoutHandler"&gt;
                      &lt;property name="invalidateHttpSession" value="false"/&gt;
                  &lt;/bean&gt;
              &lt;/list&gt;
          &lt;/constructor-arg&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt; &lt;property name="driverClassName" value="${database.driver}" /&gt; &lt;property 
          name="url" value="${database.url}" /&gt; &lt;property name="username" value="${database.user}" 
          /&gt; &lt;property name="password" value="${database.password}" /&gt; &lt;property 
          name="initialSize" value="5" /&gt; &lt;property name="maxActive" value="10" 
          /&gt; &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>can someone please tell me why everything stopped working</p>