title: Spring Security and CAS Integration
body: <p>Can anyone paste simple steps to integrate Spring security and CAS over here for single sign on and single sign out.
  Note I dont want any role based access.I have a web application which is already integrated with spring security. Now I was trying to perform SSO with CAS,but I am getting this error  <code>sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target</code></p>
  
  <p>This is my current spring security.xml</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:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/security 
          http://www.springframework.org/schema/security/spring-security-3.1.xsd
          "&gt;
  
  &lt;sec:http entry-point-ref="casProcessingFilterEntryPoint" &gt;
          &lt;sec:intercept-url pattern="/**" access="ROLE_USER" /&gt;
          &lt;sec:logout logout-success-url="/loggedout.jsp" invalidate-session="true"/&gt;
          &lt;sec:custom-filter ref="casAuthenticationFilter" after="CAS_FILTER"/&gt;
      &lt;/sec:http&gt;
  
      &lt;sec:authentication-manager alias="authenticationManager"&gt;
          &lt;sec:authentication-provider ref="casAuthenticationProvider"/&gt;
      &lt;/sec:authentication-manager&gt;
  
  &lt;bean id="casAuthenticationFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter"&gt;
          &lt;property name="authenticationManager" ref="authenticationManager"/&gt;
          &lt;property name="authenticationFailureHandler"&gt;
              &lt;bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"&gt;
                  &lt;property name="defaultFailureUrl" value="/casfailed.jsp"/&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
          &lt;property name="authenticationSuccessHandler"&gt;
              &lt;bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler"&gt;
                  &lt;property name="defaultTargetUrl" value="/"/&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="casProcessingFilterEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint"&gt;
          &lt;property name="loginUrl" value="https://cegicollabdev.india.xxx.com:8443/cas/login"/&gt;
          &lt;property name="serviceProperties" ref="serviceProperties"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider"&gt;
          &lt;property name="userDetailsService" ref="userService"/&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://cegicollabdev.india.tcs.com:8443/cas" /&gt;
                  &lt;/bean&gt;
          &lt;/property&gt;
          &lt;property name="key" value="an_id_for_this_auth_provider_only"/&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties"&gt;
          &lt;property name="service" value="http://localhost:8080/dbcomparision/j_spring_cas_security_check"/&gt;
          &lt;property name="sendRenew" value="false"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="userService" class="com.tcs.ceg.services.impl.UserServiceImpl" /&gt;
  
   &lt;!--     &lt;sec:global-method-security pre-post-annotations="enabled" /&gt;
  
      &lt;sec:http pattern="/css/**" security="none"/&gt;
      &lt;sec:http pattern="/images/**" security="none"/&gt;
      &lt;sec:http pattern="/js/**" security="none"/&gt;
      &lt;sec:http pattern="/index.jsp" security="none"/&gt;
      &lt;sec:http pattern="/app/addNewUser.json" security="none"/&gt;
      &lt;sec:http pattern="/dbcomplogin.jsp" security="none"/&gt;
      &lt;sec:http pattern="/loggedout.jsp" security="none"/&gt;
  
      &lt;sec:http use-expressions="true"&gt;--&gt;
          &lt;!--
               Allow all other requests. In a real application you should
               adopt a whitelisting approach where access is not allowed by default
            --&gt;
        &lt;!--    &lt;sec:intercept-url pattern="/**" access="isAuthenticated()" /&gt;
          &lt;sec:form-login login-page='/dbcomplogin.jsp'
            authentication-failure-url="/dbcomplogin.jsp?login_error=1"
            default-target-url="/index.jsp" /&gt;
          &lt;sec:logout logout-success-url="/loggedout.jsp" delete-cookies="JSESSIONID"/&gt;
          &lt;sec:remember-me /&gt;
  
      &lt;/sec:http&gt;
  
      &lt;bean id="myUserService" class="com.tcs.ceg.services.impl.UserServiceImpl" /&gt;
      &lt;sec:authentication-manager&gt;
      &lt;sec:authentication-provider user-service-ref="myUserService" /&gt;
      &lt;/sec:authentication-manager&gt; --&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>This is my web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;Spring3MVC&lt;/display-name&gt;
    &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              /WEB-INF/spring-rootcontext.xml
              /WEB-INF/spring-security.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
        &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
        &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
      &lt;!--
        - Loads the root application context of this web app at startup.
      --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
  
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
              org.springframework.web.servlet.DispatcherServlet
          &lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/app/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
   &lt;filter&gt;
         &lt;filter-name&gt;CAS Single Sign Out Filter&lt;/filter-name&gt;
         &lt;filter-class&gt;org.jasig.cas.client.session.SingleSignOutFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
   &lt;filter-mapping&gt;
         &lt;filter-name&gt;CAS Single Sign Out Filter&lt;/filter-name&gt;
         &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.jasig.cas.client.session.SingleSignOutHttpSessionListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>This is my Spring-rootcontext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:lang="http://www.springframework.org/schema/lang"
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:util="http://www.springframework.org/schema/util"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" &gt;
    &lt;context:annotation-config /&gt;
   &lt;mvc:annotation-driven /&gt;
      &lt;context:component-scan
          base-package="com.tcs.ceg" /&gt;
  
   &lt;jee:jndi-lookup id="dataSource1" jndi-name="jdbc/PmdDS"/&gt;
  
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource1" /&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;classpath:hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="configurationClass"&gt;
              &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="current_session_context_class"&gt;thread&lt;/prop&gt;
                  &lt;prop key="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/prop&gt;
                  &lt;prop key="hibernate.connection.release_mode"&gt;auto&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
  
      &lt;tx:annotation-driven /&gt;
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
      &lt;/beans&gt;
  </code></pre>
  
  <p>This is my spring-servlet.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:lang="http://www.springframework.org/schema/lang"
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:util="http://www.springframework.org/schema/util"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" &gt;
  
  
  
      &lt;bean id="viewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
          &lt;property name="viewClass"&gt;
          &lt;value&gt;
              org.springframework.web.servlet.view.tiles2.TilesView
          &lt;/value&gt;
      &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean id="tilesConfigurer"
      class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;
      &lt;property name="definitions"&gt;
          &lt;list&gt;
              &lt;value&gt;/WEB-INF/tiles.xml&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="messageSource"
      class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
      &lt;property name="basename" value="classpath:messages" /&gt;
      &lt;property name="defaultEncoding" value="UTF-8"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="localeChangeInterceptor"
      class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"&gt;
      &lt;property name="paramName" value="lang" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="localeResolver"
      class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt;
      &lt;property name="defaultLocale" value="en"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="handlerMapping"
      class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"&gt;
      &lt;property name="interceptors"&gt;
          &lt;ref bean="localeChangeInterceptor" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  
  
      &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
          &lt;!-- one of the properties available; the maximum file size in bytes --&gt;
          &lt;property name="maxUploadSize" value="1000000000000"/&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Problem : 1  <code>sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target</code></p>
  
  <p>Problem 2: Custom UserServiceimpl is not getting called </p>
  
  <p>Problem 3: Is this correct ? <code>&lt;property name="service" value="http://localhost:8080/dbcomparision/j_spring_cas_security_check"/&gt;</code> ,Note In my program no Request Mapping is there for j_spring_cas_security_check</p>