1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.runas;
17
18 import org.acegisecurity.GrantedAuthority;
19 import org.acegisecurity.providers.AbstractAuthenticationToken;
20
21
22 /***
23 * An immutable {@link org.acegisecurity.Authentication} implementation
24 * that supports {@link RunAsManagerImpl}.
25 *
26 * @author Ben Alex
27 * @version $Id: RunAsUserToken.java,v 1.5 2005/11/17 00:55:51 benalex Exp $
28 */
29 public class RunAsUserToken extends AbstractAuthenticationToken {
30
31
32 private Class originalAuthentication;
33 private Object credentials;
34 private Object principal;
35 private GrantedAuthority[] authorities;
36 private int keyHash;
37 private boolean authenticated;
38
39
40
41 public RunAsUserToken(String key, Object principal, Object credentials,
42 GrantedAuthority[] authorities, Class originalAuthentication) {
43 super();
44 this.keyHash = key.hashCode();
45 this.authorities = authorities;
46 this.principal = principal;
47 this.credentials = credentials;
48 this.originalAuthentication = originalAuthentication;
49 this.authenticated = true;
50 }
51
52 protected RunAsUserToken() {
53 throw new IllegalArgumentException("Cannot use default constructor");
54 }
55
56
57
58 public void setAuthenticated(boolean isAuthenticated) {
59 this.authenticated = isAuthenticated;
60 }
61
62 public boolean isAuthenticated() {
63 return this.authenticated;
64 }
65
66 public GrantedAuthority[] getAuthorities() {
67 return this.authorities;
68 }
69
70 public Object getCredentials() {
71 return this.credentials;
72 }
73
74 public int getKeyHash() {
75 return this.keyHash;
76 }
77
78 public Class getOriginalAuthentication() {
79 return this.originalAuthentication;
80 }
81
82 public Object getPrincipal() {
83 return this.principal;
84 }
85
86 public String toString() {
87 StringBuffer sb = new StringBuffer(super.toString());
88 sb.append("; Original Class: " + this.originalAuthentication.getName());
89
90 return sb.toString();
91 }
92 }