jdk/src/java.base/share/classes/javax/security/auth/x500/X500Principal.java
author juh
Tue, 07 Oct 2014 22:23:19 -0700
changeset 26967 c182469301ee
parent 25859 3317bb8137f4
permissions -rw-r--r--
8037550: Update RFC references in javadoc to RFC 5280 Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.security.auth.x500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.security.x509.X500Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
    36
 * <p> This class represents an X.500 {@code Principal}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
    37
 * {@code X500Principal}s are represented by distinguished names such as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p> This class can be instantiated by using a string representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * of the distinguished name, or by using the ASN.1 DER encoded byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * representation of the distinguished name.  The current specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * for the string representation of a distinguished name is defined in
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
    44
 * <a href="http://tools.ietf.org/html/rfc2253">RFC 2253: Lightweight
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Directory Access Protocol (v3): UTF-8 String Representation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Distinguished Names</a>. This class, however, accepts string formats from
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
    47
 * both RFC 2253 and <a href="http://tools.ietf.org/html/rfc1779">RFC 1779:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * A String Representation of Distinguished Names</a>, and also recognizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * attribute type keywords whose OIDs (Object Identifiers) are defined in
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
    50
 * <a href="http://tools.ietf.org/html/rfc5280">RFC 5280: Internet X.509
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Public Key Infrastructure Certificate and CRL Profile</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
    53
 * <p> The string representation for this {@code X500Principal}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
    54
 * can be obtained by calling the {@code getName} methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
    56
 * <p> Note that the {@code getSubjectX500Principal} and
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
    57
 * {@code getIssuerX500Principal} methods of
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
    58
 * {@code X509Certificate} return X500Principals representing the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * issuer and subject fields of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see java.security.cert.X509Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
