View Javadoc

1   // ========================================================================
2   // Copyright (c) 2008-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.security.authentication;
15  
16  import javax.servlet.ServletRequest;
17  import javax.servlet.ServletResponse;
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.eclipse.jetty.security.Authenticator;
22  import org.eclipse.jetty.security.CrossContextPsuedoSession;
23  import org.eclipse.jetty.security.ServerAuthException;
24  import org.eclipse.jetty.server.Authentication;
25  
26  /**
27   * Cross-context psuedo-session caching ServerAuthentication
28   * 
29   * @version $Rev: 4793 $ $Date: 2009-03-19 00:00:01 +0100 (Thu, 19 Mar 2009) $
30   */
31  public class XCPSCachingAuthenticator extends DelegateAuthenticator
32  {
33      public final static String __J_AUTHENTICATED = "org.eclipse.jetty.server.Auth";
34  
35      private final CrossContextPsuedoSession<Authentication> _xcps;
36  
37      public XCPSCachingAuthenticator(Authenticator delegate, CrossContextPsuedoSession<Authentication> xcps)
38      {
39          super(delegate);
40          this._xcps = xcps;
41      }
42  
43      public Authentication validateRequest(ServletRequest request, ServletResponse response, boolean manditory) throws ServerAuthException
44      {
45  
46          Authentication serverAuthResult = _xcps.fetch((HttpServletRequest)request);
47          if (serverAuthResult != null) 
48              return serverAuthResult;
49  
50          serverAuthResult = _delegate.validateRequest(request, response, manditory);
51          if (serverAuthResult != null) 
52              _xcps.store(serverAuthResult, (HttpServletResponse)response);
53  
54          return serverAuthResult;
55      }
56  
57  }