title: Setting up Pre auth filter for CasAuthenticationFilter
body: <p>I've a Spring Jasig CAS SSO set up for a couple of applications. This uses <code>CasAuthenticationFilter</code>. So I've webapps set up like these -</p>
  
  <p><code>Cas Server (Cas 3.5.2) - Cas.war</code>, <code>App1 - App1.war</code> and <code>App2 - App2.war</code>. Applications use Spring 3.2.3 and Spring Security 3.1.4.RELEASE.</p>
  
  <p><code>Spring Security Config</code>: <a href="http://pastie.org/private/qxcx1h8i9ys0w3lmwegiw" rel="nofollow">http://pastie.org/private/qxcx1h8i9ys0w3lmwegiw</a></p>
  
  <p>Things seem to work normally with this setup. Now, when I enable OAuth at the Cas Server (not through Spring Cas), I'm unable to integrate that authentication with the usual form-based authentication that I've set up. Facebook OAuth integration seems to work fine as I can see facebook profile attributes successfully retrieved in the logs. The problem is that post facebook login, CasAuthenticationFilter tries to authenticate the user "FacebookProfile#XYZXYZ" with a similar mechanism for form-based login and obviously it doesn't find that user in the database table for users. My guess is that I need to write a custom filter that extends <code>AbstractPreAuthenticatedProcessingFilter</code> and with position before <code>PRE_AUTH_FILTER</code> (check the pastie configuration above) and that should somehow set the <code>Authentication</code> right, so <code>CasAuthenticationFilter</code> should know that the user is already logged in.</p>
  
  <p>This is the URL being authenticated by <code>CasAuthenticationFilter</code> as per the logs - <code>/j_spring_cas_security_proxyreceptor?pgtIou=PGTIOU-1-pR9r9LVJvB5EkezbMJHN-talenteye.in&amp;pgtId=TGT-2-QXvAHIRciBNR9HU5FOvpOaHcJaBj5OJTUPPz5ZwA7yK1xH54iL-myorg.in</code></p>
  
  <p>The implementation <code>requiresAuthentication</code> of <code>CasAuthenticationFilter</code> looks like this: </p>
  
  <pre><code>protected boolean requiresAuthentication(final HttpServletRequest request, final HttpServletResponse response) {
      final boolean serviceTicketRequest = serviceTicketRequest(request, response);
      final boolean result = serviceTicketRequest || proxyReceptorRequest(request) || (proxyTicketRequest(serviceTicketRequest, request));
      if(logger.isDebugEnabled()) {
          logger.debug("requiresAuthentication = "+result);
      }
      return result;
  }
  </code></pre>
  
  <p>And the logs say -</p>
  
  <pre><code>19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter -     serviceTicketRequest = false
  19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - proxyReceptorConfigured = true
  19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - proxyReceptorRequest = true
  19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - requiresAuthentication = true
  19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - Request is to process authentication
  19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - proxyReceptorConfigured = true
  19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - proxyReceptorRequest = true
  19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - Responding to proxy receptor request
  </code></pre>
  
  <p>I'm confused as to how to make this work together. I wonder if I'm complicating things a bit too much. Any pointers will be really helpful as I've already wasted a couple of days on this.</p>