Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
da5c36c3
Commit
da5c36c3
authored
Jul 29, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
14c62436
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
67 deletions
+100
-67
MongoHealthIndicatorTests.java
...mework/boot/actuate/health/MongoHealthIndicatorTests.java
+1
-1
howto.adoc
spring-boot-docs/src/main/asciidoc/howto.adoc
+2
-0
SampleTomcatSslApplication.java
...c/main/java/sample/tomcat/SampleTomcatSslApplication.java
+1
-0
AbstractConfigurableEmbeddedServletContainer.java
...mbedded/AbstractConfigurableEmbeddedServletContainer.java
+5
-5
JettyEmbeddedServletContainerFactory.java
.../embedded/jetty/JettyEmbeddedServletContainerFactory.java
+46
-27
TomcatEmbeddedServletContainerFactory.java
...mbedded/tomcat/TomcatEmbeddedServletContainerFactory.java
+45
-34
No files found.
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java
View file @
da5c36c3
...
...
@@ -36,7 +36,7 @@ import static org.junit.Assert.assertTrue;
/**
* Tests for {@link MongoHealthIndicator}.
*
*
* @author Christian Dupuis
*/
public
class
MongoHealthIndicatorTests
{
...
...
spring-boot-docs/src/main/asciidoc/howto.adoc
View file @
da5c36c3
...
...
@@ -387,6 +387,8 @@ and then inject the actual (``local'') port as a `@Value`. For example:
}
----
[[howto-configure-ssl]]
=== Configure SSL
SSL can be configured declaratively by setting the various `server.ssl.*` properties,
...
...
spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/java/sample/tomcat/SampleTomcatSslApplication.java
View file @
da5c36c3
...
...
@@ -31,4 +31,5 @@ public class SampleTomcatSslApplication {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleTomcatSslApplication
.
class
,
args
);
}
}
spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableEmbeddedServletContainer.java
View file @
da5c36c3
...
...
@@ -244,11 +244,6 @@ public abstract class AbstractConfigurableEmbeddedServletContainer implements
return
this
.
registerDefaultServlet
;
}
@Override
public
void
setJspServletClassName
(
String
jspServletClassName
)
{
this
.
jspServletClassName
=
jspServletClassName
;
}
@Override
public
void
setSsl
(
Ssl
ssl
)
{
this
.
ssl
=
ssl
;
...
...
@@ -258,6 +253,11 @@ public abstract class AbstractConfigurableEmbeddedServletContainer implements
return
this
.
ssl
;
}
@Override
public
void
setJspServletClassName
(
String
jspServletClassName
)
{
this
.
jspServletClassName
=
jspServletClassName
;
}
/**
* @return the JSP servlet class name
*/
...
...
spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java
View file @
da5c36c3
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.context.embedded.jetty;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
...
...
@@ -69,7 +70,7 @@ import org.springframework.util.StringUtils;
* @see JettyEmbeddedServletContainer
*/
public
class
JettyEmbeddedServletContainerFactory
extends
AbstractEmbeddedServletContainerFactory
implements
ResourceLoaderAware
{
AbstractEmbeddedServletContainerFactory
implements
ResourceLoaderAware
{
private
List
<
Configuration
>
configurations
=
new
ArrayList
<
Configuration
>();
...
...
@@ -115,7 +116,7 @@ AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
if
(
getSsl
()
!=
null
)
{
SslContextFactory
sslContextFactory
=
new
SslContextFactory
();
configureSsl
ContextFactory
(
sslContextFactory
,
getSsl
());
configureSsl
(
sslContextFactory
,
getSsl
());
SslSocketConnector
sslConnector
=
new
SslSocketConnector
(
sslContextFactory
);
sslConnector
.
setPort
(
port
);
...
...
@@ -129,47 +130,65 @@ AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
return
getJettyEmbeddedServletContainer
(
server
);
}
protected
void
configureSslContextFactory
(
SslContextFactory
sslContextFactory
,
Ssl
ssl
)
{
sslContextFactory
.
setProtocol
(
ssl
.
getProtocol
());
/**
* Configure the SSL connection.
* @param factory the Jetty {@link SslContextFactory}.
* @param ssl the ssl details.
*/
protected
void
configureSsl
(
SslContextFactory
factory
,
Ssl
ssl
)
{
factory
.
setProtocol
(
ssl
.
getProtocol
());
configureSslClientAuth
(
factory
,
ssl
);
configureSslPasswords
(
factory
,
ssl
);
factory
.
setCertAlias
(
ssl
.
getKeyAlias
());
configureSslKeyStore
(
factory
,
ssl
);
if
(
ssl
.
getCiphers
()
!=
null
)
{
factory
.
setIncludeCipherSuites
(
ssl
.
getCiphers
());
}
configureSslTrustStore
(
factory
,
ssl
);
}
private
void
configureSslClientAuth
(
SslContextFactory
factory
,
Ssl
ssl
)
{
if
(
ssl
.
getClientAuth
()
==
ClientAuth
.
NEED
)
{
sslContextF
actory
.
setNeedClientAuth
(
true
);
sslContextF
actory
.
setWantClientAuth
(
true
);
f
actory
.
setNeedClientAuth
(
true
);
f
actory
.
setWantClientAuth
(
true
);
}
else
if
(
ssl
.
getClientAuth
()
==
ClientAuth
.
WANT
)
{
sslContextF
actory
.
setWantClientAuth
(
true
);
f
actory
.
setWantClientAuth
(
true
);
}
}
private
void
configureSslPasswords
(
SslContextFactory
factory
,
Ssl
ssl
)
{
if
(
ssl
.
getKeyStorePassword
()
!=
null
)
{
sslContextF
actory
.
setKeyStorePassword
(
ssl
.
getKeyStorePassword
());
f
actory
.
setKeyStorePassword
(
ssl
.
getKeyStorePassword
());
}
if
(
ssl
.
getKeyPassword
()
!=
null
)
{
sslContextF
actory
.
setKeyManagerPassword
(
ssl
.
getKeyPassword
());
f
actory
.
setKeyManagerPassword
(
ssl
.
getKeyPassword
());
}
sslContextFactory
.
setCertAlias
(
ssl
.
getKeyAlias
());
}
private
void
configureSslKeyStore
(
SslContextFactory
factory
,
Ssl
ssl
)
{
try
{
sslContextFactory
.
setKeyStoreResource
(
Resource
.
newResource
(
ResourceUtils
.
getURL
(
ssl
.
getKeyStore
())
));
URL
url
=
ResourceUtils
.
getURL
(
ssl
.
getKeyStore
());
factory
.
setKeyStoreResource
(
Resource
.
newResource
(
url
));
}
catch
(
IOException
e
)
{
catch
(
IOException
e
x
)
{
throw
new
EmbeddedServletContainerException
(
"Could not find key store '"
+
ssl
.
getKeyStore
()
+
"'"
,
e
);
}
if
(
ssl
.
getCiphers
()
!=
null
)
{
sslContextFactory
.
setIncludeCipherSuites
(
ssl
.
getCiphers
());
+
ssl
.
getKeyStore
()
+
"'"
,
ex
);
}
}
private
void
configureSslTrustStore
(
SslContextFactory
factory
,
Ssl
ssl
)
{
if
(
ssl
.
getTrustStorePassword
()
!=
null
)
{
sslContextF
actory
.
setTrustStorePassword
(
ssl
.
getTrustStorePassword
());
f
actory
.
setTrustStorePassword
(
ssl
.
getTrustStorePassword
());
}
if
(
ssl
.
getTrustStore
()
!=
null
)
{
try
{
sslContextFactory
.
setTrustStoreResource
(
Resource
.
newResource
(
ResourceUtils
.
getURL
(
ssl
.
getTrustStore
())
));
URL
url
=
ResourceUtils
.
getURL
(
ssl
.
getTrustStore
());
factory
.
setTrustStoreResource
(
Resource
.
newResource
(
url
));
}
catch
(
IOException
e
)
{
catch
(
IOException
e
x
)
{
throw
new
EmbeddedServletContainerException
(
"Could not find trust store '"
+
ssl
.
getTrustStore
()
+
"'"
,
e
);
"Could not find trust store '"
+
ssl
.
getTrustStore
()
+
"'"
,
e
x
);
}
}
}
...
...
@@ -202,7 +221,7 @@ AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
initializersToUse
);
context
.
setConfigurations
(
configurations
);
context
.
getSessionHandler
().
getSessionManager
()
.
setMaxInactiveInterval
(
getSessionTimeout
());
.
setMaxInactiveInterval
(
getSessionTimeout
());
postProcessWebAppContext
(
context
);
}
...
...
@@ -211,8 +230,8 @@ AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
if
(
root
!=
null
)
{
try
{
if
(!
root
.
isDirectory
())
{
handler
.
setBaseResource
(
Resource
.
newResource
(
"jar:"
+
root
.
toURI
()
+
"!"
)
);
Resource
resource
=
Resource
.
newResource
(
"jar:"
+
root
.
toURI
()
+
"!"
);
handler
.
setBaseResource
(
resource
);
}
else
{
handler
.
setBaseResource
(
Resource
.
newResource
(
root
));
...
...
spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java
View file @
da5c36c3
...
...
@@ -79,7 +79,7 @@ import org.springframework.util.StringUtils;
* @see TomcatEmbeddedServletContainer
*/
public
class
TomcatEmbeddedServletContainerFactory
extends
AbstractEmbeddedServletContainerFactory
implements
ResourceLoaderAware
{
AbstractEmbeddedServletContainerFactory
implements
ResourceLoaderAware
{
private
static
final
String
DEFAULT_PROTOCOL
=
"org.apache.coyote.http11.Http11NioProtocol"
;
...
...
@@ -226,7 +226,7 @@ AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
if
(
connector
.
getProtocolHandler
()
instanceof
AbstractProtocol
)
{
if
(
getAddress
()
!=
null
)
{
((
AbstractProtocol
)
connector
.
getProtocolHandler
())
.
setAddress
(
getAddress
());
.
setAddress
(
getAddress
());
}
}
if
(
getUriEncoding
()
!=
null
)
{
...
...
@@ -238,17 +238,14 @@ AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
connector
.
setProperty
(
"bindOnInit"
,
"false"
);
if
(
getSsl
()
!=
null
)
{
if
(
connector
.
getProtocolHandler
()
instanceof
AbstractHttp11JsseProtocol
)
{
AbstractHttp11JsseProtocol
jsseProtocol
=
(
AbstractHttp11JsseProtocol
)
connector
.
getProtocolHandler
();
configureJsseProtocol
(
jsseProtocol
,
getSsl
());
connector
.
setScheme
(
"https"
);
connector
.
setSecure
(
true
);
}
else
{
throw
new
IllegalStateException
(
"To use SSL, the connector's protocol handler must be an AbstractHttp11JsseProtocol subclass"
);
}
Assert
.
state
(
connector
.
getProtocolHandler
()
instanceof
AbstractHttp11JsseProtocol
,
"To use SSL, the connector's protocol handler must be an "
+
"AbstractHttp11JsseProtocol subclass"
);
configureSsl
((
AbstractHttp11JsseProtocol
)
connector
.
getProtocolHandler
(),
getSsl
());
connector
.
setScheme
(
"https"
);
connector
.
setSecure
(
true
);
}
for
(
TomcatConnectorCustomizer
customizer
:
this
.
tomcatConnectorCustomizers
)
{
...
...
@@ -256,42 +253,56 @@ AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware {
}
}
protected
void
configureJsseProtocol
(
AbstractHttp11JsseProtocol
jsseProtocol
,
Ssl
ssl
)
{
jsseProtocol
.
setSSLEnabled
(
true
);
jsseProtocol
.
setSslProtocol
(
ssl
.
getProtocol
());
/**
* Configure Tomcat's {@link AbstractHttp11JsseProtocol} for SSL.
* @param protocol the protocol
* @param ssl the ssl details
*/
protected
void
configureSsl
(
AbstractHttp11JsseProtocol
protocol
,
Ssl
ssl
)
{
protocol
.
setSSLEnabled
(
true
);
protocol
.
setSslProtocol
(
ssl
.
getProtocol
());
configureSslClientAuth
(
protocol
,
ssl
);
protocol
.
setKeystorePass
(
ssl
.
getKeyStorePassword
());
protocol
.
setKeyPass
(
ssl
.
getKeyPassword
());
protocol
.
setKeyAlias
(
ssl
.
getKeyAlias
());
configureSslKeyStore
(
protocol
,
ssl
);
String
ciphers
=
StringUtils
.
arrayToCommaDelimitedString
(
ssl
.
getCiphers
());
protocol
.
setCiphers
(
ciphers
);
configureSslTrustStore
(
protocol
,
ssl
);
}
private
void
configureSslClientAuth
(
AbstractHttp11JsseProtocol
protocol
,
Ssl
ssl
)
{
if
(
ssl
.
getClientAuth
()
==
ClientAuth
.
NEED
)
{
jsseP
rotocol
.
setClientAuth
(
Boolean
.
TRUE
.
toString
());
p
rotocol
.
setClientAuth
(
Boolean
.
TRUE
.
toString
());
}
else
if
(
ssl
.
getClientAuth
()
==
ClientAuth
.
WANT
)
{
jsseP
rotocol
.
setClientAuth
(
"want"
);
p
rotocol
.
setClientAuth
(
"want"
);
}
jsseProtocol
.
setKeystorePass
(
ssl
.
getKeyStorePassword
());
jsseProtocol
.
setKeyPass
(
ssl
.
getKeyPassword
());
jsseProtocol
.
setKeyAlias
(
ssl
.
getKeyAlias
());
}
private
void
configureSslKeyStore
(
AbstractHttp11JsseProtocol
protocol
,
Ssl
ssl
)
{
try
{
jsseProtocol
.
setKeystoreFile
(
ResourceUtils
.
getFile
(
ssl
.
getKeyStore
())
.
getAbsolutePath
());
File
file
=
ResourceUtils
.
getFile
(
ssl
.
getKeyStore
());
protocol
.
setKeystoreFile
(
file
.
getAbsolutePath
());
}
catch
(
FileNotFoundException
e
)
{
catch
(
FileNotFoundException
e
x
)
{
throw
new
EmbeddedServletContainerException
(
"Could not find key store "
+
ssl
.
getKeyStore
(),
e
);
+
ssl
.
getKeyStore
(),
e
x
);
}
}
jsseProtocol
.
setCiphers
(
StringUtils
.
arrayToCommaDelimitedString
(
ssl
.
getCiphers
()));
private
void
configureSslTrustStore
(
AbstractHttp11JsseProtocol
protocol
,
Ssl
ssl
)
{
if
(
ssl
.
getTrustStore
()
!=
null
)
{
try
{
jsseProtocol
.
setTruststoreFile
(
ResourceUtils
.
getFile
(
ssl
.
getTrustStore
())
.
getAbsolutePath
());
File
file
=
ResourceUtils
.
getFile
(
ssl
.
getTrustStore
());
protocol
.
setTruststoreFile
(
file
.
getAbsolutePath
());
}
catch
(
FileNotFoundException
e
)
{
catch
(
FileNotFoundException
e
x
)
{
throw
new
EmbeddedServletContainerException
(
"Could not find trust store "
+
ssl
.
getTrustStore
(),
e
);
+
ssl
.
getTrustStore
(),
e
x
);
}
}
jsseProtocol
.
setTruststorePass
(
ssl
.
getTrustStorePassword
());
protocol
.
setTruststorePass
(
ssl
.
getTrustStorePassword
());
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment