View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.jaas;
20  
21  import java.security.Principal;
22  import javax.security.auth.Subject;
23  import javax.security.auth.login.LoginContext;
24  
25  
26  
27  /* ---------------------------------------------------- */
28  /** JAASUserPrincipal
29   * <p>Implements the JAAS version of the
30   *  org.eclipse.jetty.http.UserPrincipal interface.
31   *
32   * @version $Id: JAASUserPrincipal.java 4780 2009-03-17 15:36:08Z jesse $
33   *
34   */
35  public class JAASUserPrincipal implements Principal
36  {
37      private final String _name;
38      private final Subject _subject;
39      private final LoginContext _loginContext;
40  
41      /* ------------------------------------------------ */
42  
43      public JAASUserPrincipal(String name, Subject subject, LoginContext loginContext)
44      {
45          this._name = name;
46          this._subject = subject;
47          this._loginContext = loginContext;
48      }
49  
50      /* ------------------------------------------------ */
51      /** Get the name identifying the user
52       */
53      public String getName ()
54      {
55          return _name;
56      }
57  
58  
59      /* ------------------------------------------------ */
60      /** Provide access to the Subject
61       * @return subject
62       */
63      public Subject getSubject ()
64      {
65          return this._subject;
66      }
67  
68      LoginContext getLoginContext ()
69      {
70          return this._loginContext;
71      }
72  
73      public String toString()
74      {
75          return getName();
76      }
77  
78  }