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.LoginAuthenticator;
17 import org.eclipse.jetty.server.Authentication;
18 import org.eclipse.jetty.server.UserIdentity;
19 import org.eclipse.jetty.server.UserIdentity.Scope;
20
21
22
23
24
25 public class UserAuthentication implements Authentication.User
26 {
27 private final Authenticator _authenticator;
28 private final UserIdentity _userIdentity;
29
30 public UserAuthentication(Authenticator authenticator, UserIdentity userIdentity)
31 {
32 _authenticator = authenticator;
33 _userIdentity=userIdentity;
34 }
35
36 public String getAuthMethod()
37 {
38 return _authenticator.getAuthMethod();
39 }
40
41 public UserIdentity getUserIdentity()
42 {
43 return _userIdentity;
44 }
45
46 public boolean isUserInRole(Scope scope, String role)
47 {
48 return _userIdentity.isUserInRole(role, scope);
49 }
50
51 public void logout()
52 {
53 final Authenticator authenticator = _authenticator;
54 if (authenticator instanceof LoginAuthenticator)
55 {
56 IdentityService id_service=((LoginAuthenticator)authenticator).getLoginService().getIdentityService();
57 if (id_service!=null)
58 id_service.disassociate(null);
59 }
60 }
61
62 @Override
63 public String toString()
64 {
65 return "{Auth,"+getAuthMethod()+","+_userIdentity+"}";
66 }
67 }