1818import java .security .cert .X509Certificate ;
1919import java .util .Collections ;
2020import java .util .Enumeration ;
21+ import java .util .Map ;
2122import java .util .concurrent .ConcurrentHashMap ;
2223
2324/**
@@ -28,7 +29,6 @@ public class SecurityUtil {
2829
2930 private static final String KEY_FILE_TYPE = "PKCS12" ;
3031
31- private static final String SERVER_ALIAS = "CyberSource_SJC_US" ;
3232 private static final String FAILED_TO_LOAD_KEY_STORE = "Exception while loading KeyStore" ;
3333 private static final String FAILED_TO_OBTAIN_PRIVATE_KEY = "Exception while obtaining private key from KeyStore with alias" ;
3434
@@ -202,7 +202,7 @@ public static Document handleMessageCreation(Document signedDoc, String merchant
202202 WSSecEncrypt encrBuilder = new WSSecEncrypt ();
203203 //Set the user name to get the encryption certificate.
204204 //The public key of this certificate is used, thus no password necessary. The user name is a keystore alias usually.
205- String serverAlias = getServerAlias ();
205+ String serverAlias = getServerAlias (identities );
206206 encrBuilder .setUserInfo (identities .get (serverAlias ).getKeyAlias ());
207207 /*This is to reference a public key or certificate when signing or encrypting a SOAP message.
208208 *The following valid values for these configuration items are:
@@ -382,7 +382,7 @@ private static void loadJavaKeystore(MerchantConfig merchantConfig, Logger logge
382382 identities .put (identity .getName (), identity );
383383 }
384384 }
385- java .security .cert .Certificate serverCert = keystore .getCertificate (getServerAlias ());
385+ java .security .cert .Certificate serverCert = keystore .getCertificate (getServerAlias (identities ));
386386 if (serverCert == null ) {
387387 throw new SignException ("Missing Server Certificate " );
388388 }
@@ -420,15 +420,15 @@ private static void loadJavaKeystore(MerchantConfig merchantConfig, Logger logge
420420
421421 }
422422
423- protected static String getServerAlias () {
424- String serverAlias = SERVER_ALIAS ;
425- if (!identities .containsKey (serverAlias )) {
426- if (identities .containsKey (serverAlias .toLowerCase ())) {
423+ protected static String getServerAlias (Map < String , Identity > identitiesMapper ) {
424+ String serverAlias = Utility . SERVER_ALIAS ;
425+ if (!identitiesMapper .containsKey (serverAlias )) {
426+ if (identitiesMapper .containsKey (serverAlias .toLowerCase ())) {
427427 serverAlias = serverAlias .toLowerCase ();
428- } else if (identities .containsKey (serverAlias .toUpperCase ())) {
428+ } else if (identitiesMapper .containsKey (serverAlias .toUpperCase ())) {
429429 serverAlias = serverAlias .toUpperCase ();
430430 } else {
431- for (String identityKey :identities .keySet ()) {
431+ for (String identityKey :identitiesMapper .keySet ()) {
432432 if (identityKey .equalsIgnoreCase (serverAlias )) {
433433 serverAlias = identityKey ;
434434 break ;
0 commit comments