Commit 32a57837 authored by Guus der Kinderen's avatar Guus der Kinderen

OF-1049: Prevent partially initialized objects

By reversing the order in which objects are added to the internal state,
a failure during store construction won't put the manager in a half-initialized
state.
parent 4ad55187
...@@ -43,32 +43,34 @@ public class CertificateStoreManager extends BasicModule ...@@ -43,32 +43,34 @@ public class CertificateStoreManager extends BasicModule
{ {
try try
{ {
Log.debug( "(identity store for connection type '{}') Initializing store...", type );
final CertificateStoreConfiguration identityStoreConfiguration = getIdentityStoreConfiguration( type ); final CertificateStoreConfiguration identityStoreConfiguration = getIdentityStoreConfiguration( type );
typeToIdentityStore.put( type, identityStoreConfiguration );
if ( !identityStores.containsKey( identityStoreConfiguration ) ) if ( !identityStores.containsKey( identityStoreConfiguration ) )
{ {
final IdentityStore store = new IdentityStore( identityStoreConfiguration, false ); final IdentityStore store = new IdentityStore( identityStoreConfiguration, false );
identityStores.put( identityStoreConfiguration, store ); identityStores.put( identityStoreConfiguration, store );
} }
typeToIdentityStore.put( type, identityStoreConfiguration );
} }
catch ( CertificateStoreConfigException | IOException e ) catch ( CertificateStoreConfigException | IOException e )
{ {
Log.warn( "Unable to instantiate identity store for type '" + type + "'", e ); Log.warn( "(identity store for connection type '{}') Unable to instantiate store ", type, e );
} }
try try
{ {
Log.debug( "(trust store for connection type '{}') Initializing store...", type );
final CertificateStoreConfiguration trustStoreConfiguration = getTrustStoreConfiguration( type ); final CertificateStoreConfiguration trustStoreConfiguration = getTrustStoreConfiguration( type );
typeToTrustStore.put( type, trustStoreConfiguration );
if ( !trustStores.containsKey( trustStoreConfiguration ) ) if ( !trustStores.containsKey( trustStoreConfiguration ) )
{ {
final TrustStore store = new TrustStore( trustStoreConfiguration, false ); final TrustStore store = new TrustStore( trustStoreConfiguration, false );
trustStores.put( trustStoreConfiguration, store ); trustStores.put( trustStoreConfiguration, store );
} }
typeToTrustStore.put( type, trustStoreConfiguration );
} }
catch ( CertificateStoreConfigException | IOException e ) catch ( CertificateStoreConfigException | IOException e )
{ {
Log.warn( "Unable to instantiate trust store for type '" + type + "'", e ); Log.warn( "(trust store for connection type '{}') Unable to instantiate store ", type, e );
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment