1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.api.security.tls; |
12 | |
|
13 | |
import java.io.IOException; |
14 | |
import java.net.InetAddress; |
15 | |
import java.net.Socket; |
16 | |
|
17 | |
import javax.net.ssl.SSLSocketFactory; |
18 | |
|
19 | |
import org.apache.commons.logging.Log; |
20 | |
import org.apache.commons.logging.LogFactory; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class TlsPropertiesSocketFactory extends SSLSocketFactory |
27 | |
{ |
28 | |
|
29 | 2 | private Log logger = LogFactory.getLog(getClass()); |
30 | |
private boolean anon; |
31 | |
private String namespace; |
32 | |
private SSLSocketFactory factory; |
33 | |
|
34 | |
public TlsPropertiesSocketFactory(boolean anon, String namespace) |
35 | |
{ |
36 | 2 | super(); |
37 | 2 | logger.debug("creating: " + anon + "; " + namespace); |
38 | 2 | this.anon = anon; |
39 | 2 | this.namespace = namespace; |
40 | 2 | } |
41 | |
|
42 | |
private synchronized SSLSocketFactory getFactory() throws IOException |
43 | |
{ |
44 | 2 | if (null == factory) |
45 | |
{ |
46 | 2 | logger.debug("creating factory"); |
47 | 2 | TlsPropertiesMapper propertiesMapper = new TlsPropertiesMapper(namespace); |
48 | 2 | TlsConfiguration configuration = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE); |
49 | 2 | propertiesMapper.readFromProperties(configuration, System.getProperties()); |
50 | |
try |
51 | |
{ |
52 | 2 | configuration.initialise(anon, namespace); |
53 | 2 | factory = configuration.getSocketFactory(); |
54 | |
} |
55 | 0 | catch (Exception e) |
56 | |
{ |
57 | 0 | throw (IOException) new IOException(e.getMessage()).initCause(e); |
58 | 2 | } |
59 | |
} |
60 | 2 | return factory; |
61 | |
} |
62 | |
|
63 | |
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException |
64 | |
{ |
65 | 0 | return getFactory().createSocket(s, host, port, autoClose); |
66 | |
} |
67 | |
|
68 | |
public String[] getDefaultCipherSuites() |
69 | |
{ |
70 | |
try |
71 | |
{ |
72 | 0 | return getFactory().getDefaultCipherSuites(); |
73 | |
} |
74 | 0 | catch (Exception e) |
75 | |
{ |
76 | 0 | return new String[0]; |
77 | |
} |
78 | |
} |
79 | |
|
80 | |
public String[] getSupportedCipherSuites() |
81 | |
{ |
82 | |
try |
83 | |
{ |
84 | 2 | return getFactory().getSupportedCipherSuites(); |
85 | |
} |
86 | 0 | catch (Exception e) |
87 | |
{ |
88 | 0 | return new String[0]; |
89 | |
} |
90 | |
} |
91 | |
|
92 | |
public Socket createSocket(String arg0, int arg1) throws IOException |
93 | |
{ |
94 | 0 | return getFactory().createSocket(arg0, arg1); |
95 | |
} |
96 | |
|
97 | |
public Socket createSocket(InetAddress arg0, int arg1) throws IOException |
98 | |
{ |
99 | 0 | return getFactory().createSocket(arg0, arg1); |
100 | |
} |
101 | |
|
102 | |
public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException |
103 | |
{ |
104 | 0 | return getFactory().createSocket(arg0, arg1); |
105 | |
} |
106 | |
|
107 | |
public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException |
108 | |
{ |
109 | 0 | return getFactory().createSocket(arg0, arg1, arg2, arg3); |
110 | |
} |
111 | |
|
112 | |
|
113 | |
public Socket createSocket() throws IOException |
114 | |
{ |
115 | 0 | return getFactory().createSocket(); |
116 | |
} |
117 | |
|
118 | |
} |
119 | |
|
120 | |
|