Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/security/auth/X500Principal.java
38924 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.security.auth;2627import java.security.Principal;28import sun.security.x509.X500Name;2930/**31* <p> This class represents an X.500 <code>Principal</code>.32* X500Principals have names such as,33* "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"34* (RFC 1779 style).35*36* <p> Principals such as this <code>X500Principal</code>37* may be associated with a particular <code>Subject</code>38* to augment that <code>Subject</code> with an additional39* identity. Refer to the <code>Subject</code> class for more information40* on how to achieve this. Authorization decisions can then be based upon41* the Principals associated with a <code>Subject</code>.42*43* @see java.security.Principal44* @see javax.security.auth.Subject45* @deprecated A new X500Principal class is available in the Java platform.46* This X500Principal classs is entirely deprecated and47* is here to allow for a smooth transition to the new48* class.49* @see javax.security.auth.x500.X500Principal50*/51@jdk.Exported(false)52@Deprecated53public class X500Principal implements Principal, java.io.Serializable {5455private static final long serialVersionUID = -8222422609431628648L;5657private static final java.util.ResourceBundle rb =58java.security.AccessController.doPrivileged59(new java.security.PrivilegedAction<java.util.ResourceBundle>() {60public java.util.ResourceBundle run() {61return (java.util.ResourceBundle.getBundle62("sun.security.util.AuthResources"));63}64});6566/**67* @serial68*/69private String name;7071transient private X500Name thisX500Name;7273/**74* Create a X500Principal with an X.500 Name,75* such as "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"76* (RFC 1779 style).77*78* <p>79*80* @param name the X.500 name81*82* @exception NullPointerException if the <code>name</code>83* is <code>null</code>. <p>84*85* @exception IllegalArgumentException if the <code>name</code>86* is improperly specified.87*/88public X500Principal(String name) {89if (name == null)90throw new NullPointerException(rb.getString("provided.null.name"));9192try {93thisX500Name = new X500Name(name);94} catch (Exception e) {95throw new IllegalArgumentException(e.toString());96}9798this.name = name;99}100101/**102* Return the Unix username for this <code>X500Principal</code>.103*104* <p>105*106* @return the Unix username for this <code>X500Principal</code>107*/108public String getName() {109return thisX500Name.getName();110}111112/**113* Return a string representation of this <code>X500Principal</code>.114*115* <p>116*117* @return a string representation of this <code>X500Principal</code>.118*/119public String toString() {120return thisX500Name.toString();121}122123/**124* Compares the specified Object with this <code>X500Principal</code>125* for equality.126*127* <p>128*129* @param o Object to be compared for equality with this130* <code>X500Principal</code>.131*132* @return true if the specified Object is equal equal to this133* <code>X500Principal</code>.134*/135public boolean equals(Object o) {136if (o == null)137return false;138139if (this == o)140return true;141142if (o instanceof X500Principal) {143X500Principal that = (X500Principal)o;144try {145X500Name thatX500Name = new X500Name(that.getName());146return thisX500Name.equals(thatX500Name);147} catch (Exception e) {148// any parsing exceptions, return false149return false;150}151} else if (o instanceof Principal) {152// this will return 'true' if 'o' is a sun.security.x509.X500Name153// and the X500Names are equal154return o.equals(thisX500Name);155}156157return false;158}159160/**161* Return a hash code for this <code>X500Principal</code>.162*163* <p>164*165* @return a hash code for this <code>X500Principal</code>.166*/167public int hashCode() {168return thisX500Name.hashCode();169}170171/**172* Reads this object from a stream (i.e., deserializes it)173*/174private void readObject(java.io.ObjectInputStream s) throws175java.io.IOException,176java.io.NotActiveException,177ClassNotFoundException {178179s.defaultReadObject();180181// re-create thisX500Name182thisX500Name = new X500Name(name);183}184}185186187