Exemplo n.º 1
0
 /**
  * Converts the given X.500 principal to a list of type/value attributes.
  *
  * @param principal Principal to convert.
  * @return List of type/value attributes.
  */
 public static Attributes readX500Principal(final X500Principal principal) {
   final X500Name name = X500Name.getInstance(principal.getEncoded());
   final Attributes attributes = new Attributes();
   for (RDN rdn : name.getRDNs()) {
     for (AttributeTypeAndValue tv : rdn.getTypesAndValues()) {
       attributes.add(tv.getType().getId(), tv.getValue().toString());
     }
   }
   return attributes;
 }
Exemplo n.º 2
0
 /**
  * Converts the given X.500 principal to a list of relative distinguished names that contains the
  * attributes comprising the DN.
  *
  * @param principal Principal to convert.
  * @return X500 principal as an RDN sequence.
  */
 public static RDNSequence readX500Principal(final X500Principal principal) {
   final X500Name name = X500Name.getInstance(principal.getEncoded());
   final RDNSequence sequence = new RDNSequence();
   for (org.bouncycastle.asn1.x500.RDN rdn : name.getRDNs()) {
     final Attributes attributes = new Attributes();
     for (AttributeTypeAndValue tv : rdn.getTypesAndValues()) {
       attributes.add(tv.getType().getId(), tv.getValue().toString());
     }
     sequence.add(new RDN(attributes));
   }
   return sequence;
 }
  /**
   * Returns the (first) value of the (first) RDN of type rdnOid
   *
   * @param dn The X500Name
   * @param rdnOid OID of wanted RDN
   * @return Value of requested RDN
   */
  public static String getRdn(X500Name dn, ASN1ObjectIdentifier rdnOid) {

    if (dn == null || rdnOid == null) {
      return "";
    }

    RDN[] rdns = dn.getRDNs(rdnOid);
    String value = "";

    if (rdns.length > 0) {
      RDN rdn = rdns[0];
      value = rdn.getFirst().getValue().toString();
    }

    return value;
  }