KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > security > DummySSLSocketFactory


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.security;
25
26 import java.io.*;
27 import java.net.*;
28 import javax.net.SocketFactory;
29 import javax.net.ssl.SSLSocketFactory;
30 import javax.net.ssl.*;
31
32
33 /**
34  * <p>Socket factory for SSL jndi links that returns an SSL socket.
35  * It incorporates a keystore, which must contain the certs used
36  * to authenticate the client.</p>
37  *
38  * <p>This code is based on sample code made freely available by author
39  * Spencer W. Thomas on his web site http://hubris.engin.umich.edu/java/
40  * On Wed 24 May, 2000.</p>
41  *
42  * <p><b>Warning</b></p>
43  *
44  * <p>This class relies heavily on an internal, single, static SSLSocketFactory.
45  * multiple objects of this type in fact will use the same internal SSLSocketFactory.
46  * (This is why a single static init() method sets up everything for the entire
47  * class.) The reason for this structure is that JndiSocketFactory is dynmaically
48  * invoked by the jndi connection, and we have no other chance to initialise the
49  * object.</p>
50  */

51
52 public class DummySSLSocketFactory extends SSLSocketFactory
53 {
54     private SSLSocketFactory factory;
55
56     public DummySSLSocketFactory()
57     {
58         try
59         {
60             SSLContext sslcontext = SSLContext.getInstance( "TLS");
61             sslcontext.init( null, // No KeyManager required
62
new TrustManager[] { new DummyTrustManager()},
63             new java.security.SecureRandom JavaDoc());
64             factory = ( SSLSocketFactory) sslcontext.getSocketFactory();
65
66         }
67         catch( Exception JavaDoc ex)
68         {
69             ex.printStackTrace();
70         }
71     }
72
73     public static SocketFactory getDefault()
74     {
75       return new DummySSLSocketFactory();
76     }
77
78     public Socket createSocket() throws IOException
79     {
80         return factory.createSocket();
81     }
82
83     public Socket createSocket( Socket socket, String JavaDoc s, int i, boolean flag) throws IOException
84     {
85         return factory.createSocket( socket, s, i, flag);
86     }
87
88     public Socket createSocket( InetAddress inaddr, int i, InetAddress inaddr1, int j) throws IOException
89     {
90         return factory.createSocket( inaddr, i, inaddr1, j);
91     }
92
93     public Socket createSocket( InetAddress inaddr, int i) throws IOException
94     {
95         return factory.createSocket( inaddr, i);
96     }
97
98     public Socket createSocket( String JavaDoc s, int i, InetAddress inaddr, int j) throws IOException
99     {
100         return factory.createSocket( s, i, inaddr, j);
101     }
102
103     public Socket createSocket( String JavaDoc s, int i) throws IOException
104     {
105         return factory.createSocket( s, i);
106     }
107
108     public String JavaDoc[] getDefaultCipherSuites()
109     {
110         return factory.getSupportedCipherSuites();
111     }
112
113     public String JavaDoc[] getSupportedCipherSuites()
114     {
115         return factory.getSupportedCipherSuites();
116     }
117 }
Popular Tags