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.providers.x509;
17:
18: import org.acegisecurity.GrantedAuthority;
19:
20: import org.acegisecurity.providers.AbstractAuthenticationToken;
21:
22: import java.security.cert.X509Certificate;
23:
24: /**
25: * <code>Authentication</code> implementation for X.509 client-certificate authentication.
26: *
27: * @author Luke Taylor
28: * @version $Id: X509AuthenticationToken.java 1784 2007-02-24 21:00:24Z luke_t $
29: */
30: public class X509AuthenticationToken extends
31: AbstractAuthenticationToken {
32: //~ Instance fields ================================================================================================
33:
34: private static final long serialVersionUID = 1L;
35: private Object principal;
36: private X509Certificate credentials;
37:
38: //~ Constructors ===================================================================================================
39:
40: /**
41: * Used for an authentication request. The {@link org.acegisecurity.Authentication#isAuthenticated()} will return
42: * <code>false</code>.
43: *
44: * @param credentials the certificate
45: */
46: public X509AuthenticationToken(X509Certificate credentials) {
47: super (null);
48: this .credentials = credentials;
49: }
50:
51: /**
52: * Used for an authentication response object. The {@link Authentication#isAuthenticated()}
53: * will return <code>true</code>.
54: *
55: * @param principal the principal, which is generally a
56: * <code>UserDetails</code>
57: * @param credentials the certificate
58: * @param authorities the authorities
59: */
60: public X509AuthenticationToken(Object principal,
61: X509Certificate credentials, GrantedAuthority[] authorities) {
62: super (authorities);
63: this .principal = principal;
64: this .credentials = credentials;
65: setAuthenticated(true);
66: }
67:
68: //~ Methods ========================================================================================================
69:
70: public Object getCredentials() {
71: return credentials;
72: }
73:
74: public Object getPrincipal() {
75: return principal;
76: }
77: }
|