---
title: "Yale CAS as an Acegi Client in SpringSide"
author: "security"
date: "2006-10-15T23:53:00Z"
tags: []
slug: "yale-cas-as-an-acegi-client-in-springside"
draft: false
lastmod: "2006-10-15T23:53:00Z"
id: 28460
url: "https://security.iteye.com/blog/28460"
---

First,  Set [SpringSide](http://www.springside.org.cn "SpringSide")'s web.xml,  we use Acegi CAS Filter:

     &lt; filter-mapping &gt;  
         &lt; filter-name &gt; hibernateFilter &lt;/ filter-name &gt;  
         &lt; url-pattern &gt; /j\_acegi\_cas\_security\_check &lt;/ url-pattern &gt;  
     &lt;/ filter-mapping &gt;

We Should Set Main ACEGI application Context：  
1\) filterChainProxy should add a cas filter as Acegi's Sample, but here, we reuse  
authenticationProcessingFilter, which we act as cas client filter.

     &lt; bean  id ="filterChainProxy"  
          class ="org.acegisecurity.util.FilterChainProxy" &gt;  
         &lt; property  name ="filterInvocationDefinitionSource" &gt;  
             &lt; value &gt;  
                CONVERT\_URL\_TO\_LOWERCASE\_BEFORE\_COMPARISON  
                PATTERN\_TYPE\_APACHE\_ANT  
                /\*\*=httpSessionContextIntegrationFilter,anonymousProcessingFilter,authenticationProcessingFilter,rememberMeProcessingFilter,logoutFilter,channelProcessingFilter,basicProcessingFilter,securityContextHolderAwareRequestFilter,exceptionTranslationFilter,filterInvocationInterceptor  
             &lt;/ value &gt;  
         &lt;/ property &gt;  
     &lt;/ bean &gt;

2\) authenticationProcessingFilter, of course, play the most important role in this  
applicationContext\_acegi.xml.  
In [SpringSide](http://www.springside.org.cn "SpringSide"),  /admin  is protected resource, so defaultTargetUrl protected it  
and all those request to the target url must be authenticated by authenticationManager.

![](/Images/OutliningIndicators/None.gif)    &lt;bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.cas.CasProcessingFilter"&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;property name="authenticationManager" ref="authenticationManager"/&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;property name="authenticationFailureUrl"&gt;  
![](/Images/OutliningIndicators/None.gif)            &lt;value&gt;/security/login.jsp?login\_error=1&lt;/value&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;/property&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;property name="defaultTargetUrl"&gt;  
![](/Images/OutliningIndicators/None.gif)            &lt;value&gt;/admin/&lt;/value&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;/property&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;property name="filterProcessesUrl"&gt;  
![](/Images/OutliningIndicators/None.gif)            &lt;value&gt;/j\_acegi\_cas\_security\_check&lt;/value&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;/property&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;property name="rememberMeServices" ref="rememberMeServices"/&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;property name="exceptionMappings"&gt;  
![](/Images/OutliningIndicators/None.gif)            &lt;value&gt;  
![](/Images/OutliningIndicators/None.gif)                org.acegisecurity.userdetails.UsernameNotFoundException=/security/login.jsp?login\_error=user\_not\_found\_error  
![](/Images/OutliningIndicators/None.gif)                org.acegisecurity.BadCredentialsException=/security/login.jsp?login\_error=user\_psw\_error  
![](/Images/OutliningIndicators/None.gif)                org.acegisecurity.concurrent.ConcurrentLoginException=/security/login.jsp?login\_error=too\_many\_user\_error  
![](/Images/OutliningIndicators/None.gif)            &lt;/value&gt;  
![](/Images/OutliningIndicators/None.gif)        &lt;/property&gt;  
![](/Images/OutliningIndicators/None.gif)    &lt;/bean&gt;

3\) Then, we set all the needed beans in CAS Filter

    &lt;!-- =========  Acegi as a CAS Client的配置============= --&gt;   
    &lt;bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter"&gt;  
        &lt;property name="authenticationEntryPoint"&gt;  
            &lt;ref local="casProcessingFilterEntryPoint"/&gt;  
        &lt;/property&gt;  
    &lt;/bean&gt;  
      
   &lt;!-- cas config --&gt;  
    &lt;bean id="casProcessingFilterEntryPoint" class="org.acegisecurity.ui.cas.CasProcessingFilterEntryPoint"&gt;  
        &lt;property name="loginUrl"&gt;&lt;value&gt;https://sourcesite:8443/cas/login&lt;/value&gt;&lt;/property&gt;  
        &lt;property name="serviceProperties"&gt;&lt;ref local="serviceProperties"/&gt;&lt;/property&gt;  
    &lt;/bean&gt;  
      
    &lt;bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;  
        &lt;property name="providers"&gt;  
            &lt;list&gt;  
                &lt;ref local="casAuthenticationProvider"/&gt;  
            &lt;/list&gt;  
        &lt;/property&gt;  
    &lt;/bean&gt;  
      
    &lt;bean id="casAuthenticationProvider" class="org.acegisecurity.providers.cas.CasAuthenticationProvider"&gt;  
        &lt;property name="casAuthoritiesPopulator"&gt;&lt;ref bean="casAuthoritiesPopulator"/&gt;&lt;/property&gt;  
        &lt;property name="casProxyDecider"&gt;&lt;ref local="casProxyDecider"/&gt;&lt;/property&gt;  
        &lt;property name="ticketValidator"&gt;&lt;ref local="casProxyTicketValidator"/&gt;&lt;/property&gt;  
        &lt;property name="statelessTicketCache"&gt;&lt;ref local="statelessTicketCache"/&gt;&lt;/property&gt;  
        &lt;property name="key"&gt;&lt;value&gt;my\_password\_for\_this\_auth\_provider\_only&lt;/value&gt;&lt;/property&gt;  
    &lt;/bean&gt;  
    &lt;bean id="casProxyTicketValidator" class="org.acegisecurity.providers.cas.ticketvalidator.CasProxyTicketValidator"&gt;  
        &lt;property name="casValidate"&gt;&lt;value&gt;https://sourcesite:8443/cas/proxyValidate&lt;/value&gt;&lt;/property&gt;  
        &lt;property name="serviceProperties"&gt;&lt;ref local="serviceProperties"/&gt;&lt;/property&gt;  
    &lt;/bean&gt;  
    &lt;!--   
    &lt;bean id="casProxyDecider" class="org.acegisecurity.providers.cas.proxy.AcceptAnyCasProxy" /&gt;  
    --&gt;  
    &lt;bean id="casProxyDecider" class="org.acegisecurity.providers.cas.proxy.RejectProxyTickets" /&gt;  
      
    &lt;bean id="serviceProperties" class="org.acegisecurity.ui.cas.ServiceProperties"&gt;  
        &lt;property name="service"&gt;  
            &lt;value&gt;http://gzug:8080/springside/j\_acegi\_cas\_security\_check&lt;/value&gt;  
        &lt;/property&gt;  
        &lt;property name="sendRenew"&gt;  
            &lt;value&gt;false&lt;/value&gt;  
        &lt;/property&gt;  
    &lt;/bean&gt;  
      
    &lt;bean id="statelessTicketCache" class="org.acegisecurity.providers.cas.cache.EhCacheBasedTicketCache"&gt;  
        &lt;property name="cache"&gt;  
            &lt;bean class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;  
                &lt;property name="cacheManager"&gt;  
                    &lt;bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/&gt;  
                &lt;/property&gt;  
                &lt;property name="cacheName" value="userCache"/&gt;  
            &lt;/bean&gt;  
        &lt;/property&gt;  
    &lt;/bean&gt;  
      
    &lt;bean id="casAuthoritiesPopulator" class="org.acegisecurity.providers.cas.populator.DaoCasAuthoritiesPopulator"&gt;  
        &lt;property name="userDetailsService"&gt;&lt;ref local="jdbcDaoImpl"/&gt;&lt;/property&gt;  
    &lt;/bean&gt;

    &lt;bean id="casProcessingFilter" class="org.acegisecurity.ui.cas.CasProcessingFilter"&gt;  
        &lt;property name="authenticationManager"&gt;&lt;ref local="authenticationManager"/&gt;&lt;/property&gt;  
        &lt;property name="authenticationFailureUrl"&gt;&lt;value&gt;/casfailed.jsp&lt;/value&gt;&lt;/property&gt;  
        &lt;property name="defaultTargetUrl"&gt;&lt;value&gt;/&lt;/value&gt;&lt;/property&gt;  
        &lt;property name="filterProcessesUrl"&gt;&lt;value&gt;/j\_acegi\_cas\_security\_check&lt;/value&gt;&lt;/property&gt;  
    &lt;/bean&gt;

