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;
15  
16  import java.security.Principal;
17  
18  import javax.security.auth.Subject;
19  
20  import org.eclipse.jetty.server.Request;
21  import org.eclipse.jetty.server.UserIdentity;
22  
23  /* ------------------------------------------------------------ */
24  /**
25   * Associates UserIdentities from with threads and UserIdentity.Contexts.
26   * 
27   */
28  public interface IdentityService
29  {
30      final static String[] NO_ROLES = new String[]{}; 
31      
32      /* ------------------------------------------------------------ */
33      /**
34       * Associate a user identity with the current thread.
35       * This is called with as a thread enters the 
36       * {@link SecurityHandler#handle(String, Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}
37       * method and then again with a null argument as that call exits.
38       * @param user The current user or null for no user to associated.
39       */
40      void associate(UserIdentity user);
41      
42      /* ------------------------------------------------------------ */
43      /**
44       * Associate a runas Token with the current user and thread.
45       * @param token The runAsToken to associate.
46       * @return The previous runAsToken or null.
47       */
48      Object setRunAs(UserIdentity user, RunAsToken token);
49      
50      /* ------------------------------------------------------------ */
51      /**
52       * Disassociate the current runAsToken from the thread
53       * and reassociate the previous token.
54       * @param token RUNAS returned from previous associateRunAs call
55       */
56      void unsetRunAs(Object token);
57  
58      /* ------------------------------------------------------------ */
59      /**
60       * Create a new UserIdentity for use with this identity service.
61       * The UserIdentity should be immutable and able to be cached.
62       * 
63       * @param subject Subject to include in UserIdentity
64       * @param userPrincipal Principal to include in UserIdentity.  This will be returned from getUserPrincipal calls
65       * @param roles set of roles to include in UserIdentity.
66       * @return A new immutable UserIdententity
67       */
68      UserIdentity newUserIdentity(Subject subject, Principal userPrincipal, String[] roles);
69  
70      /* ------------------------------------------------------------ */
71      /**
72       * Create a new RunAsToken from a runAsName (normally a role).
73       * @param runAsName Normally a role name
74       * @return A new immutable RunAsToken
75       */
76      RunAsToken newRunAsToken(String runAsName);
77  
78      /* ------------------------------------------------------------ */
79      UserIdentity getSystemUserIdentity();
80  }