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.adapters;
17:
18: import org.acegisecurity.GrantedAuthority;
19:
20: import java.security.Principal;
21:
22: /**
23: * A {@link Principal} compatible {@link org.acegisecurity.Authentication} object.
24: *
25: * @author Ben Alex
26: * @version $Id: PrincipalAcegiUserToken.java 1784 2007-02-24 21:00:24Z luke_t $
27: */
28: public class PrincipalAcegiUserToken extends
29: AbstractAdapterAuthenticationToken implements Principal {
30: //~ Instance fields ================================================================================================
31:
32: private static final long serialVersionUID = 1L;
33: private Object principal;
34: private String password;
35: private String username;
36:
37: //~ Constructors ===================================================================================================
38:
39: public PrincipalAcegiUserToken(String key, String username,
40: String password, GrantedAuthority[] authorities,
41: Object principal) {
42: super (key, authorities);
43: this .username = username;
44: this .password = password;
45: this .principal = principal;
46: }
47:
48: //~ Methods ========================================================================================================
49:
50: public Object getCredentials() {
51: return this .password;
52: }
53:
54: public String getName() {
55: return this .username;
56: }
57:
58: public Object getPrincipal() {
59: if (this.principal == null) {
60: return this.username;
61: }
62:
63: return this.principal;
64: }
65: }
|