View Javadoc

1   /*
2    * Copyright 2005-2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.security.x509;
18  
19  import java.security.cert.X509Certificate;
20  import java.util.Collection;
21  
22  import org.springframework.security.authentication.AbstractAuthenticationToken;
23  import org.springframework.security.core.GrantedAuthority;
24  
25  
26  /**
27   * <code>Authentication</code> implementation for X.509 client-certificate authentication.
28   * <p>Migrated from Spring Security 2 since it has been removed in Spring Security 3.</p>
29   *
30   * @author Luke Taylor
31   */
32  public class X509AuthenticationToken extends AbstractAuthenticationToken {
33      //~ Instance fields ================================================================================================
34  
35      private static final long serialVersionUID = 1L;
36      private Object principal;
37      private X509Certificate credentials;
38  
39      //~ Constructors ===================================================================================================
40  
41      /**
42       * Used for an authentication request.  The {@link org.springframework.security.core.Authentication#isAuthenticated()} will return
43       * <code>false</code>.
44       *
45       * @param credentials the certificate
46       */
47      public X509AuthenticationToken(X509Certificate credentials) {
48          super(null);
49          this.credentials = credentials;
50      }
51  
52      /**
53       * Used for an authentication response object. The {@link org.springframework.security.core.Authentication#isAuthenticated()}
54       * will return <code>true</code>.
55       *
56       * @param principal the principal, which is generally a
57       *        <code>UserDetails</code>
58       * @param credentials the certificate
59       * @param authorities the authorities
60       */
61      public X509AuthenticationToken(Object principal, X509Certificate credentials, Collection<? extends 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  }