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