< prev index next >

## src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosPrincipal.java

Print this page

      1 /*
      2  * Copyright (c) 2000, 2019, 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
    248      * @param other the object to compare to
    249      * @return true if the object passed in represents the same principal
    250      * as this one, false otherwise.
    251      */
    252     public boolean equals(Object other) {
    253
    254         if (other == this)
    255             return true;
    256
    257         if (! (other instanceof KerberosPrincipal)) {
    258             return false;
    259         }
    260         String myFullName = getName();
    261         String otherFullName = ((KerberosPrincipal) other).getName();
    262         return myFullName.equals(otherFullName);
    263     }
    264
    265     /**
    266      * Save the {@code KerberosPrincipal} object to a stream
    267      *

    268      * @serialData this {@code KerberosPrincipal} is serialized
    269      *          by writing out the PrincipalName and the
    270      *          Realm in their DER-encoded form as specified in Section 5.2.2 of
    271      *          <a href=http://www.ietf.org/rfc/rfc4120.txt> RFC4120</a>.
    272      */
    273     private void writeObject(ObjectOutputStream oos)
    274             throws IOException {
    275
    276         PrincipalName krb5Principal;
    277         try {
    278             krb5Principal  = new PrincipalName(fullName, nameType);
    279             oos.writeObject(krb5Principal.asn1Encode());
    280             oos.writeObject(krb5Principal.getRealm().asn1Encode());
    281         } catch (Exception e) {
    282             throw new IOException(e);
    283         }
    284     }
    285
    286     /**
    287      * Reads this object from a stream (i.e., deserializes it)

    288      */
    289     private void readObject(ObjectInputStream ois)
    290             throws IOException, ClassNotFoundException {
    291         byte[] asn1EncPrincipal = (byte [])ois.readObject();
    292         byte[] encRealm = (byte [])ois.readObject();
    293         try {
    294            Realm realmObject = new Realm(new DerValue(encRealm));
    295            PrincipalName krb5Principal = new PrincipalName(
    296                    new DerValue(asn1EncPrincipal), realmObject);
    297            realm = realmObject.toString();
    298            fullName = krb5Principal.toString();
    299            nameType = krb5Principal.getNameType();
    300         } catch (Exception e) {
    301             throw new IOException(e);
    302         }
    303     }
    304
    305     /**
    306      * The returned string corresponds to the single-string
    307      * representation of a Kerberos Principal name as specified in
      1 /*
      2  * Copyright (c) 2000, 2021, 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
    248      * @param other the object to compare to
    249      * @return true if the object passed in represents the same principal
    250      * as this one, false otherwise.
    251      */
    252     public boolean equals(Object other) {
    253
    254         if (other == this)
    255             return true;
    256
    257         if (! (other instanceof KerberosPrincipal)) {
    258             return false;
    259         }
    260         String myFullName = getName();
    261         String otherFullName = ((KerberosPrincipal) other).getName();
    262         return myFullName.equals(otherFullName);
    263     }
    264
    265     /**
    266      * Save the {@code KerberosPrincipal} object to a stream
    267      *
    268      * @param  oos the {@code ObjectOutputStream} to which data is written
    269      * @throws IOException if an I/O error occurs
    270      *
    271      * @serialData this {@code KerberosPrincipal} is serialized
    272      *          by writing out the PrincipalName and the
    273      *          Realm in their DER-encoded form as specified in Section 5.2.2 of
    274      *          <a href=http://www.ietf.org/rfc/rfc4120.txt> RFC4120</a>.
    275      */
    276     private void writeObject(ObjectOutputStream oos)
    277             throws IOException {
    278
    279         PrincipalName krb5Principal;
    280         try {
    281             krb5Principal  = new PrincipalName(fullName, nameType);
    282             oos.writeObject(krb5Principal.asn1Encode());
    283             oos.writeObject(krb5Principal.getRealm().asn1Encode());
    284         } catch (Exception e) {
    285             throw new IOException(e);
    286         }
    287     }
    288
    289     /**
    290      * Reads this object from a stream (i.e., deserializes it)
    291      *
    292      * @param  ois the {@code ObjectInputStream} from which data is read
    293      * @throws IOException if an I/O error occurs
    294      * @throws ClassNotFoundException if a serialized class cannot be loaded
    295      */
    296     private void readObject(ObjectInputStream ois)
    297             throws IOException, ClassNotFoundException {
    298         byte[] asn1EncPrincipal = (byte [])ois.readObject();
    299         byte[] encRealm = (byte [])ois.readObject();
    300         try {
    301            Realm realmObject = new Realm(new DerValue(encRealm));
    302            PrincipalName krb5Principal = new PrincipalName(
    303                    new DerValue(asn1EncPrincipal), realmObject);
    304            realm = realmObject.toString();
    305            fullName = krb5Principal.toString();
    306            nameType = krb5Principal.getNameType();
    307         } catch (Exception e) {
    308             throw new IOException(e);
    309         }
    310     }
    311
    312     /**
    313      * The returned string corresponds to the single-string
    314      * representation of a Kerberos Principal name as specified in

< prev index next >