Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/axis/components/net/SunFakeTrustSocketFactory.java


1   /*
2    * Copyright 2001-2004 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.axis.components.net;
17  
18  import java.util.Hashtable;
19  
20  import org.apache.axis.components.logger.LogFactory;
21  import org.apache.axis.utils.Messages;
22  import org.apache.commons.logging.Log;
23  
24  import com.sun.net.ssl.SSLContext;
25  import com.sun.net.ssl.TrustManager;
26  import com.sun.net.ssl.X509TrustManager;
27  
28  /**
29   * Hook for Axis sender, allowing unsigned server certs
30   */
31  public class SunFakeTrustSocketFactory extends SunJSSESocketFactory {
32  
33      /** Field log           */
34      protected static Log log =
35              LogFactory.getLog(SunFakeTrustSocketFactory.class.getName());
36  
37      /**
38       * Constructor FakeTrustSocketFactory
39       *
40       * @param attributes
41       */
42      public SunFakeTrustSocketFactory(Hashtable attributes) {
43          super(attributes);
44      }
45  
46      /**
47       * Method getContext
48       *
49       * @return
50       *
51       * @throws Exception
52       */
53      protected SSLContext getContext() throws Exception {
54  
55          try {
56              SSLContext sc = SSLContext.getInstance("SSL");
57  
58              sc.init(null, // we don't need no stinkin KeyManager
59                      new TrustManager[]{new FakeX509TrustManager()},
60                      new java.security.SecureRandom());
61              if (log.isDebugEnabled()) {
62                  log.debug(Messages.getMessage("ftsf00"));
63              }
64              return sc;
65          } catch (Exception exc) {
66              log.error(Messages.getMessage("ftsf01"), exc);
67              throw new Exception(Messages.getMessage("ftsf02"));
68          }
69      }
70  
71      /**
72       * Class FakeX509TrustManager
73       */
74      public static class FakeX509TrustManager implements X509TrustManager {
75  
76          /** Field log           */
77          protected static Log log =
78                  LogFactory.getLog(FakeX509TrustManager.class.getName());
79  
80          /**
81           * Method isClientTrusted
82           *
83           * @param chain
84           *
85           * @return
86           */
87          public boolean isClientTrusted(java.security.cert
88                  .X509Certificate[] chain) {
89  
90              if (log.isDebugEnabled()) {
91                  log.debug(Messages.getMessage("ftsf03"));
92              }
93              return true;
94          }
95  
96          /**
97           * Method isServerTrusted
98           *
99           * @param chain
100          *
101          * @return
102          */
103         public boolean isServerTrusted(java.security.cert
104                 .X509Certificate[] chain) {
105 
106             if (log.isDebugEnabled()) {
107                 log.debug(Messages.getMessage("ftsf04"));
108             }
109             return true;
110         }
111 
112         /**
113          * Method getAcceptedIssuers
114          *
115          * @return
116          */
117         public java.security.cert.X509Certificate[] getAcceptedIssuers() {
118 
119             if (log.isDebugEnabled()) {
120                 log.debug(Messages.getMessage("ftsf05"));
121             }
122             return null;
123         }
124     }
125 }