36
36
import javax .servlet .http .HttpServletResponse ;
37
37
38
38
import org .eclipse .jetty .http .HttpMethod ;
39
- import org .eclipse .jetty .http .HttpVersion ;
40
39
import org .eclipse .jetty .http .MimeTypes ;
41
40
import org .eclipse .jetty .server .AbstractConnector ;
42
41
import org .eclipse .jetty .server .ConnectionFactory ;
43
42
import org .eclipse .jetty .server .Connector ;
44
43
import org .eclipse .jetty .server .ForwardedRequestCustomizer ;
45
44
import org .eclipse .jetty .server .Handler ;
46
45
import org .eclipse .jetty .server .HttpConfiguration ;
47
- import org .eclipse .jetty .server .HttpConnectionFactory ;
48
46
import org .eclipse .jetty .server .Request ;
49
- import org .eclipse .jetty .server .SecureRequestCustomizer ;
50
47
import org .eclipse .jetty .server .Server ;
51
48
import org .eclipse .jetty .server .ServerConnector ;
52
- import org .eclipse .jetty .server .SslConnectionFactory ;
53
49
import org .eclipse .jetty .server .handler .ErrorHandler ;
54
50
import org .eclipse .jetty .server .handler .HandlerWrapper ;
55
51
import org .eclipse .jetty .server .handler .gzip .GzipHandler ;
62
58
import org .eclipse .jetty .util .resource .JarResource ;
63
59
import org .eclipse .jetty .util .resource .Resource ;
64
60
import org .eclipse .jetty .util .resource .ResourceCollection ;
65
- import org .eclipse .jetty .util .ssl .SslContextFactory ;
66
61
import org .eclipse .jetty .util .thread .ThreadPool ;
67
62
import org .eclipse .jetty .webapp .AbstractConfiguration ;
68
63
import org .eclipse .jetty .webapp .Configuration ;
71
66
import org .springframework .boot .web .server .Compression ;
72
67
import org .springframework .boot .web .server .ErrorPage ;
73
68
import org .springframework .boot .web .server .MimeMappings ;
74
- import org .springframework .boot .web .server .Ssl ;
75
- import org .springframework .boot .web .server .Ssl .ClientAuth ;
76
69
import org .springframework .boot .web .server .WebServer ;
77
- import org .springframework .boot .web .server .WebServerException ;
78
70
import org .springframework .boot .web .servlet .ServletContextInitializer ;
79
71
import org .springframework .boot .web .servlet .server .AbstractServletWebServerFactory ;
80
72
import org .springframework .boot .web .servlet .server .ServletWebServerFactory ;
81
73
import org .springframework .context .ResourceLoaderAware ;
82
74
import org .springframework .core .io .ResourceLoader ;
83
75
import org .springframework .util .Assert ;
84
- import org .springframework .util .ObjectUtils ;
85
- import org .springframework .util .ResourceUtils ;
86
76
import org .springframework .util .StringUtils ;
87
77
88
78
/**
@@ -163,13 +153,9 @@ public WebServer getWebServer(ServletContextInitializer... initializers) {
163
153
configureWebAppContext (context , initializers );
164
154
server .setHandler (addHandlerWrappers (context ));
165
155
this .logger .info ("Server initialized with port: " + port );
166
- if (getSsl () != null && getSsl ().isEnabled ()) {
167
- SslContextFactory sslContextFactory = new SslContextFactory ();
168
- configureSsl (sslContextFactory , getSsl ());
169
- AbstractConnector connector = createSslConnector (server , sslContextFactory ,
170
- port );
171
- server .setConnectors (new Connector [] { connector });
172
- }
156
+ SslServerCustomizer sslServerCustomizer = new SslServerCustomizer (port ,
157
+ getSsl (), getSslStoreProvider ());
158
+ sslServerCustomizer .customize (server );
173
159
for (JettyServerCustomizer customizer : getServerCustomizers ()) {
174
160
customizer .customize (server );
175
161
}
@@ -181,7 +167,7 @@ public WebServer getWebServer(ServletContextInitializer... initializers) {
181
167
182
168
private Server createServer (InetSocketAddress address ) {
183
169
Server server = new Server (getThreadPool ());
184
- server .setConnectors (new Connector [] { createConnector (address , server ) });
170
+ server .setConnectors (new Connector [] {createConnector (address , server )});
185
171
return server ;
186
172
}
187
173
@@ -199,20 +185,6 @@ private AbstractConnector createConnector(InetSocketAddress address, Server serv
199
185
return connector ;
200
186
}
201
187
202
- private AbstractConnector createSslConnector (Server server ,
203
- SslContextFactory sslContextFactory , int port ) {
204
- HttpConfiguration config = new HttpConfiguration ();
205
- config .setSendServerVersion (false );
206
- config .addCustomizer (new SecureRequestCustomizer ());
207
- HttpConnectionFactory connectionFactory = new HttpConnectionFactory (config );
208
- SslConnectionFactory sslConnectionFactory = new SslConnectionFactory (
209
- sslContextFactory , HttpVersion .HTTP_1_1 .asString ());
210
- ServerConnector serverConnector = new ServerConnector (server ,
211
- sslConnectionFactory , connectionFactory );
212
- serverConnector .setPort (port );
213
- return serverConnector ;
214
- }
215
-
216
188
private Handler addHandlerWrappers (Handler handler ) {
217
189
if (getCompression () != null && getCompression ().getEnabled ()) {
218
190
handler = applyWrapper (handler , createGzipHandler ());
@@ -242,96 +214,6 @@ private HandlerWrapper createGzipHandler() {
242
214
return handler ;
243
215
}
244
216
245
- /**
246
- * Configure the SSL connection.
247
- * @param factory the Jetty {@link SslContextFactory}.
248
- * @param ssl the ssl details.
249
- */
250
- protected void configureSsl (SslContextFactory factory , Ssl ssl ) {
251
- factory .setProtocol (ssl .getProtocol ());
252
- configureSslClientAuth (factory , ssl );
253
- configureSslPasswords (factory , ssl );
254
- factory .setCertAlias (ssl .getKeyAlias ());
255
- if (!ObjectUtils .isEmpty (ssl .getCiphers ())) {
256
- factory .setIncludeCipherSuites (ssl .getCiphers ());
257
- factory .setExcludeCipherSuites ();
258
- }
259
- if (ssl .getEnabledProtocols () != null ) {
260
- factory .setIncludeProtocols (ssl .getEnabledProtocols ());
261
- }
262
- if (getSslStoreProvider () != null ) {
263
- try {
264
- factory .setKeyStore (getSslStoreProvider ().getKeyStore ());
265
- factory .setTrustStore (getSslStoreProvider ().getTrustStore ());
266
- }
267
- catch (Exception ex ) {
268
- throw new IllegalStateException ("Unable to set SSL store" , ex );
269
- }
270
- }
271
- else {
272
- configureSslKeyStore (factory , ssl );
273
- configureSslTrustStore (factory , ssl );
274
- }
275
- }
276
-
277
- private void configureSslClientAuth (SslContextFactory factory , Ssl ssl ) {
278
- if (ssl .getClientAuth () == ClientAuth .NEED ) {
279
- factory .setNeedClientAuth (true );
280
- factory .setWantClientAuth (true );
281
- }
282
- else if (ssl .getClientAuth () == ClientAuth .WANT ) {
283
- factory .setWantClientAuth (true );
284
- }
285
- }
286
-
287
- private void configureSslPasswords (SslContextFactory factory , Ssl ssl ) {
288
- if (ssl .getKeyStorePassword () != null ) {
289
- factory .setKeyStorePassword (ssl .getKeyStorePassword ());
290
- }
291
- if (ssl .getKeyPassword () != null ) {
292
- factory .setKeyManagerPassword (ssl .getKeyPassword ());
293
- }
294
- }
295
-
296
- private void configureSslKeyStore (SslContextFactory factory , Ssl ssl ) {
297
- try {
298
- URL url = ResourceUtils .getURL (ssl .getKeyStore ());
299
- factory .setKeyStoreResource (Resource .newResource (url ));
300
- }
301
- catch (IOException ex ) {
302
- throw new WebServerException (
303
- "Could not find key store '" + ssl .getKeyStore () + "'" , ex );
304
- }
305
- if (ssl .getKeyStoreType () != null ) {
306
- factory .setKeyStoreType (ssl .getKeyStoreType ());
307
- }
308
- if (ssl .getKeyStoreProvider () != null ) {
309
- factory .setKeyStoreProvider (ssl .getKeyStoreProvider ());
310
- }
311
- }
312
-
313
- private void configureSslTrustStore (SslContextFactory factory , Ssl ssl ) {
314
- if (ssl .getTrustStorePassword () != null ) {
315
- factory .setTrustStorePassword (ssl .getTrustStorePassword ());
316
- }
317
- if (ssl .getTrustStore () != null ) {
318
- try {
319
- URL url = ResourceUtils .getURL (ssl .getTrustStore ());
320
- factory .setTrustStoreResource (Resource .newResource (url ));
321
- }
322
- catch (IOException ex ) {
323
- throw new WebServerException (
324
- "Could not find trust store '" + ssl .getTrustStore () + "'" , ex );
325
- }
326
- }
327
- if (ssl .getTrustStoreType () != null ) {
328
- factory .setTrustStoreType (ssl .getTrustStoreType ());
329
- }
330
- if (ssl .getTrustStoreProvider () != null ) {
331
- factory .setTrustStoreProvider (ssl .getTrustStoreProvider ());
332
- }
333
- }
334
-
335
217
/**
336
218
* Configure the given Jetty {@link WebAppContext} for use.
337
219
* @param context the context to configure
@@ -456,7 +338,7 @@ protected final void addJspServlet(WebAppContext context) {
456
338
context .getServletHandler ().addServlet (holder );
457
339
ServletMapping mapping = new ServletMapping ();
458
340
mapping .setServletName ("jsp" );
459
- mapping .setPathSpecs (new String [] { "*.jsp" , "*.jspx" });
341
+ mapping .setPathSpecs (new String [] {"*.jsp" , "*.jspx" });
460
342
context .getServletHandler ().addServletMapping (mapping );
461
343
}
462
344
0 commit comments