2121import java .util .ArrayList ;
2222import java .util .Collections ;
2323import java .util .Enumeration ;
24+ import java .util .HashSet ;
2425import java .util .List ;
26+ import java .util .Set ;
2527
2628
2729/**
@@ -31,9 +33,9 @@ public class SignedAndEncryptedMessageHandler extends BaseMessageHandler {
3133
3234 private static final String KEY_FILE_TYPE = "PKCS12" ;
3335
34- public static List <Identity > identities = new ArrayList <Identity >();
36+ private List <Identity > identities = new ArrayList <Identity >();
3537
36- private static String currentMerchantId = null ;
38+ private static Set < String > currentMerchantId = new HashSet < String >() ;
3739
3840 private static final String SERVER_ALIAS = "CyberSource_SJC_US" ;
3941
@@ -52,7 +54,7 @@ private SignedAndEncryptedMessageHandler(MerchantConfig merchantConfig, Logger l
5254 // load keystore from disk p12 file (not keystore)
5355 loadMerchantP12File (merchantConfig , logger );
5456 for (int pos =0 ;pos <identities .size ();pos ++) {
55- localKeyStoreHandler .addIdentityToKeyStore (identities .get (pos ));
57+ localKeyStoreHandler .addIdentityToKeyStore (identities .get (pos ), logger );
5658 }
5759 }
5860
@@ -69,10 +71,10 @@ static SignedAndEncryptedMessageHandler getInstance(MerchantConfig merchantConfi
6971 * @param logger - logger instance
7072 * @throws SignException - Signature exception
7173 */
72- private static void loadMerchantP12File (MerchantConfig merchantConfig , Logger logger ) throws SignException {
74+ private void loadMerchantP12File (MerchantConfig merchantConfig , Logger logger ) throws SignException {
7375 // Load the KeyStore and get the signing key and certificate do this once only
7476 // This change is made based on the assumptions that at point of time , a merchant will have only one P12 Key
75- if ( ! merchantConfig .getMerchantID (). equals ( currentMerchantId )){
77+ if (! currentMerchantId . contains ( merchantConfig .getMerchantID ())){
7678 readAndStoreCertificateAndPrivateKey ( merchantConfig , logger );
7779 }
7880 }
@@ -84,7 +86,7 @@ private static void loadMerchantP12File(MerchantConfig merchantConfig, Logger lo
8486 * @throws SignException
8587 */
8688
87- private static void readAndStoreCertificateAndPrivateKey (
89+ private void readAndStoreCertificateAndPrivateKey (
8890 MerchantConfig merchantConfig , Logger logger ) throws SignException {
8991 KeyStore merchantKeyStore ;
9092 try {
@@ -142,7 +144,7 @@ private static void readAndStoreCertificateAndPrivateKey(
142144 logger .log (Logger .LT_EXCEPTION , "No valid entries found in the KeyStore, check alias, '" + merchantConfig .getKeyAlias () + "'" );
143145 throw new SignException ("No valid entries found in the KeyStore, check alias, '" + merchantConfig .getKeyAlias () + "'" );
144146 }
145- currentMerchantId = merchantConfig .getMerchantID ();
147+ currentMerchantId . add ( merchantConfig .getMerchantID () );
146148 } catch (KeyStoreException e ) {
147149 logger .log (Logger .LT_EXCEPTION , "Exception while obtaining private key from KeyStore with alias, '" + merchantConfig .getKeyAlias () + "'" );
148150 throw new SignException (e );
0 commit comments