org.jsslutils.sslcontext
Class DefaultSSLContextFactory

java.lang.Object
  extended by org.jsslutils.sslcontext.DefaultSSLContextFactory
All Implemented Interfaces:
SSLContextFactory
Direct Known Subclasses:
X509SSLContextFactory

public class DefaultSSLContextFactory
extends java.lang.Object
implements SSLContextFactory

This class is a factory that provides methods for creating an SSLContext configured with the settings set in this factory. It creates and initialises the SSLContext with init(getKeyManagers(), getTrustManagers(), getSecureRandom()), which all default to null. These three methods can be overridden.

Author:
Bruno Harbulot

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jsslutils.sslcontext.SSLContextFactory
SSLContextFactory.SSLContextFactoryException
 
Field Summary
static java.lang.String CONTEXT_PROTOCOL_NAME_PROP
           
static java.lang.String CONTEXT_PROVIDER_NAME_PROP
           
static java.lang.String SECURERANDOM_ALGORITHM_PROP
           
static java.lang.String SECURERANDOM_PROVIDER_NAME_PROP
           
 
Constructor Summary
DefaultSSLContextFactory()
           
 
Method Summary
 javax.net.ssl.SSLContext buildSSLContext()
          Creates a new SSLContext with the context protocol set with setContextProtocol(String).
 javax.net.ssl.SSLContext buildSSLContext(java.lang.String contextProtocol)
          Creates a new SSLContext initialised with getKeyManagers(), getTrustManagers() and getSecureRandom().
protected  DefaultSSLContextFactory clone()
          SSLContextFactories are likely to contain sensitive information; cloning is therefore not allowed.
 void configure(java.util.Properties properties)
          Configures some this factory based on values in the properties.
 java.lang.String getContextProtocol()
          Returns the protocol to be used for creating a new SSLContext.
 java.security.Provider getContextProvider()
          Returns the Provider that is used for creating the SSLContext.
 java.lang.String getDefaultSecureRandomAlgorithm()
          Returns the default SecureRandom algorithm.
 javax.net.ssl.KeyManager[] getKeyManagers()
          Returns the KeyManagers to be used for initialising the SSLContext.
 java.security.SecureRandom getSecureRandom()
          Returns the SecureRandom to be used for initialising the SSLContext.
 java.security.Provider getSecureRandomProvider()
          Returns the default SecureRandom Provider.
 javax.net.ssl.TrustManager[] getTrustManagers()
          Returns the TrustManagers to be used for initialising the SSLContext.
 void setSecureRandom(java.security.SecureRandom secureRandom)
          Sets the SecureRandom to be used for initialising the SSLContext.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_PROVIDER_NAME_PROP

public static final java.lang.String CONTEXT_PROVIDER_NAME_PROP
See Also:
Constant Field Values

CONTEXT_PROTOCOL_NAME_PROP

public static final java.lang.String CONTEXT_PROTOCOL_NAME_PROP
See Also:
Constant Field Values

SECURERANDOM_PROVIDER_NAME_PROP

public static final java.lang.String SECURERANDOM_PROVIDER_NAME_PROP
See Also:
Constant Field Values

SECURERANDOM_ALGORITHM_PROP

public static final java.lang.String SECURERANDOM_ALGORITHM_PROP
See Also:
Constant Field Values
Constructor Detail

DefaultSSLContextFactory

public DefaultSSLContextFactory()
Method Detail

configure

public void configure(java.util.Properties properties)
               throws SSLContextFactory.SSLContextFactoryException
Configures some this factory based on values in the properties.
Property name Description
org.jsslutils.prop.contextProvider Name of the security Provider to use to instantiate the SSLContext.
org.jsslutils.prop.contextProtocol Name of the protocol for the SSLContext, defaults to TLS.
org.jsslutils.prop.secureRandomProvider Name of the security Provider to use to instantiate the SecureRandom.
org.jsslutils.prop.secureRandomAlgorithm Name of the SecureRandom algorithm, defaults to null.

