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