@Test public void getPropertyFromX500Principal() { X509Certificate cert = mock(X509Certificate.class); X500Principal principal = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); when(cert.getSubjectX500Principal()).thenReturn(principal); String value = X509CertificateUtil.getPropertyFromX500Principal(cert, "CN"); assertNotNull(value); assertEquals("Duke", value); }
public static String getPropertyFromX500Principal(X509Certificate cert, String propertyName) { String propertyValue = null; String principalName = cert.getSubjectX500Principal().getName(); log.debug("Found principalName = {}", principalName); Pattern pattern = createPattern(propertyName); Matcher matcher = pattern.matcher(principalName); if (matcher.find()) { propertyValue = matcher.group(1); log.debug("Found principal property {} = {}", propertyName, propertyValue); } else { logAndThrowError("Principal property " + propertyName + " not found in Certificate"); } return propertyValue; }
X509CertificateUtil { public static String getPropertyFromX500Principal(X509Certificate cert, String propertyName) { String propertyValue = null; String principalName = cert.getSubjectX500Principal().getName(); log.debug("Found principalName = {}", principalName); Pattern pattern = createPattern(propertyName); Matcher matcher = pattern.matcher(principalName); if (matcher.find()) { propertyValue = matcher.group(1); log.debug("Found principal property {} = {}", propertyName, propertyValue); } else { logAndThrowError("Principal property " + propertyName + " not found in Certificate"); } return propertyValue; } }
X509CertificateUtil { public static String getPropertyFromX500Principal(X509Certificate cert, String propertyName) { String propertyValue = null; String principalName = cert.getSubjectX500Principal().getName(); log.debug("Found principalName = {}", principalName); Pattern pattern = createPattern(propertyName); Matcher matcher = pattern.matcher(principalName); if (matcher.find()) { propertyValue = matcher.group(1); log.debug("Found principal property {} = {}", propertyName, propertyValue); } else { logAndThrowError("Principal property " + propertyName + " not found in Certificate"); } return propertyValue; } private  X509CertificateUtil(); }
X509CertificateUtil { public static String getPropertyFromX500Principal(X509Certificate cert, String propertyName) { String propertyValue = null; String principalName = cert.getSubjectX500Principal().getName(); log.debug("Found principalName = {}", principalName); Pattern pattern = createPattern(propertyName); Matcher matcher = pattern.matcher(principalName); if (matcher.find()) { propertyValue = matcher.group(1); log.debug("Found principal property {} = {}", propertyName, propertyValue); } else { logAndThrowError("Principal property " + propertyName + " not found in Certificate"); } return propertyValue; } private  X509CertificateUtil(); static String getPropertyFromX500Principal(X509Certificate cert, String propertyName); }
X509CertificateUtil { public static String getPropertyFromX500Principal(X509Certificate cert, String propertyName) { String propertyValue = null; String principalName = cert.getSubjectX500Principal().getName(); log.debug("Found principalName = {}", principalName); Pattern pattern = createPattern(propertyName); Matcher matcher = pattern.matcher(principalName); if (matcher.find()) { propertyValue = matcher.group(1); log.debug("Found principal property {} = {}", propertyName, propertyValue); } else { logAndThrowError("Principal property " + propertyName + " not found in Certificate"); } return propertyValue; } private  X509CertificateUtil(); static String getPropertyFromX500Principal(X509Certificate cert, String propertyName);  }