/** * Gets the attribute type whose OID is the given string. * * @param oid OID of attribute type to get. * * @return Attribute type whose OID matches given value or none if there is no standard attribute type matching the * given OID. */ public static StandardAttributeType fromOid(final String oid) { for (StandardAttributeType t : StandardAttributeType.values()) { if (t.getOid().equals(oid)) { return t; } } return null; }
@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(); }
/** * Gets the attribute type whose name is the given string. * * @param name Name of attribute to get, where the name is the all-caps RFC/standard name that would be returned by * {@link #getName()} for the desired attribute. * * @return Attribute type whose {@link #getName()} property matches the given value or null if there is no standard * attribute with the given name. */ public static AttributeType fromName(final String name) { for (AttributeType t : StandardAttributeType.values()) { if (t.getName().equals(name)) { return t; } } return null; } }
/** * Adds an attribute by type and value to the end of the attribute list. * * @param typeOid OID of attribute type. * @param value Attribute value. */ public void add(final String typeOid, final String value) { final StandardAttributeType type = StandardAttributeType.fromOid(typeOid); if (type != null) { add(new Attribute(type, value)); } else { add(new Attribute(new UnknownAttributeType(typeOid), value)); } }
if (!attrMap.containsKey(name)) { values = getAttributeValues(rdnSequence, StandardAttributeType.fromName(name)); attrMap.put(name, new AttributeContext(name, values));