casProcessingFilterEntryPoint is very critical,  
loginUrl is the CAS Server's /login url, you should set up your CAS Server(2.0 or 3.0) and config for  
those JKS keystore after enable SSL in Tomcat(Tomcat 5.5/conf/server.xml) and place the cacerts that  
have the CAS Server's public cert to Acegi Client's [JDK](http://java.sun.com/ "JDK")/jre/lib/security/  
Check serviceProperties to make sure that [SpringSide](http://www.springside.org.cn "SpringSide") Service url is config as /j\_acegi\_cas\_security\_check

because Yale CAS use ticket cache for SSO impl, so we should config for statelessTicketCache  
Just use springframework's ehcache for cacheManager.

[SpringSide](http://www.springside.org.cn "SpringSide") use jdbcDaoImpl which perform database authentication. So I am very happy to use it  
as casAuthoritiesPopulator , which will set use detail for the user. And these info are very useful for  
application authorization.

    &lt;bean id="jdbcDaoImpl"  
          class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl"&gt;  
        &lt;property name="dataSource" ref="dataSource"/&gt;  
        &lt;property name="usersByUsernameQuery"&gt;  
            &lt;value&gt;  
                select loginid,passwd,1 from ss\_users where status='1' and loginid = ?  
            &lt;/value&gt;  
        &lt;/property&gt;  
        &lt;property name="authoritiesByUsernameQuery"&gt;  
            &lt;value&gt;  
                select u.loginid,p.name from ss\_users u,ss\_roles r,ss\_permissions  
                p,ss\_user\_role ur,ss\_role\_permis rp where u.id=ur.user\_id and  
                r.id=ur.role\_id and p.id=rp.permis\_id and  
                r.id=rp.role\_id and p.status='1' and u.loginid=?  
            &lt;/value&gt;  
        &lt;/property&gt;  
    &lt;/bean&gt;

There is little difference between casclient 2.0.12 and Acegi, right?

Note that in my env, gzug:8080/springside is bookstore webapp  
and sourcesite:8443 is the CAS 3 Server.

Hope for suggestion.....