5353 * @author Philip Helger
5454 * @since 3.0.0
5555 */
56- @ SuppressWarnings ("javadoc" )
5756@ Immutable
5857public class AS4CryptoFactoryConfiguration extends AS4CryptoFactoryInMemoryKeyStore
5958{
@@ -71,7 +70,7 @@ public static AS4CryptoFactoryConfiguration getDefaultInstance () throws Phase4R
7170 {
7271 // Don't store this in a static variable, because it may fail if the
7372 // respective configuration properties are not present
74- return new AS4CryptoFactoryConfiguration (AS4Configuration .getConfig ());
73+ return new AS4CryptoFactoryConfiguration (AS4Configuration .getConfig (), CAS4Crypto . DEFAULT_CONFIG_PREFIX , false );
7574 }
7675
7776 /**
@@ -115,7 +114,8 @@ public AS4CryptoFactoryConfiguration (@Nonnull final IConfigWithFallback aConfig
115114
116115 @ Nonnull
117116 private static IKeyStoreAndKeyDescriptor _loadKeyStore (@ Nonnull final IConfigWithFallback aConfig ,
118- @ Nonnull @ Nonempty final String sConfigPrefix ) throws Phase4RuntimeException
117+ @ Nonnull @ Nonempty final String sConfigPrefix ,
118+ final boolean bLogError ) throws Phase4RuntimeException
119119 {
120120 // Load the keystore - may be null
121121 final IKeyStoreAndKeyDescriptor aDescriptor = AS4KeyStoreDescriptor .createFromConfig (aConfig , sConfigPrefix , null );
@@ -124,7 +124,8 @@ private static IKeyStoreAndKeyDescriptor _loadKeyStore (@Nonnull final IConfigWi
124124 final String sMsg = "Failed to load the key store configuration from properties starting with '" +
125125 sConfigPrefix +
126126 "'" ;
127- LOGGER .error (sMsg );
127+ if (bLogError )
128+ LOGGER .error (sMsg );
128129 throw new Phase4RuntimeException (sMsg );
129130 }
130131
@@ -135,7 +136,8 @@ private static IKeyStoreAndKeyDescriptor _loadKeyStore (@Nonnull final IConfigWi
135136 sConfigPrefix +
136137 "': " +
137138 aLKS .getErrorText (Locale .ROOT );
138- LOGGER .error (sMsg );
139+ if (bLogError )
140+ LOGGER .error (sMsg );
139141 throw new Phase4RuntimeException (sMsg );
140142 }
141143
@@ -146,7 +148,8 @@ private static IKeyStoreAndKeyDescriptor _loadKeyStore (@Nonnull final IConfigWi
146148 sConfigPrefix +
147149 "': " +
148150 aLK .getErrorText (Locale .ROOT );
149- LOGGER .error (sMsg );
151+ if (bLogError )
152+ LOGGER .error (sMsg );
150153 throw new Phase4RuntimeException (sMsg );
151154 }
152155
@@ -155,7 +158,8 @@ private static IKeyStoreAndKeyDescriptor _loadKeyStore (@Nonnull final IConfigWi
155158
156159 @ Nullable
157160 private static ITrustStoreDescriptor _loadTrustStore (@ Nonnull final IConfigWithFallback aConfig ,
158- @ Nonnull @ Nonempty final String sConfigPrefix )
161+ @ Nonnull @ Nonempty final String sConfigPrefix ,
162+ final boolean bLogError )
159163 {
160164 // Load the trust store - may be null
161165 final ITrustStoreDescriptor aDescriptor = AS4TrustStoreDescriptor .createFromConfig (aConfig , sConfigPrefix , null );
@@ -164,10 +168,11 @@ private static ITrustStoreDescriptor _loadTrustStore (@Nonnull final IConfigWith
164168 final LoadedKeyStore aLTS = aDescriptor .loadTrustStore ();
165169 if (aLTS .getKeyStore () == null )
166170 {
167- LOGGER .error ("Failed to load the trust store from the properties starting with '" +
168- sConfigPrefix +
169- "': " +
170- aLTS .getErrorText (Locale .ROOT ));
171+ if (bLogError )
172+ LOGGER .error ("Failed to load the trust store from the properties starting with '" +
173+ sConfigPrefix +
174+ "': " +
175+ aLTS .getErrorText (Locale .ROOT ));
171176 }
172177 }
173178 return aDescriptor ;
@@ -188,7 +193,29 @@ private static ITrustStoreDescriptor _loadTrustStore (@Nonnull final IConfigWith
188193 public AS4CryptoFactoryConfiguration (@ Nonnull final IConfigWithFallback aConfig ,
189194 @ Nonnull @ Nonempty final String sConfigPrefix ) throws Phase4RuntimeException
190195 {
191- this (_loadKeyStore (aConfig , sConfigPrefix ), _loadTrustStore (aConfig , sConfigPrefix ));
196+ // Log warning for backward compatibility reasons
197+ this (aConfig , sConfigPrefix , true );
198+ }
199+
200+ /**
201+ * This constructor takes the configuration object and uses the provided
202+ * configuration prefix. This is kind of the default constructor.
203+ *
204+ * @param aConfig
205+ * The configuration object to be used. May not be <code>null</code>.
206+ * @param sConfigPrefix
207+ * The configuration prefix to be used. May neither be
208+ * <code>null</code> nor empty and must end with a dot ('.').
209+ * @param bLogError
210+ * <code>true</code> if errors should be logged if loading fails.
211+ * @throws Phase4RuntimeException
212+ * If loading the key store configuration from configuration fails.
213+ */
214+ public AS4CryptoFactoryConfiguration (@ Nonnull final IConfigWithFallback aConfig ,
215+ @ Nonnull @ Nonempty final String sConfigPrefix ,
216+ final boolean bLogError ) throws Phase4RuntimeException
217+ {
218+ this (_loadKeyStore (aConfig , sConfigPrefix , bLogError ), _loadTrustStore (aConfig , sConfigPrefix , bLogError ));
192219 }
193220
194221 /**
0 commit comments