KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > internal > model > DummySSLSocketFactory


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. 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,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.core.internal.model;
22
23
24 import java.io.IOException JavaDoc;
25 import java.net.InetAddress JavaDoc;
26 import java.net.Socket JavaDoc;
27 import java.net.UnknownHostException JavaDoc;
28 import java.security.SecureRandom JavaDoc;
29 import java.security.cert.CertificateException JavaDoc;
30 import java.security.cert.X509Certificate JavaDoc;
31
32 import javax.net.SocketFactory;
33 import javax.net.ssl.SSLContext;
34 import javax.net.ssl.SSLSocketFactory;
35 import javax.net.ssl.TrustManager;
36 import javax.net.ssl.X509TrustManager;
37
38
39 public class DummySSLSocketFactory extends SSLSocketFactory
40 {
41
42     private static SocketFactory instance;
43
44
45     public static SocketFactory getDefault()
46     {
47         if ( instance == null )
48         {
49             instance = new DummySSLSocketFactory();
50         }
51         return instance;
52     }
53
54     private SSLSocketFactory delegate;
55
56
57     public DummySSLSocketFactory()
58     {
59
60         try
61         {
62             TrustManager tm = new X509TrustManager()
63             {
64                 public X509Certificate JavaDoc[] getAcceptedIssuers()
65                 {
66                     return new X509Certificate JavaDoc[0];
67                 }
68
69
70                 public void checkClientTrusted( X509Certificate JavaDoc[] arg0, String JavaDoc arg1 ) throws CertificateException JavaDoc
71                 {
72                 }
73
74
75                 public void checkServerTrusted( X509Certificate JavaDoc[] arg0, String JavaDoc arg1 ) throws CertificateException JavaDoc
76                 {
77                 }
78             };
79             TrustManager[] tma =
80                 { tm };
81             SSLContext sc = SSLContext.getInstance( "TLS" ); //$NON-NLS-1$
82
sc.init( null, tma, new SecureRandom JavaDoc() );
83             delegate = sc.getSocketFactory();
84
85         }
86         catch ( Exception JavaDoc e )
87         {
88             e.printStackTrace();
89         }
90
91     }
92
93
94     public String JavaDoc[] getDefaultCipherSuites()
95     {
96         return delegate.getDefaultCipherSuites();
97     }
98
99
100     public String JavaDoc[] getSupportedCipherSuites()
101     {
102         return delegate.getSupportedCipherSuites();
103     }
104
105
106     public Socket JavaDoc createSocket( Socket JavaDoc arg0, String JavaDoc arg1, int arg2, boolean arg3 ) throws IOException JavaDoc
107     {
108         try
109         {
110             return delegate.createSocket( arg0, arg1, arg2, arg3 );
111         }
112         catch ( IOException JavaDoc e )
113         {
114             e.printStackTrace();
115             throw e;
116         }
117     }
118
119
120     public Socket JavaDoc createSocket( String JavaDoc arg0, int arg1 ) throws IOException JavaDoc, UnknownHostException JavaDoc
121     {
122         try
123         {
124             return delegate.createSocket( arg0, arg1 );
125         }
126         catch ( IOException JavaDoc e )
127         {
128             e.printStackTrace();
129             throw e;
130         }
131     }
132
133
134     public Socket JavaDoc createSocket( InetAddress JavaDoc arg0, int arg1 ) throws IOException JavaDoc
135     {
136         try
137         {
138             return delegate.createSocket( arg0, arg1 );
139         }
140         catch ( IOException JavaDoc e )
141         {
142             e.printStackTrace();
143             throw e;
144         }
145     }
146
147
148     public Socket JavaDoc createSocket( String JavaDoc arg0, int arg1, InetAddress JavaDoc arg2, int arg3 ) throws IOException JavaDoc,
149         UnknownHostException JavaDoc
150     {
151         try
152         {
153             return delegate.createSocket( arg0, arg1, arg2, arg3 );
154         }
155         catch ( IOException JavaDoc e )
156         {
157             e.printStackTrace();
158             throw e;
159         }
160     }
161
162
163     public Socket JavaDoc createSocket( InetAddress JavaDoc arg0, int arg1, InetAddress JavaDoc arg2, int arg3 ) throws IOException JavaDoc
164     {
165         try
166         {
167             return delegate.createSocket( arg0, arg1, arg2, arg3 );
168         }
169         catch ( IOException JavaDoc e )
170         {
171             e.printStackTrace();
172             throw e;
173         }
174     }
175
176 }
177
Popular Tags