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.UserIdentity;
21  
22  
23  /* ------------------------------------------------------------ */
24  /**
25   * Default Identity Service implementation.
26   * This service handles only role reference maps passed in an
27   * associated {@link org.eclipse.jetty.server.UserIdentity.Scope}.  If there are roles
28   * refs present, then associate will wrap the UserIdentity with one
29   * that uses the role references in the 
30   * {@link org.eclipse.jetty.server.UserIdentity#isUserInRole(String, org.eclipse.jetty.server.UserIdentity.Scope)}
31   * implementation. All other operations are effectively noops.
32   *
33   */
34  public class DefaultIdentityService implements IdentityService
35  {
36      /* ------------------------------------------------------------ */
37      public DefaultIdentityService()
38      {
39      }
40      
41      /* ------------------------------------------------------------ */
42      /** 
43       * If there are roles refs present in the scope, then wrap the UserIdentity 
44       * with one that uses the role references in the {@link UserIdentity#isUserInRole(String, org.eclipse.jetty.server.UserIdentity.Scope)}
45       */
46      public Object associate(UserIdentity user)
47      {
48          return null;
49      }
50  
51      /* ------------------------------------------------------------ */
52      public void disassociate(Object previous) 
53      {
54      }
55  
56      /* ------------------------------------------------------------ */
57      public Object setRunAs(UserIdentity user, RunAsToken token)
58      {
59          return token;
60      }
61  
62      /* ------------------------------------------------------------ */
63      public void unsetRunAs(Object lastToken)
64      {
65      }
66  
67      /* ------------------------------------------------------------ */
68      public RunAsToken newRunAsToken(String runAsName)
69      {
70          return new RoleRunAsToken(runAsName);
71      }
72  
73      /* ------------------------------------------------------------ */
74      public UserIdentity getSystemUserIdentity()
75      {
76          return null;
77      }
78  
79      /* ------------------------------------------------------------ */
80      public UserIdentity newUserIdentity(final Subject subject, final Principal userPrincipal, final String[] roles)
81      {
82          return new DefaultUserIdentity(subject,userPrincipal,roles);
83      }
84      
85  }