Class MemberX500Name

  • All Implemented Interfaces:
    java.lang.Comparable

    
    public final class MemberX500Name
     implements Comparable<T>
                        

    X.500 distinguished name data type customised to how Corda membership uses names.

    This restricts the attributes to those Corda supports, and requires that organization, locality, and country attributes are specified. See also RFC 4519 for the underlying attribute type definitions.

    The class also guaranties the reliable equality comparison regardless of which order the attributes are specified when parsing from the string or X500principal, and outputs the attributes to the string in a predictable order.

    There may be additional network specific requirements which need to be taken into account when creating a name by the user. For example, the network operator may require a particular format for names so that they can issue suitable certificates. Finding and giving a suitable name will be the user's responsibility.

    The order of attributes for building the names is the following: CN, OU, O, L, ST, C.

    Example usages:

    • 
      String commonName = "Alice";
      String organizationUnit = "Accounting";
      String organization = "R3";
      String locality = "New York";
      String state = "New York";
      String country = "US";
      
      
      MemberX500Name exampleNameFirst = new MemberX500Name(organization, locality, country);
      MemberX500Name exampleNameSecond = new MemberX500Name(commonName, organizationUnit, organization, locality, state, country);
      MemberX500Name exampleNameThird = new MemberX500Name(commonName, organization, locality, country);
      
      String commonNameForExampleNameThird = exampleNameThird.getCommonName();
      String organizationUnitForExampleNameThird = exampleNameThird.getOrganisationUnit();
      String organizationForExampleNameThird = exampleNameThird.getOrganisation();
      String localityForExampleNameThird = exampleNameThird.getLocality();
      String stateForExampleNameThird = exampleNameThird.getState();
      String countryForExampleNameThird = exampleNameThird.getCountry();
      X500Principal principalForExampleNameThird = exampleNameThird.getX500Principal();
      
      String name = "O=organization,L=London,C=GB";
      X500Principal principalForNewName = new X500Principal(name);
      MemberX500Name nameByPrincipal = MemberX500Name.build(principalForNewName);
      MemberX500Name nameByParse = MemberX500Name.parse(name);
      
      Map<String, String > map = MemberX500Name.toAttributesMap("CN=alice, OU=Accounting, O=R3, L=Seattle, ST=Washington, C=US");
      
    • Kotlin:
      
      val commonName = "Alice"
      val organizationUnit = "Accounting"
      val organization = "R3"
      val locality = "New York"
      val state = "New York"
      val country = "US"
      
      val exampleNameFirst = MemberX500Name(organization, locality, country)
      val exampleNameSecond = MemberX500Name(commonName, organizationUnit, organization, locality, state, country)
      val exampleNameThird = MemberX500Name(commonName, organization, locality, country)
      
      val commonNameForExampleNameThird = exampleNameThird.commonName
      val organizationUnitForExampleNameThird = exampleNameThird.organizationUnit
      val organizationForExampleNameThird = exampleNameThird.organization
      val localityForExampleNameThird = exampleNameThird.locality
      val stateForExampleNameThird = exampleNameThird.state
      val countryForExampleNameThird = exampleNameThird.country
      val principalForExampleNameThird = exampleNameThird.x500Principal
      val name = "O=organization,L=London,C=GB"
      val principalForNewName = X500Principal(name)
      val nameByPrincipal = MemberX500Name.build(principalForNewName)
      val nameByParse = MemberX500Name.parse(name)
      
      val map = MemberX500Name.toAttributesMap("CN=alice, OU=Accounting, O=R3, L=Seattle, ST=Washington, C=US")
      
    • Constructor Detail

      • MemberX500Name

        MemberX500Name(String commonName, String organizationUnit, String organization, String locality, String state, String country)
        Parameters:
        commonName - Summary name by which the entity is usually known.
        organizationUnit - Name of a unit within the [organization], typically the department, or business unit.
        organization - Name of the organization, typically the company name.
        locality - Locality of the organization, typically the nearest major city.
        state - The full name of the state or province the organization is based in.
        country - Country the organization is in, as an ISO 3166-1 2-letter country code.
      • MemberX500Name

        MemberX500Name(String commonName, String organization, String locality, String country)
        Parameters:
        commonName - Summary name by which the entity is usually known.
        organization - Name of the organization, typically the company name.
        locality - Locality of the organization, typically the nearest major city.
        country - Country the organization is in, as an ISO 3166-1 2-letter country code.
      • MemberX500Name

        MemberX500Name(String organization, String locality, String country)
        Parameters:
        organization - Name of the organization, typically the company name.
        locality - Locality of the organization, typically the nearest major city.
        country - Country the organization is in, as an ISO 3166-1 2-letter country code.
    • Method Detail

      • getCommonName

        @Nullable() String getCommonName()

        Optional field, summary name by which the entity is usually known. Corresponds to the "CN" attribute type. Null, if not provided.

      • getOrganizationUnit

        @Nullable() String getOrganizationUnit()

        Optional field, name of a unit within the [organization], typically the department, or business unit. Corresponds to the "OU" attribute type. Null, if not provided.

      • getOrganization

        @NotNull() String getOrganization()

        Mandatory field, name of the organization, typically the company name. Corresponds to the "O" attribute type. Must be provided.

      • getLocality

        @NotNull() String getLocality()

        Mandatory field, locality of the organization, typically the nearest major city. Corresponds to the "L" attribute type. Must be provided.

      • getState

        @Nullable() String getState()

        Optional field, the full name of the state or province the organization is based in. Corresponds to the "ST" attribute type. Null, if not provided.

      • getCountry

        @NotNull() String getCountry()

        Mandatory field, country the organization is in, as an ISO 3166-1 2-letter country code. Corresponds to the "C" attribute type. Must be provided.

      • parse

        @NotNull() static MemberX500Name parse(@NotNull() String name)

        Creates an instance of MemberX500Name by parsing the string representation of X.500 name.

        Expects a string representation like "CN=Alice, OU=Engineering, O=R3, L=London, C=GB". Constrains are the same as for toAttributesMap plus some additional constrains: - O, L, C are required attributes.

        Parameters:
        name - The string representation of the name.
      • toAttributesMap

        @NotNull() static Map<String, String> toAttributesMap(@NotNull() String name)

        Parses the string representation of X.500 name and builds the attribute map.

        The key is the attributes keys (CN, OU, O, L, ST, C). Constraints:

        • The RDNs cannot be multivalued.
        • The attributes must have single value.
        • The only supported attributes are CN, OU, O, L, ST, C.
        • Attributes cannot be duplicated.
        Parameters:
        name - The string representation to build the attribute map from.
      • getX500Principal

        @NotNull() synchronized X500Principal getX500Principal()

        Returns the X500Principal equivalent of this name where the order of RDNs is C, ST, L, O, OU, CN (the printing order would be reversed).

      • toString

        @NotNull() String toString()

        Returns the string equivalent of this name where the order of RDNs is CN, OU, O, L, ST, C.