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.io.Serializable;
17  
18  import org.eclipse.jetty.security.authentication.LoginAuthenticator;
19  import org.eclipse.jetty.server.Authentication;
20  import org.eclipse.jetty.server.UserIdentity;
21  import org.eclipse.jetty.server.UserIdentity.Scope;
22  
23  
24  /**
25   * @version $Rev: 4793 $ $Date: 2009-03-19 00:00:01 +0100 (Thu, 19 Mar 2009) $
26   */
27  public class UserAuthentication implements Authentication.User
28  {
29      private final String _method;
30      private final UserIdentity _userIdentity;
31  
32      public UserAuthentication(String method, UserIdentity userIdentity)
33      {
34          _method = method;
35          _userIdentity = userIdentity;
36      }
37      
38      public String getAuthMethod()
39      {
40          return _method;
41      }
42  
43      public UserIdentity getUserIdentity()
44      {
45          return _userIdentity;
46      }
47  
48      public boolean isUserInRole(Scope scope, String role)
49      {
50          return _userIdentity.isUserInRole(role, scope);
51      }
52      
53      @Override
54      public String toString()
55      {
56          return "{User,"+getAuthMethod()+","+_userIdentity+"}";
57      }
58  
59      public void logout()
60      {
61          SecurityHandler security=SecurityHandler.getCurrentSecurityHandler();
62          if (security!=null)
63              security.logout(this);
64      }
65  }