View Javadoc
1   /*
2    * Copyright 2013 The Apache Software Foundation.
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  package org.apache.juddi.v3.client.mapping;
17  
18  import java.io.IOException;
19  import java.security.KeyManagementException;
20  import java.security.KeyStoreException;
21  import java.security.NoSuchAlgorithmException;
22  import java.security.UnrecoverableKeyException;
23  import java.security.cert.CertificateException;
24  import java.security.cert.X509Certificate;
25  import javax.net.ssl.SSLException;
26  import javax.net.ssl.SSLSession;
27  import javax.net.ssl.SSLSocket;
28  import org.apache.http.conn.ssl.SSLSocketFactory;
29  
30  import org.apache.http.conn.ssl.TrustStrategy;
31  import org.apache.http.conn.ssl.X509HostnameVerifier;
32  
33  /**
34   *
35   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
36   */
37  public class MockSSLSocketFactory extends SSLSocketFactory {
38  
39      public MockSSLSocketFactory() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
40          super(trustStrategy, hostnameVerifier);
41      }
42      private static final X509HostnameVerifier hostnameVerifier = new X509HostnameVerifier() {
43          //@Override
44          public void verify(String host, SSLSocket ssl) throws IOException {
45              // Do nothing
46          }
47  
48          //@Override
49          public void verify(String host, X509Certificate cert) throws SSLException {
50              //Do nothing
51          }
52  
53          //@Override
54          public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException {
55              //Do nothing
56          }
57  
58          //@Override
59          public boolean verify(String s, SSLSession sslSession) {
60              return true;
61          }
62      };
63      private static final TrustStrategy trustStrategy = new TrustStrategy() {
64          //@Override
65          public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
66              return true;
67          }
68      };
69  }