< prev index next >

src/share/classes/javax/security/auth/x500/X500Principal.java

Print this page
rev 1461 : 6987827: security/util/Resources.java needs improvement
Reviewed-by: valeriep
   1 /*
   2  * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 138      * name maps to an improperly specified OID, an
 139      * <code>IllegalArgumentException</code> is thrown. It is permissible to
 140      * have 2 different keywords that map to the same OID.
 141      *
 142      * @param name an X.500 distinguished name in RFC 1779 or RFC 2253 format
 143      * @param keywordMap an attribute type keyword map, where each key is a
 144      *   keyword String that maps to a corresponding object identifier in String
 145      *   form (a sequence of nonnegative integers separated by periods). The map
 146      *   may be empty but never <code>null</code>.
 147      * @exception NullPointerException if <code>name</code> or
 148      *   <code>keywordMap</code> is <code>null</code>
 149      * @exception IllegalArgumentException if the <code>name</code> is
 150      *   improperly specified or a keyword in the <code>name</code> maps to an
 151      *   OID that is not in the correct form
 152      * @since 1.6
 153      */
 154     public X500Principal(String name, Map<String, String> keywordMap) {
 155         if (name == null) {
 156             throw new NullPointerException
 157                 (sun.security.util.ResourcesMgr.getString
 158                 ("provided null name"));
 159         }
 160         if (keywordMap == null) {
 161             throw new NullPointerException
 162                 (sun.security.util.ResourcesMgr.getString
 163                 ("provided null keyword map"));
 164         }
 165 
 166         try {
 167             thisX500Name = new X500Name(name, keywordMap);
 168         } catch (Exception e) {
 169             IllegalArgumentException iae = new IllegalArgumentException
 170                         ("improperly specified input name: " + name);
 171             iae.initCause(e);
 172             throw iae;
 173         }
 174     }
 175 
 176     /**
 177      * Creates an <code>X500Principal</code> from a distinguished name in
 178      * ASN.1 DER encoded form. The ASN.1 notation for this structure is as
 179      * follows.
 180      * <pre><code>
 181      * Name ::= CHOICE {
 182      *   RDNSequence }
 183      *


 374      * by other implementations; therefore do not use this method if
 375      * you are unsure if these keywords will be recognized by other
 376      * implementations.
 377      *
 378      * @param format the format to use
 379      * @param oidMap an OID map, where each key is an object identifier in
 380      *  String form (a sequence of nonnegative integers separated by periods)
 381      *  that maps to a corresponding attribute type keyword String.
 382      *  The map may be empty but never <code>null</code>.
 383      * @return a string representation of this <code>X500Principal</code>
 384      *          using the specified format
 385      * @throws IllegalArgumentException if the specified format is invalid,
 386      *  null, or an OID in the name maps to an improperly specified keyword
 387      * @throws NullPointerException if <code>oidMap</code> is <code>null</code>
 388      * @since 1.6
 389      */
 390     public String getName(String format, Map<String, String> oidMap) {
 391         if (oidMap == null) {
 392             throw new NullPointerException
 393                 (sun.security.util.ResourcesMgr.getString
 394                 ("provided null OID map"));
 395         }
 396         if (format != null) {
 397             if (format.equalsIgnoreCase(RFC1779)) {
 398                 return thisX500Name.getRFC1779Name(oidMap);
 399             } else if (format.equalsIgnoreCase(RFC2253)) {
 400                 return thisX500Name.getRFC2253Name(oidMap);
 401             }
 402         }
 403         throw new IllegalArgumentException("invalid format specified");
 404     }
 405 
 406     /**
 407      * Returns the distinguished name in ASN.1 DER encoded form. The ASN.1
 408      * notation for this structure is supplied in the documentation for
 409      * {@link #X500Principal(byte[] name) X500Principal(byte[] name)}.
 410      *
 411      * <p>Note that the byte array returned is cloned to protect against
 412      * subsequent modifications.
 413      *
 414      * @return a byte array containing the distinguished name in ASN.1 DER


   1 /*
   2  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 138      * name maps to an improperly specified OID, an
 139      * <code>IllegalArgumentException</code> is thrown. It is permissible to
 140      * have 2 different keywords that map to the same OID.
 141      *
 142      * @param name an X.500 distinguished name in RFC 1779 or RFC 2253 format
 143      * @param keywordMap an attribute type keyword map, where each key is a
 144      *   keyword String that maps to a corresponding object identifier in String
 145      *   form (a sequence of nonnegative integers separated by periods). The map
 146      *   may be empty but never <code>null</code>.
 147      * @exception NullPointerException if <code>name</code> or
 148      *   <code>keywordMap</code> is <code>null</code>
 149      * @exception IllegalArgumentException if the <code>name</code> is
 150      *   improperly specified or a keyword in the <code>name</code> maps to an
 151      *   OID that is not in the correct form
 152      * @since 1.6
 153      */
 154     public X500Principal(String name, Map<String, String> keywordMap) {
 155         if (name == null) {
 156             throw new NullPointerException
 157                 (sun.security.util.ResourcesMgr.getString
 158                 ("provided.null.name"));
 159         }
 160         if (keywordMap == null) {
 161             throw new NullPointerException
 162                 (sun.security.util.ResourcesMgr.getString
 163                 ("provided.null.keyword.map"));
 164         }
 165 
 166         try {
 167             thisX500Name = new X500Name(name, keywordMap);
 168         } catch (Exception e) {
 169             IllegalArgumentException iae = new IllegalArgumentException
 170                         ("improperly specified input name: " + name);
 171             iae.initCause(e);
 172             throw iae;
 173         }
 174     }
 175 
 176     /**
 177      * Creates an <code>X500Principal</code> from a distinguished name in
 178      * ASN.1 DER encoded form. The ASN.1 notation for this structure is as
 179      * follows.
 180      * <pre><code>
 181      * Name ::= CHOICE {
 182      *   RDNSequence }
 183      *


 374      * by other implementations; therefore do not use this method if
 375      * you are unsure if these keywords will be recognized by other
 376      * implementations.
 377      *
 378      * @param format the format to use
 379      * @param oidMap an OID map, where each key is an object identifier in
 380      *  String form (a sequence of nonnegative integers separated by periods)
 381      *  that maps to a corresponding attribute type keyword String.
 382      *  The map may be empty but never <code>null</code>.
 383      * @return a string representation of this <code>X500Principal</code>
 384      *          using the specified format
 385      * @throws IllegalArgumentException if the specified format is invalid,
 386      *  null, or an OID in the name maps to an improperly specified keyword
 387      * @throws NullPointerException if <code>oidMap</code> is <code>null</code>
 388      * @since 1.6
 389      */
 390     public String getName(String format, Map<String, String> oidMap) {
 391         if (oidMap == null) {
 392             throw new NullPointerException
 393                 (sun.security.util.ResourcesMgr.getString
 394                 ("provided.null.OID.map"));
 395         }
 396         if (format != null) {
 397             if (format.equalsIgnoreCase(RFC1779)) {
 398                 return thisX500Name.getRFC1779Name(oidMap);
 399             } else if (format.equalsIgnoreCase(RFC2253)) {
 400                 return thisX500Name.getRFC2253Name(oidMap);
 401             }
 402         }
 403         throw new IllegalArgumentException("invalid format specified");
 404     }
 405 
 406     /**
 407      * Returns the distinguished name in ASN.1 DER encoded form. The ASN.1
 408      * notation for this structure is supplied in the documentation for
 409      * {@link #X500Principal(byte[] name) X500Principal(byte[] name)}.
 410      *
 411      * <p>Note that the byte array returned is cloned to protect against
 412      * subsequent modifications.
 413      *
 414      * @return a byte array containing the distinguished name in ASN.1 DER


< prev index next >