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