/** * Gets the common name attribute (CN) of the certificate subject distinguished name. * * @param cert Certificate to examine. * * @return Subject CN or null if no CN attribute is defined in the subject DN. * * @throws EncodingException on cert field extraction. */ public static String subjectCN(final X509Certificate cert) throws EncodingException { return new NameReader(cert).readSubject().getValue(StandardAttributeType.CommonName); }
@Override protected String resolvePrincipalInternal(final X509Certificate certificate) { LOGGER.debug("Resolving principal for [{}]", certificate); val sb = new StringBuffer(); val m = ATTR_PATTERN.matcher(this.descriptor); val attrMap = new HashMap<String, AttributeContext>(); val rdnSequence = new NameReader(certificate).readSubject(); while (m.find()) { val name = m.group(1); if (!attrMap.containsKey(name)) { val values = getAttributeValues(rdnSequence, StandardAttributeType.fromName(name)); attrMap.put(name, new AttributeContext(values)); } val context = attrMap.get(name); m.appendReplacement(sb, context.nextValue()); } m.appendTail(sb); return sb.toString(); }
final Matcher m = ATTR_PATTERN.matcher(this.descriptor); final Map<String, AttributeContext> attrMap = new HashMap<>(); final RDNSequence rdnSequence = new NameReader(certificate).readSubject(); String name; String[] values;