View Javadoc

1   /*
2    *   @(#) $Id: BogusTrustManagerFactory.java 355016 2005-12-08 07:00:30Z trustin $
3    *
4    *   Copyright 2004 The Apache Software Foundation
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   *
18   */
19  package org.apache.mina.integration.spring.ssl;
20  
21  import java.security.InvalidAlgorithmParameterException;
22  import java.security.KeyStore;
23  import java.security.KeyStoreException;
24  import java.security.Provider;
25  import java.security.cert.CertificateException;
26  import java.security.cert.X509Certificate;
27  
28  import javax.net.ssl.ManagerFactoryParameters;
29  import javax.net.ssl.TrustManager;
30  import javax.net.ssl.TrustManagerFactory;
31  import javax.net.ssl.TrustManagerFactorySpi;
32  import javax.net.ssl.X509TrustManager;
33  
34  /***
35   * Bogus {@link javax.net.ssl.TrustManagerFactory} which creates 
36   * {@link javax.net.ssl.X509TrustManager} trusting everything.
37   *
38   * @author The Apache Directory Project (dev@directory.apache.org)
39   * @version $Rev: 326586 $, $Date: 2005-10-19 17:50:29 +0200 (ons, 19 okt 2005) $
40   */
41  public class BogusTrustManagerFactory extends TrustManagerFactory
42  {
43  
44      public BogusTrustManagerFactory()
45      {
46          super( new BogusTrustManagerFactorySpi(), 
47                 new Provider("MinaBogus", 1.0, "") {}, "MinaBogus" );
48      }
49      
50      private static final X509TrustManager X509 = new X509TrustManager()
51      {
52          public void checkClientTrusted( X509Certificate[] x509Certificates,
53                                         String s ) throws CertificateException
54          {
55          }
56  
57          public void checkServerTrusted( X509Certificate[] x509Certificates,
58                                         String s ) throws CertificateException
59          {
60          }
61  
62          public X509Certificate[] getAcceptedIssuers()
63          {
64              return new X509Certificate[ 0 ];
65          }
66      };
67  
68      private static final TrustManager[] X509_MANAGERS = new TrustManager[] { X509 };
69  
70      private static class BogusTrustManagerFactorySpi extends TrustManagerFactorySpi
71      {
72      
73          protected TrustManager[] engineGetTrustManagers()
74          {
75              return X509_MANAGERS;
76          }
77      
78          protected void engineInit( KeyStore keystore ) throws KeyStoreException
79          {
80              // noop
81          }
82      
83          protected void engineInit(
84                                    ManagerFactoryParameters managerFactoryParameters )
85                  throws InvalidAlgorithmParameterException
86          {
87              // noop
88          }
89      
90      }
91  }