View Javadoc

1   /* Copyright 2004 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * 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  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      //~ Instance fields ========================================================
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      //~ Constructors ===========================================================
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      //~ Methods ================================================================
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  }