Source code: org/acegisecurity/adapters/PrincipalAcegiUserToken.java
1 /* Copyright 2004, 2005 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.adapters;
17
18 import org.acegisecurity.GrantedAuthority;
19
20 import java.security.Principal;
21
22
23 /**
24 * A {@link Principal} compatible {@link org.acegisecurity.Authentication}
25 * object.
26 *
27 * @author Ben Alex
28 * @version $Id: PrincipalAcegiUserToken.java,v 1.6 2005/11/25 00:26:30 benalex Exp $
29 */
30 public class PrincipalAcegiUserToken extends AbstractAdapterAuthenticationToken
31 implements Principal {
32 //~ Instance fields ========================================================
33
34 private Object principal;
35 private String password;
36 private String username;
37
38 //~ Constructors ===========================================================
39
40 public PrincipalAcegiUserToken(String key, String username,
41 String password, GrantedAuthority[] authorities, Object principal) {
42 super(key, authorities);
43 this.username = username;
44 this.password = password;
45 this.principal = principal;
46 }
47
48 protected PrincipalAcegiUserToken() {
49 throw new IllegalArgumentException("Cannot use default constructor");
50 }
51
52 //~ Methods ================================================================
53
54 public Object getCredentials() {
55 return this.password;
56 }
57
58 public String getName() {
59 return this.username;
60 }
61
62 public Object getPrincipal() {
63 if (this.principal == null) {
64 return this.username;
65 }
66
67 return this.principal;
68 }
69 }