01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.runas;
17:
18: import org.acegisecurity.GrantedAuthority;
19:
20: import org.acegisecurity.providers.AbstractAuthenticationToken;
21:
22: /**
23: * An immutable {@link org.acegisecurity.Authentication} implementation that supports {@link RunAsManagerImpl}.
24: *
25: * @author Ben Alex
26: * @version $Id: RunAsUserToken.java 1784 2007-02-24 21:00:24Z luke_t $
27: */
28: public class RunAsUserToken extends AbstractAuthenticationToken {
29: //~ Instance fields ================================================================================================
30:
31: private static final long serialVersionUID = 1L;
32: private Class originalAuthentication;
33: private Object credentials;
34: private Object principal;
35: private int keyHash;
36:
37: //~ Constructors ===================================================================================================
38:
39: public RunAsUserToken(String key, Object principal,
40: Object credentials, GrantedAuthority[] authorities,
41: Class originalAuthentication) {
42: super (authorities);
43: this .keyHash = key.hashCode();
44: this .principal = principal;
45: this .credentials = credentials;
46: this .originalAuthentication = originalAuthentication;
47: setAuthenticated(true);
48: }
49:
50: //~ Methods ========================================================================================================
51:
52: public Object getCredentials() {
53: return this .credentials;
54: }
55:
56: public int getKeyHash() {
57: return this .keyHash;
58: }
59:
60: public Class getOriginalAuthentication() {
61: return this .originalAuthentication;
62: }
63:
64: public Object getPrincipal() {
65: return this .principal;
66: }
67:
68: public String toString() {
69: StringBuffer sb = new StringBuffer(super .toString());
70: sb.append("; Original Class: ").append(
71: this.originalAuthentication.getName());
72:
73: return sb.toString();
74: }
75: }
|