Code example for X509Certificate

Methods: getSubjectX500Principal

0
public abstract class CnConstraintCertValidator implements CertValidator { 
 
  private static final Pattern CN_PATTERN = Pattern.compile("CN=([^,]+)");
 
  public boolean matches(X509Certificate cert, String authority) {
    String cn = getCnFromDn(cert.getSubjectX500Principal().getName());
 
    if (cn == null) {
      return false; 
    } 
 
    return cn.equals(getRequiredCn(authority));
  } 
 
  /* visible for testing */ 
  String getCnFromDn(String dn) {
    Matcher m = CN_PATTERN.matcher(dn);
 
    if (m.find()) {
      return m.group(1);
    } else {