Package org.wildfly.security.ssl
Class SSLContextBuilder
java.lang.Object
org.wildfly.security.ssl.SSLContextBuilder
A class which allows building and configuration of a single client- or server-side SSL context. The builder requires, at a
minimum, that a key manager be set; all other parameters have default values as follows:
- The security domain defaults to being empty (no client authentication possible)
- The principal decoder defaults to the default principal decoder
- The cipher suite selector defaults to
CipherSuiteSelector.openSslDefault() - The protocol suite selector defaults to
ProtocolSelector.DEFAULT_SELECTOR - The "require client authentication" flag defaults to
false - The provider supplier defaults to
Security::getProviders
- Author:
- David M. Lloyd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build a security factory for the new context.setAuthenticationOptional(boolean authenticationOptional) Where a SecurityDomain is associated with this Builder if the client presents a certificate an attempt will be made to obtain a SecurityIdentity by using the certificate for authentication, setting this flag totrueallows for a failed authentication to be silently ignored.setCipherSuiteSelector(CipherSuiteSelector cipherSuiteSelector) Set the cipher suite selector to use for this context.setClientMode(boolean clientMode) Set the client mode of the target SSL context.setKeyManager(X509ExtendedKeyManager keyManager) Set the key manager which should be used to hold identities for this context.setKeyManagerSecurityFactory(SecurityFactory<X509ExtendedKeyManager> keyManagerSecurityFactory) Set the factory for the key manager which should be used to hold identities for this context.setMechanismConfigurationSelector(MechanismConfigurationSelector mechanismConfigurationSelector) Set selector of mechanism configuration forServerAuthenticationContext, which will be used for SSL client authentication.setNeedClientAuth(boolean needClientAuth) Force the SSLContext created by this builder to need client authentication.setProtocolSelector(ProtocolSelector protocolSelector) Set the protocol selector to use for this context.setProviderName(String name) Set the provider name.setProviderSupplier(Supplier<Provider[]> providerSupplier) Set the provider supplier.setSecurityDomain(SecurityDomain securityDomain) Set the security domain to use to authenticate clients.setSessionCacheSize(int sessionCacheSize) Sets the size of the cache used for storing SSLSession objects.setSessionTimeout(int sessionTimeout) Sets the timeout limit for SSLSession objects.setTrustManager(X509TrustManager trustManager) Set the trust manager which should be used to hold identities for this context.setTrustManagerSecurityFactory(SecurityFactory<X509TrustManager> trustManagerSecurityFactory) Set the factory for the trust manager which should be used for the initial trust decisions during connection.setUseCipherSuitesOrder(boolean useCipherSuitesOrder) Sets whether the local cipher suites preference should be honored.setWantClientAuth(boolean wantClientAuth) Force the SSLContext created by this builder to want client authentication.setWrap(boolean wrap) Set if the configured SSL engine and sockets created using the SSL context should be wrapped to prevent modification to the configuration.
-
Constructor Details
-
SSLContextBuilder
public SSLContextBuilder()
-
-
Method Details
-
setSecurityDomain
Set the security domain to use to authenticate clients.- Parameters:
securityDomain- the security domain to use to authenticate clients, ornullto disable client certificate authentication
-
setCipherSuiteSelector
Set the cipher suite selector to use for this context.- Parameters:
cipherSuiteSelector- the cipher suite selector (notnull)
-
setProtocolSelector
Set the protocol selector to use for this context.- Parameters:
protocolSelector- the protocol selector to use for this context (notnull)
-
setUseCipherSuitesOrder
Sets whether the local cipher suites preference should be honored.- Parameters:
useCipherSuitesOrder- whether the local cipher suites preference should be honored.
-
setWantClientAuth
Force the SSLContext created by this builder to want client authentication. The SSLContext returned by this builder will be configured to want client authentication if this value is set to true OR of a SecurityDomain is associated.- Parameters:
wantClientAuth- should the SSLContext be forced to want client authentication.
-
setNeedClientAuth
Force the SSLContext created by this builder to need client authentication. The SSLContext returned by this builder will be configured to need client authentication if this value is set to true.- Parameters:
needClientAuth- should the SSLContext be forced to need client authentication.
-
setAuthenticationOptional
Where a SecurityDomain is associated with this Builder if the client presents a certificate an attempt will be made to obtain a SecurityIdentity by using the certificate for authentication, setting this flag totrueallows for a failed authentication to be silently ignored. This setting does not bypass any certificate checking performed by the underlying TrustManager so failure there will still cause the connection attempt to be aborted. The reason this setting would be used would be to enable a fallback to another authentication mechanism after the connection is established. Note: Where this is no security domain associated there is no authentication step so this value will be ignored.- Parameters:
authenticationOptional- should the authentication step be allowed to silently fail.
-
setSessionCacheSize
Sets the size of the cache used for storing SSLSession objects.- Parameters:
sessionCacheSize- the size of the cache used for storing SSLSession objects.- Returns:
- The
SSLContextBuilderto allow chaining of method calls.
-
setSessionTimeout
Sets the timeout limit for SSLSession objects.- Parameters:
sessionTimeout- the timeout limit for SSLSession objects.- Returns:
- The
SSLContextBuilderto allow chaining of method calls.
-
setKeyManagerSecurityFactory
public SSLContextBuilder setKeyManagerSecurityFactory(SecurityFactory<X509ExtendedKeyManager> keyManagerSecurityFactory) Set the factory for the key manager which should be used to hold identities for this context.- Parameters:
keyManagerSecurityFactory- the security factory which produces the key manager (notnull)
-
setKeyManager
Set the key manager which should be used to hold identities for this context.- Parameters:
keyManager- the security factory which produces the key manager (notnull)
-
setTrustManagerSecurityFactory
public SSLContextBuilder setTrustManagerSecurityFactory(SecurityFactory<X509TrustManager> trustManagerSecurityFactory) Set the factory for the trust manager which should be used for the initial trust decisions during connection.- Parameters:
trustManagerSecurityFactory- the factory for the trust manager which should be used for the initial trust decisions during connection (notnull).
-
setTrustManager
Set the trust manager which should be used to hold identities for this context.- Parameters:
trustManager- the trust manager which should be used to hold identities for this context (notnull).
-
setProviderSupplier
Set the provider supplier.- Parameters:
providerSupplier- the provider supplier (notnull)
-
setProviderName
Set the provider name.- Parameters:
name- the provider name (ifnulland provider is allowed)- Returns:
- this builder
-
setClientMode
Set the client mode of the target SSL context.- Parameters:
clientMode-trueto use client mode,falseotherwise- Returns:
- this builder
-
setWrap
Set if the configured SSL engine and sockets created using the SSL context should be wrapped to prevent modification to the configuration. Defaults totrue.- Parameters:
wrap- should the engine or socket created by the SSL context be wrapped to prevent modification to the configuration.- Returns:
- this builder
-
setMechanismConfigurationSelector
public SSLContextBuilder setMechanismConfigurationSelector(MechanismConfigurationSelector mechanismConfigurationSelector) Set selector of mechanism configuration forServerAuthenticationContext, which will be used for SSL client authentication.- Parameters:
mechanismConfigurationSelector- mechanism configuration selector to be used byServerAuthenticationContextin SSL authentication.- Returns:
- this builder
-
build
Build a security factory for the new context. The factory will cache the constructed instance.- Returns:
- the security factory
-