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