public final class X500Principal implements Principal, java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final long serialVersionUID = -500463348111345721L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * RFC 1779 String format of Distinguished Names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final String RFC1779 = "RFC1779";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * RFC 2253 String format of Distinguished Names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final String RFC2253 = "RFC2253";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Canonical String format of Distinguished Names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static final String CANONICAL = "CANONICAL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * The X500Name representing this principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * NOTE: this field is reflectively accessed from within X500Name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private transient X500Name thisX500Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Creates an X500Principal by wrapping an X500Name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * NOTE: The constructor is package private. It is intended to be accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * using privileged reflection from classes in sun.security.*.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Currently referenced from sun.security.x509.X500Name.asX500Principal().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    X500Principal(X500Name x500Name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        thisX500Name = x500Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   100
     * Creates an {@code X500Principal} from a string representation of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * an X.500 distinguished name (ex:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * The distinguished name must be specified using the grammar defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * RFC 1779 or RFC 2253 (either format is acceptable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <p>This constructor recognizes the attribute type keywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * defined in RFC 1779 and RFC 2253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * (and listed in {@link #getName(String format) getName(String format)}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * as well as the T, DNQ or DNQUALIFIER, SURNAME, GIVENNAME, INITIALS,
11846
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   110
     * GENERATION, EMAILADDRESS, and SERIALNUMBER keywords whose Object
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   111
     * Identifiers (OIDs) are defined in RFC 5280.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Any other attribute type must be specified as an OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
11846
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   114
     * <p>This implementation enforces a more restrictive OID syntax than
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   115
     * defined in RFC 1779 and 2253. It uses the more correct syntax defined in
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   116
     * <a href="http://www.ietf.org/rfc/rfc4512.txt">RFC 4512</a>, which
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   117
     * specifies that OIDs contain at least 2 digits:
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   118
     *
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   119
     * <p>{@code numericoid = number 1*( DOT number ) }
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   120
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param name an X.500 distinguished name in RFC 1779 or RFC 2253 format
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   122
     * @exception NullPointerException if the {@code name}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   123
     *                  is {@code null}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   124
     * @exception IllegalArgumentException if the {@code name}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *                  is improperly specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public X500Principal(String name) {
10709
d865c9f21240 7092375: Security Libraries don't build with javac -Werror
xuelei
parents: 7179
diff changeset
   128
        this(name, Collections.<String, String>emptyMap());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   132
     * Creates an {@code X500Principal} from a string representation of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * an X.500 distinguished name (ex:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * The distinguished name must be specified using the grammar defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * RFC 1779 or RFC 2253 (either format is acceptable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <p> This constructor recognizes the attribute type keywords specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * in {@link #X500Principal(String)} and also recognizes additional
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   140
     * keywords that have entries in the {@code keywordMap} parameter.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Keyword entries in the keywordMap take precedence over the default
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   142
     * keywords recognized by {@code X500Principal(String)}. Keywords
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * MUST be specified in all upper-case, otherwise they will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Improperly specified keywords are ignored; however if a keyword in the
11846
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   145
     * name maps to an improperly specified Object Identifier (OID), an
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   146
     * {@code IllegalArgumentException} is thrown. It is permissible to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * have 2 different keywords that map to the same OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
11846
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   149
     * <p>This implementation enforces a more restrictive OID syntax than
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   150
     * defined in RFC 1779 and 2253. It uses the more correct syntax defined in
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   151
     * <a href="http://www.ietf.org/rfc/rfc4512.txt">RFC 4512</a>, which
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   152
     * specifies that OIDs contain at least 2 digits:
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   153
     *
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   154
     * <p>{@code numericoid = number 1*( DOT number ) }
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10709
diff changeset
   155
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param name an X.500 distinguished name in RFC 1779 or RFC 2253 format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param keywordMap an attribute type keyword map, where each key is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *   keyword String that maps to a corresponding object identifier in String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *   form (a sequence of nonnegative integers separated by periods). The map
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   160
     *   may be empty but never {@code null}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   161
     * @exception NullPointerException if {@code name} or
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   162
     *   {@code keywordMap} is {@code null}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   163
     * @exception IllegalArgumentException if the {@code name} is
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   164
     *   improperly specified or a keyword in the {@code name} maps to an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *   OID that is not in the correct form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public X500Principal(String name, Map<String, String> keywordMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                (sun.security.util.ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   172
                ("provided.null.name"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (keywordMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            throw new NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                (sun.security.util.ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   177
                ("provided.null.keyword.map"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            thisX500Name = new X500Name(name, keywordMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            IllegalArgumentException iae = new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        ("improperly specified input name: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            iae.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            throw iae;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   191
     * Creates an {@code X500Principal} from a distinguished name in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * ASN.1 DER encoded form. The ASN.1 notation for this structure is as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * follows.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   194
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Name ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *   RDNSequence }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * RelativeDistinguishedName ::=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *   SET SIZE (1 .. MAX) OF AttributeTypeAndValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * AttributeTypeAndValue ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *   type     AttributeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *   value    AttributeValue }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * AttributeType ::= OBJECT IDENTIFIER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * AttributeValue ::= ANY DEFINED BY AttributeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * ....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * DirectoryString ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *       teletexString           TeletexString (SIZE (1..MAX)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *       printableString         PrintableString (SIZE (1..MAX)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *       universalString         UniversalString (SIZE (1..MAX)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *       utf8String              UTF8String (SIZE (1.. MAX)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *       bmpString               BMPString (SIZE (1..MAX)) }
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   217
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param name a byte array containing the distinguished name in ASN.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * DER encoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @throws IllegalArgumentException if an encoding error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *          (incorrect form for DN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public X500Principal(byte[] name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            thisX500Name = new X500Name(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            IllegalArgumentException iae = new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                        ("improperly specified input name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            iae.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            throw iae;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   236
     * Creates an {@code X500Principal} from an {@code InputStream}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * containing the distinguished name in ASN.1 DER encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * The ASN.1 notation for this structure is supplied in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * {@link #X500Principal(byte[] name) X500Principal(byte[] name)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <p> The read position of the input stream is positioned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * to the next available byte after the encoded distinguished name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   245
     * @param is an {@code InputStream} containing the distinguished
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *          name in ASN.1 DER encoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   248
     * @exception NullPointerException if the {@code InputStream}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   249
     *          is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @exception IllegalArgumentException if an encoding error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *          (incorrect form for DN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public X500Principal(InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (is == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            throw new NullPointerException("provided null input stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (is.markSupported())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                is.mark(is.available() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            DerValue der = new DerValue(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            thisX500Name = new X500Name(der.data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (is.markSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    is.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    IllegalArgumentException iae = new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        ("improperly specified input stream " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        ("and unable to reset input stream"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    iae.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    throw iae;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            IllegalArgumentException iae = new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                        ("improperly specified input stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            iae.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            throw iae;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Returns a string representation of the X.500 distinguished name using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * the format defined in RFC 2253.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * <p>This method is equivalent to calling
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   287
     * {@code getName(X500Principal.RFC2253)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   289
     * @return the distinguished name of this {@code X500Principal}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return getName(X500Principal.RFC2253);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Returns a string representation of the X.500 distinguished name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * using the specified format. Valid values for the format are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * "RFC1779", "RFC2253", and "CANONICAL" (case insensitive).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * <p> If "RFC1779" is specified as the format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * this method emits the attribute type keywords defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * RFC 1779 (CN, L, ST, O, OU, C, STREET).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Any other attribute type is emitted as an OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <p> If "RFC2253" is specified as the format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * this method emits the attribute type keywords defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * RFC 2253 (CN, L, ST, O, OU, C, STREET, DC, UID).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Any other attribute type is emitted as an OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Under a strict reading, RFC 2253 only specifies a UTF-8 string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * representation. The String returned by this method is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Unicode string achieved by decoding this UTF-8 representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * <p> If "CANONICAL" is specified as the format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * this method returns an RFC 2253 conformant string representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * with the following additional canonicalizations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
21955
abc02575919c 8029475: Fix more doclint issues in javax.security
darcy
parents: 18830
diff changeset
   317
     * <ol>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <li> Leading zeros are removed from attribute types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *          that are encoded as dotted decimal OIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <li> DirectoryString attribute values of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *          PrintableString and UTF8String are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *          output in hexadecimal format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * <li> DirectoryString attribute values of types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *          other than PrintableString and UTF8String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *          are output in hexadecimal format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <li> Leading and trailing white space characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *          are removed from non-hexadecimal attribute values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *          (unless the value consists entirely of white space characters)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <li> Internal substrings of one or more white space characters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *          converted to a single space in non-hexadecimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *          attribute values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <li> Relative Distinguished Names containing more than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *          Attribute Value Assertion (AVA) are output in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *          following order: an alphabetical ordering of AVAs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *          containing standard keywords, followed by a numeric
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *          ordering of AVAs containing OID keywords.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <li> The only characters in attribute values that are escaped are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *          those which section 2.4 of RFC 2253 states must be escaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *          (they are escaped using a preceding backslash character)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <li> The entire name is converted to upper case
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   341
     *          using {@code String.toUpperCase(Locale.US)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * <li> The entire name is converted to lower case
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   343
     *          using {@code String.toLowerCase(Locale.US)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <li> The name is finally normalized using normalization form KD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *          as described in the Unicode Standard and UAX #15
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * <p> Additional standard formats may be introduced in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @param format the format to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   352
     * @return a string representation of this {@code X500Principal}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *          using the specified format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @throws IllegalArgumentException if the specified format is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *          or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public String getName(String format) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (format != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (format.equalsIgnoreCase(RFC1779)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                return thisX500Name.getRFC1779Name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            } else if (format.equalsIgnoreCase(RFC2253)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                return thisX500Name.getRFC2253Name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            } else if (format.equalsIgnoreCase(CANONICAL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                return thisX500Name.getRFC2253CanonicalName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        throw new IllegalArgumentException("invalid format specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Returns a string representation of the X.500 distinguished name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * using the specified format. Valid values for the format are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * "RFC1779" and "RFC2253" (case insensitive). "CANONICAL" is not
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   374
     * permitted and an {@code IllegalArgumentException} will be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * <p>This method returns Strings in the format as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * {@link #getName(String)} and also emits additional attribute type
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   378
     * keywords for OIDs that have entries in the {@code oidMap}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * parameter. OID entries in the oidMap take precedence over the default
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   380
     * OIDs recognized by {@code getName(String)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * Improperly specified OIDs are ignored; however if an OID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * in the name maps to an improperly specified keyword, an
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   383
     * {@code IllegalArgumentException} is thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * <p> Additional standard formats may be introduced in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * <p> Warning: additional attribute type keywords may not be recognized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * by other implementations; therefore do not use this method if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * you are unsure if these keywords will be recognized by other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @param format the format to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @param oidMap an OID map, where each key is an object identifier in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *  String form (a sequence of nonnegative integers separated by periods)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *  that maps to a corresponding attribute type keyword String.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   396
     *  The map may be empty but never {@code null}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   397
     * @return a string representation of this {@code X500Principal}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *          using the specified format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @throws IllegalArgumentException if the specified format is invalid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *  null, or an OID in the name maps to an improperly specified keyword
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   401
     * @throws NullPointerException if {@code oidMap} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public String getName(String format, Map<String, String> oidMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (oidMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            throw new NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                (sun.security.util.ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   408
                ("provided.null.OID.map"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (format != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (format.equalsIgnoreCase(RFC1779)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                return thisX500Name.getRFC1779Name(oidMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            } else if (format.equalsIgnoreCase(RFC2253)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                return thisX500Name.getRFC2253Name(oidMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        throw new IllegalArgumentException("invalid format specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Returns the distinguished name in ASN.1 DER encoded form. The ASN.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * notation for this structure is supplied in the documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * {@link #X500Principal(byte[] name) X500Principal(byte[] name)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * <p>Note that the byte array returned is cloned to protect against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * subsequent modifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @return a byte array containing the distinguished name in ASN.1 DER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * encoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public byte[] getEncoded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            return thisX500Name.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            throw new RuntimeException("unable to get encoding", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Return a user-friendly string representation of this
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   441
     * {@code X500Principal}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   443
     * @return a string representation of this {@code X500Principal}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return thisX500Name.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   450
     * Compares the specified {@code Object} with this
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   451
     * {@code X500Principal} for equality.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   453
     * <p> Specifically, this method returns {@code true} if
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   454
     * the {@code Object} <i>o</i> is an {@code X500Principal}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * and if the respective canonical string representations
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   456
     * (obtained via the {@code getName(X500Principal.CANONICAL)} method)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * of this object and <i>o</i> are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   459
     * <p> This implementation is compliant with the requirements of RFC 5280.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @param o Object to be compared for equality with this
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   462
     *          {@code X500Principal}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   464
     * @return {@code true} if the specified {@code Object} is equal
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   465
     *          to this {@code X500Principal}, {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (this == o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        if (o instanceof X500Principal == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        X500Principal other = (X500Principal)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return this.thisX500Name.equals(other.thisX500Name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   479
     * Return a hash code for this {@code X500Principal}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * <p> The hash code is calculated via:
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   482
     * {@code getName(X500Principal.CANONICAL).hashCode()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   484
     * @return a hash code for this {@code X500Principal}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return thisX500Name.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * Save the X500Principal object to a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   493
     * @serialData this {@code X500Principal} is serialized
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *          by writing out its DER-encoded form
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 11846
diff changeset
   495
     *          (the value of {@code getEncoded} is serialized).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        s.writeObject(thisX500Name.getEncodedInternal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Reads this object from a stream (i.e., deserializes it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        throws java.io.IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
               java.io.NotActiveException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
               ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        // re-create thisX500Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        thisX500Name = new X500Name((byte[])s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
}