1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.servlet.jetty; |
12 | |
|
13 | |
import org.mule.api.MuleContext; |
14 | |
import org.mule.api.lifecycle.CreateException; |
15 | |
import org.mule.api.lifecycle.InitialisationException; |
16 | |
import org.mule.api.security.TlsDirectKeyStore; |
17 | |
import org.mule.api.security.TlsDirectTrustStore; |
18 | |
import org.mule.api.security.TlsIndirectKeyStore; |
19 | |
import org.mule.api.security.TlsProtocolHandler; |
20 | |
import org.mule.api.security.provider.SecurityProviderFactory; |
21 | |
import org.mule.api.security.tls.TlsConfiguration; |
22 | |
import org.mule.util.SystemUtils; |
23 | |
|
24 | |
import java.io.IOException; |
25 | |
import java.security.Provider; |
26 | |
|
27 | |
import javax.net.ssl.KeyManagerFactory; |
28 | |
import javax.net.ssl.TrustManagerFactory; |
29 | |
|
30 | |
import org.mortbay.jetty.AbstractConnector; |
31 | |
import org.mortbay.jetty.security.SslSocketConnector; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class JettyHttpsConnector extends JettyHttpConnector implements TlsDirectKeyStore, TlsIndirectKeyStore, TlsDirectTrustStore, TlsProtocolHandler |
39 | |
{ |
40 | |
|
41 | |
public static final String JETTY_SSL = "jetty-ssl"; |
42 | |
public static final String HTTPS = "https"; |
43 | |
public static final String PEER_CERTIFICATES = "PEER_CERTIFICATES"; |
44 | |
public static final String LOCAL_CERTIFICATES = "LOCAL_CERTIFICATES"; |
45 | |
|
46 | 0 | private TlsConfiguration tls = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE); |
47 | |
|
48 | |
public JettyHttpsConnector(MuleContext context) |
49 | |
{ |
50 | 0 | super(context); |
51 | 0 | registerSupportedProtocol("https"); |
52 | 0 | registerSupportedProtocol("jetty-ssl"); |
53 | 0 | } |
54 | |
|
55 | |
protected void doInitialise() throws InitialisationException |
56 | |
{ |
57 | 0 | validateSslConfig(); |
58 | 0 | super.doInitialise(); |
59 | 0 | } |
60 | |
|
61 | |
protected void validateSslConfig() throws InitialisationException |
62 | |
{ |
63 | |
try |
64 | |
{ |
65 | 0 | tls.initialise(false, TlsConfiguration.JSSE_NAMESPACE); |
66 | |
} |
67 | 0 | catch (CreateException e) |
68 | |
{ |
69 | 0 | throw new InitialisationException(e, this); |
70 | 0 | } |
71 | 0 | } |
72 | |
|
73 | |
public String getProtocol() |
74 | |
{ |
75 | 0 | return JETTY_SSL; |
76 | |
} |
77 | |
|
78 | |
public String getClientKeyStore() |
79 | |
{ |
80 | 0 | return tls.getClientKeyStore(); |
81 | |
} |
82 | |
|
83 | |
public String getClientKeyStorePassword() |
84 | |
{ |
85 | 0 | return tls.getClientKeyStorePassword(); |
86 | |
} |
87 | |
|
88 | |
public String getClientKeyStoreType() |
89 | |
{ |
90 | 0 | return this.tls.getClientKeyStoreType(); |
91 | |
} |
92 | |
|
93 | |
public String getKeyManagerAlgorithm() |
94 | |
{ |
95 | 0 | return tls.getKeyManagerAlgorithm(); |
96 | |
} |
97 | |
|
98 | |
public KeyManagerFactory getKeyManagerFactory() |
99 | |
{ |
100 | 0 | return tls.getKeyManagerFactory(); |
101 | |
} |
102 | |
|
103 | |
public String getKeyPassword() |
104 | |
{ |
105 | 0 | return tls.getKeyPassword(); |
106 | |
} |
107 | |
|
108 | |
public String getKeyStore() |
109 | |
{ |
110 | 0 | return tls.getKeyStore(); |
111 | |
} |
112 | |
|
113 | |
public String getKeyStoreType() |
114 | |
{ |
115 | 0 | return tls.getKeyStoreType(); |
116 | |
} |
117 | |
|
118 | |
public String getProtocolHandler() |
119 | |
{ |
120 | 0 | return tls.getProtocolHandler(); |
121 | |
} |
122 | |
|
123 | |
public Provider getProvider() |
124 | |
{ |
125 | 0 | return tls.getProvider(); |
126 | |
} |
127 | |
|
128 | |
public SecurityProviderFactory getSecurityProviderFactory() |
129 | |
{ |
130 | 0 | return tls.getSecurityProviderFactory(); |
131 | |
} |
132 | |
|
133 | |
public String getSslType() |
134 | |
{ |
135 | 0 | return tls.getSslType(); |
136 | |
} |
137 | |
|
138 | |
public String getKeyStorePassword() |
139 | |
{ |
140 | 0 | return tls.getKeyStorePassword(); |
141 | |
} |
142 | |
|
143 | |
public String getTrustManagerAlgorithm() |
144 | |
{ |
145 | 0 | return tls.getTrustManagerAlgorithm(); |
146 | |
} |
147 | |
|
148 | |
public TrustManagerFactory getTrustManagerFactory() |
149 | |
{ |
150 | 0 | return tls.getTrustManagerFactory(); |
151 | |
} |
152 | |
|
153 | |
public String getTrustStore() |
154 | |
{ |
155 | 0 | return tls.getTrustStore(); |
156 | |
} |
157 | |
|
158 | |
public String getTrustStorePassword() |
159 | |
{ |
160 | 0 | return tls.getTrustStorePassword(); |
161 | |
} |
162 | |
|
163 | |
public String getTrustStoreType() |
164 | |
{ |
165 | 0 | return tls.getTrustStoreType(); |
166 | |
} |
167 | |
|
168 | |
public boolean isExplicitTrustStoreOnly() |
169 | |
{ |
170 | 0 | return tls.isExplicitTrustStoreOnly(); |
171 | |
} |
172 | |
|
173 | |
public boolean isRequireClientAuthentication() |
174 | |
{ |
175 | 0 | return tls.isRequireClientAuthentication(); |
176 | |
} |
177 | |
|
178 | |
public void setClientKeyStore(String clientKeyStore) throws IOException |
179 | |
{ |
180 | 0 | tls.setClientKeyStore(clientKeyStore); |
181 | 0 | } |
182 | |
|
183 | |
public void setClientKeyStorePassword(String clientKeyStorePassword) |
184 | |
{ |
185 | 0 | tls.setClientKeyStorePassword(clientKeyStorePassword); |
186 | 0 | } |
187 | |
|
188 | |
public void setClientKeyStoreType(String clientKeyStoreType) |
189 | |
{ |
190 | 0 | this.tls.setClientKeyStoreType(clientKeyStoreType); |
191 | 0 | } |
192 | |
|
193 | |
public void setExplicitTrustStoreOnly(boolean explicitTrustStoreOnly) |
194 | |
{ |
195 | 0 | tls.setExplicitTrustStoreOnly(explicitTrustStoreOnly); |
196 | 0 | } |
197 | |
|
198 | |
public void setKeyManagerAlgorithm(String keyManagerAlgorithm) |
199 | |
{ |
200 | 0 | tls.setKeyManagerAlgorithm(keyManagerAlgorithm); |
201 | 0 | } |
202 | |
|
203 | |
public void setKeyPassword(String keyPassword) |
204 | |
{ |
205 | 0 | tls.setKeyPassword(keyPassword); |
206 | 0 | } |
207 | |
|
208 | |
public void setKeyStore(String keyStore) throws IOException |
209 | |
{ |
210 | 0 | tls.setKeyStore(keyStore); |
211 | 0 | } |
212 | |
|
213 | |
public void setKeyStoreType(String keystoreType) |
214 | |
{ |
215 | 0 | tls.setKeyStoreType(keystoreType); |
216 | 0 | } |
217 | |
|
218 | |
public void setProtocolHandler(String protocolHandler) |
219 | |
{ |
220 | 0 | tls.setProtocolHandler(protocolHandler); |
221 | 0 | } |
222 | |
|
223 | |
public void setProvider(Provider provider) |
224 | |
{ |
225 | 0 | tls.setProvider(provider); |
226 | 0 | } |
227 | |
|
228 | |
public void setRequireClientAuthentication(boolean requireClientAuthentication) |
229 | |
{ |
230 | 0 | tls.setRequireClientAuthentication(requireClientAuthentication); |
231 | 0 | } |
232 | |
|
233 | |
public void setSecurityProviderFactory(SecurityProviderFactory spFactory) |
234 | |
{ |
235 | 0 | tls.setSecurityProviderFactory(spFactory); |
236 | 0 | } |
237 | |
|
238 | |
public void setSslType(String sslType) |
239 | |
{ |
240 | 0 | tls.setSslType(sslType); |
241 | 0 | } |
242 | |
|
243 | |
public void setKeyStorePassword(String storePassword) |
244 | |
{ |
245 | 0 | tls.setKeyStorePassword(storePassword); |
246 | 0 | } |
247 | |
|
248 | |
public void setTrustManagerAlgorithm(String trustManagerAlgorithm) |
249 | |
{ |
250 | 0 | tls.setTrustManagerAlgorithm(trustManagerAlgorithm); |
251 | 0 | } |
252 | |
|
253 | |
public void setTrustManagerFactory(TrustManagerFactory trustManagerFactory) |
254 | |
{ |
255 | 0 | tls.setTrustManagerFactory(trustManagerFactory); |
256 | 0 | } |
257 | |
|
258 | |
public void setTrustStore(String trustStore) throws IOException |
259 | |
{ |
260 | 0 | tls.setTrustStore(trustStore); |
261 | 0 | } |
262 | |
|
263 | |
public void setTrustStorePassword(String trustStorePassword) |
264 | |
{ |
265 | 0 | tls.setTrustStorePassword(trustStorePassword); |
266 | 0 | } |
267 | |
|
268 | |
public void setTrustStoreType(String trustStoreType) |
269 | |
{ |
270 | 0 | tls.setTrustStoreType(trustStoreType); |
271 | 0 | } |
272 | |
|
273 | |
@Override |
274 | |
protected AbstractConnector createJettyConnector() |
275 | |
{ |
276 | 0 | SslSocketConnector cnn = new SslSocketConnector(); |
277 | |
|
278 | 0 | if (SystemUtils.isIbmJDK()) |
279 | |
{ |
280 | 0 | cnn.setProtocol("SSL_TLS"); |
281 | |
} |
282 | |
|
283 | 0 | if (tls.getKeyStore() != null) cnn.setKeystore(tls.getKeyStore()); |
284 | 0 | if (tls.getKeyPassword() != null) cnn.setKeyPassword(tls.getKeyPassword()); |
285 | 0 | if (tls.getKeyStoreType() != null) cnn.setKeystoreType(tls.getKeyStoreType()); |
286 | 0 | if (tls.getKeyManagerAlgorithm() != null) cnn.setSslKeyManagerFactoryAlgorithm(tls.getKeyManagerAlgorithm()); |
287 | 0 | if (tls.getProvider() != null) cnn.setProvider(tls.getProvider().getName()); |
288 | 0 | if (tls.getTrustStorePassword() != null) cnn.setTrustPassword(tls.getTrustStorePassword()); |
289 | 0 | if (tls.getTrustStore() != null) cnn.setTruststore(tls.getTrustStore()); |
290 | 0 | if (tls.getTrustStoreType() != null) cnn.setTruststoreType(tls.getTrustStoreType()); |
291 | 0 | if (tls.getTrustManagerAlgorithm() != null) cnn.setSslTrustManagerFactoryAlgorithm(tls.getTrustManagerAlgorithm()); |
292 | 0 | return cnn; |
293 | |
} |
294 | |
} |