@Test public void testsetUpServer() throws InstantiationException, IllegalAccessException, SignException{ String keyAlias = "CN=CyberSource_SJC_US,SERIALNUMBER=400000009910179089277"; X509Certificate x509Cert = Mockito.mock(X509Certificate.class); Principal principal = Mockito.mock(Principal.class); Logger logger = Mockito.mock(Logger.class); Mockito.when(x509Cert.getSubjectDN()).thenReturn(principal); Mockito.when(principal.getName()).thenReturn(keyAlias); Identity identity = new Identity(config,x509Cert,logger); assertEquals(identity.getName(), "CyberSource_SJC_US"); assertEquals(identity.getSerialNumber(), "400000009910179089277"); assertNull(identity.getPrivateKey()); }
private void setUpServer() throws SignException { if (serialNumber == null && x509Cert != null) { String subjectDN = x509Cert.getSubjectDN().getName(); if (subjectDN != null) { String[] subjectDNrray = subjectDN.split("SERIALNUMBER="); if (subjectDNrray.length == 1 && subjectDNrray[0].contains("CyberSourceCertAuth")){ name = keyAlias = "CyberSourceCertAuth"; } else if (subjectDNrray.length == 2 && subjectDNrray[0].contains(SERVER_ALIAS)) { name = SERVER_ALIAS; serialNumber = subjectDNrray[1]; keyAlias = "serialNumber=" + serialNumber + ",CN=" + name; }else{ throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } else { throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } }
Identity { private void setUpServer() throws SignException { if (serialNumber == null && x509Cert != null) { String subjectDN = x509Cert.getSubjectDN().getName(); if (subjectDN != null) { String[] subjectDNrray = subjectDN.split("SERIALNUMBER="); if (subjectDNrray.length == 1 && subjectDNrray[0].contains("CyberSourceCertAuth")){ name = keyAlias = "CyberSourceCertAuth"; } else if (subjectDNrray.length == 2 && subjectDNrray[0].contains(SERVER_ALIAS)) { name = SERVER_ALIAS; serialNumber = subjectDNrray[1]; keyAlias = "serialNumber=" + serialNumber + ",CN=" + name; }else{ throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } else { throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } } }
Identity { private void setUpServer() throws SignException { if (serialNumber == null && x509Cert != null) { String subjectDN = x509Cert.getSubjectDN().getName(); if (subjectDN != null) { String[] subjectDNrray = subjectDN.split("SERIALNUMBER="); if (subjectDNrray.length == 1 && subjectDNrray[0].contains("CyberSourceCertAuth")){ name = keyAlias = "CyberSourceCertAuth"; } else if (subjectDNrray.length == 2 && subjectDNrray[0].contains(SERVER_ALIAS)) { name = SERVER_ALIAS; serialNumber = subjectDNrray[1]; keyAlias = "serialNumber=" + serialNumber + ",CN=" + name; }else{ throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } else { throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } } Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate,Logger logger);  Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, PrivateKey privateKey, Logger logger); }
Identity { private void setUpServer() throws SignException { if (serialNumber == null && x509Cert != null) { String subjectDN = x509Cert.getSubjectDN().getName(); if (subjectDN != null) { String[] subjectDNrray = subjectDN.split("SERIALNUMBER="); if (subjectDNrray.length == 1 && subjectDNrray[0].contains("CyberSourceCertAuth")){ name = keyAlias = "CyberSourceCertAuth"; } else if (subjectDNrray.length == 2 && subjectDNrray[0].contains(SERVER_ALIAS)) { name = SERVER_ALIAS; serialNumber = subjectDNrray[1]; keyAlias = "serialNumber=" + serialNumber + ",CN=" + name; }else{ throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } else { throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } } Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate,Logger logger);  Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, PrivateKey privateKey, Logger logger); boolean isValid(File keyFile, Logger logger); String getName(); void setName(String name); String getKeyAlias(); void setKeyAlias(String keyAlias); String getSerialNumber(); char[] getPswd(); void setSerialNumber(String serialNumber); X509Certificate getX509Cert(); void setX509Cert(X509Certificate x509Cert); PrivateKey getPrivateKey(); void setPrivateKey(PrivateKey privateKey); @Override String toString(); }
Identity { private void setUpServer() throws SignException { if (serialNumber == null && x509Cert != null) { String subjectDN = x509Cert.getSubjectDN().getName(); if (subjectDN != null) { String[] subjectDNrray = subjectDN.split("SERIALNUMBER="); if (subjectDNrray.length == 1 && subjectDNrray[0].contains("CyberSourceCertAuth")){ name = keyAlias = "CyberSourceCertAuth"; } else if (subjectDNrray.length == 2 && subjectDNrray[0].contains(SERVER_ALIAS)) { name = SERVER_ALIAS; serialNumber = subjectDNrray[1]; keyAlias = "serialNumber=" + serialNumber + ",CN=" + name; }else{ throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } else { throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'"); } } } Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate,Logger logger);  Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, PrivateKey privateKey, Logger logger); boolean isValid(File keyFile, Logger logger); String getName(); void setName(String name); String getKeyAlias(); void setKeyAlias(String keyAlias); String getSerialNumber(); char[] getPswd(); void setSerialNumber(String serialNumber); X509Certificate getX509Cert(); void setX509Cert(X509Certificate x509Cert); PrivateKey getPrivateKey(); void setPrivateKey(PrivateKey privateKey); @Override String toString();  }