1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.security;
15
16 import org.eclipse.jetty.security.authentication.DelegateAuthenticator;
17 import org.eclipse.jetty.security.authentication.LoginAuthenticator;
18 import org.eclipse.jetty.server.Authentication;
19 import org.eclipse.jetty.server.UserIdentity;
20 import org.eclipse.jetty.server.UserIdentity.Scope;
21
22
23
24
25
26 public class UserAuthentication implements Authentication.User
27 {
28 private final Authenticator _authenticator;
29 private final UserIdentity _userIdentity;
30
31 public UserAuthentication(Authenticator authenticator, UserIdentity userIdentity)
32 {
33 _authenticator = authenticator;
34 _userIdentity=userIdentity;
35 }
36
37 public String getAuthMethod()
38 {
39 return _authenticator.getAuthMethod();
40 }
41
42 public UserIdentity getUserIdentity()
43 {
44 return _userIdentity;
45 }
46
47 public boolean isUserInRole(Scope scope, String role)
48 {
49 return _userIdentity.isUserInRole(role, scope);
50 }
51
52 public void logout()
53 {
54 Authenticator authenticator = _authenticator;
55 while (true)
56 {
57 if (authenticator instanceof LoginAuthenticator)
58 {
59 ((LoginAuthenticator)authenticator).getLoginService().logout(this.getUserIdentity());
60 break;
61 }
62 else if (authenticator instanceof DelegateAuthenticator)
63 {
64 authenticator=((DelegateAuthenticator)authenticator).getDelegate();
65 }
66 else
67 break;
68 }
69 }
70
71 public String toString()
72 {
73 return "{Auth,"+getAuthMethod()+","+_userIdentity+"}";
74 }
75 }