Specified by:
configure in interface SSLContextFactory
Parameters:
properties - properties to use for the configuration.
Throws:
SSLContextFactory.SSLContextFactoryException

getContextProvider

public java.security.Provider getContextProvider()
Returns the Provider that is used for creating the SSLContext.

Returns:
Provider that is used for creating the SSLContext.

getContextProtocol

public java.lang.String getContextProtocol()
Returns the protocol to be used for creating a new SSLContext.

Returns:
Protocol to be used to create the SSLContext.

getSecureRandomProvider

public java.security.Provider getSecureRandomProvider()
Returns the default SecureRandom Provider.

Returns:
The default SecureRandom Provider.

getDefaultSecureRandomAlgorithm

public java.lang.String getDefaultSecureRandomAlgorithm()
Returns the default SecureRandom algorithm.

Returns:
The default SecureRandom algorithm.

buildSSLContext

public final javax.net.ssl.SSLContext buildSSLContext()
                                               throws SSLContextFactory.SSLContextFactoryException
Creates a new SSLContext with the context protocol set with setContextProtocol(String). The default value is "SSLv3".

Specified by:
buildSSLContext in interface SSLContextFactory
Returns:
SSLContext initialised with getKeyManagers(), getTrustManagers() and getSecureRandom().
Throws:
SSLContextFactoryException
SSLContextFactory.SSLContextFactoryException

buildSSLContext

public javax.net.ssl.SSLContext buildSSLContext(java.lang.String contextProtocol)
                                         throws SSLContextFactory.SSLContextFactoryException
Creates a new SSLContext initialised with getKeyManagers(), getTrustManagers() and getSecureRandom(). The provider is that set up with setContextProvider() or setContextProviderName().

Parameters:
contextProtocol - SSLContext protocol.
Returns:
SSLContext initialised with getKeyManagers(), getTrustManagers() and getSecureRandom().
Throws:
SSLContextFactoryException
SSLContextFactory.SSLContextFactoryException

getKeyManagers

public javax.net.ssl.KeyManager[] getKeyManagers()
                                          throws SSLContextFactory.SSLContextFactoryException
Returns the KeyManagers to be used for initialising the SSLContext. Defaults to null.

Returns:
The KeyManagers to be used for initialising the SSLContext.
Throws:
SSLContextFactoryException
SSLContextFactory.SSLContextFactoryException

getTrustManagers

public javax.net.ssl.TrustManager[] getTrustManagers()
                                              throws SSLContextFactory.SSLContextFactoryException
Returns the TrustManagers to be used for initialising the SSLContext. Defaults to null.

Returns:
The TrustManagers to be used for initialising the SSLContext.
Throws:
SSLContextFactoryException
SSLContextFactory.SSLContextFactoryException

setSecureRandom

public void setSecureRandom(java.security.SecureRandom secureRandom)
Sets the SecureRandom to be used for initialising the SSLContext.

Parameters:
secureRandom - the secureRandom to set

getSecureRandom

public java.security.SecureRandom getSecureRandom()
                                           throws SSLContextFactory.SSLContextFactoryException
Returns the SecureRandom to be used for initialising the SSLContext. Defaults to SecureRandom.getInstance(...) if defaultSecureRandomAlgorithm has been set (with optional provider) or null otherwise. It will only try to create a new SecureRandom from the default value if the current value is null. Reset it to null if you want to re-create a new SecureRandom from the default values.

Returns:
The SecureRandom to be used for initialising the SSLContext.
Throws:
SSLContextFactoryException
SSLContextFactory.SSLContextFactoryException

clone

protected final DefaultSSLContextFactory clone()
                                        throws java.lang.CloneNotSupportedException
SSLContextFactories are likely to contain sensitive information; cloning is therefore not allowed.

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException


Copyright © 2011. All Rights Reserved.