src/java.base/share/classes/javax/security/auth/Subject.java
changeset 57950 4612a3cfb927
parent 47216 71c04702a3d5
child 58519 6e017b301287
equal deleted inserted replaced
57945:e09c993ac476 57950:4612a3cfb927
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    98  * @see java.security.Principal
    98  * @see java.security.Principal
    99  * @see java.security.DomainCombiner
    99  * @see java.security.DomainCombiner
   100  */
   100  */
   101 public final class Subject implements java.io.Serializable {
   101 public final class Subject implements java.io.Serializable {
   102 
   102 
       
   103     @java.io.Serial
   103     private static final long serialVersionUID = -8308522755600156056L;
   104     private static final long serialVersionUID = -8308522755600156056L;
   104 
   105 
   105     /**
   106     /**
   106      * A {@code Set} that provides a view of all of this
   107      * A {@code Set} that provides a view of all of this
   107      * Subject's Principals
   108      * Subject's Principals
   944     }
   945     }
   945 
   946 
   946     /**
   947     /**
   947      * Writes this object out to a stream (i.e., serializes it).
   948      * Writes this object out to a stream (i.e., serializes it).
   948      */
   949      */
       
   950     @java.io.Serial
   949     private void writeObject(java.io.ObjectOutputStream oos)
   951     private void writeObject(java.io.ObjectOutputStream oos)
   950                 throws java.io.IOException {
   952                 throws java.io.IOException {
   951         synchronized(principals) {
   953         synchronized(principals) {
   952             oos.defaultWriteObject();
   954             oos.defaultWriteObject();
   953         }
   955         }
   955 
   957 
   956     /**
   958     /**
   957      * Reads this object from a stream (i.e., deserializes it)
   959      * Reads this object from a stream (i.e., deserializes it)
   958      */
   960      */
   959     @SuppressWarnings("unchecked")
   961     @SuppressWarnings("unchecked")
       
   962     @java.io.Serial
   960     private void readObject(java.io.ObjectInputStream s)
   963     private void readObject(java.io.ObjectInputStream s)
   961                 throws java.io.IOException, ClassNotFoundException {
   964                 throws java.io.IOException, ClassNotFoundException {
   962 
   965 
   963         ObjectInputStream.GetField gf = s.readFields();
   966         ObjectInputStream.GetField gf = s.readFields();
   964 
   967 
  1025      * @serial include
  1028      * @serial include
  1026      */
  1029      */
  1027     private static class SecureSet<E>
  1030     private static class SecureSet<E>
  1028         implements Set<E>, java.io.Serializable {
  1031         implements Set<E>, java.io.Serializable {
  1029 
  1032 
       
  1033         @java.io.Serial
  1030         private static final long serialVersionUID = 7911754171111800359L;
  1034         private static final long serialVersionUID = 7911754171111800359L;
  1031 
  1035 
  1032         /**
  1036         /**
  1033          * @serialField this$0 Subject The outer Subject instance.
  1037          * @serialField this$0 Subject The outer Subject instance.
  1034          * @serialField elements LinkedList The elements in this set.
  1038          * @serialField elements LinkedList The elements in this set.
  1035          */
  1039          */
       
  1040         @java.io.Serial
  1036         private static final ObjectStreamField[] serialPersistentFields = {
  1041         private static final ObjectStreamField[] serialPersistentFields = {
  1037             new ObjectStreamField("this$0", Subject.class),
  1042             new ObjectStreamField("this$0", Subject.class),
  1038             new ObjectStreamField("elements", LinkedList.class),
  1043             new ObjectStreamField("elements", LinkedList.class),
  1039             new ObjectStreamField("which", int.class)
  1044             new ObjectStreamField("which", int.class)
  1040         };
  1045         };
  1406          *      a security check is performed to ensure that
  1411          *      a security check is performed to ensure that
  1407          *      the caller has permission to access each credential
  1412          *      the caller has permission to access each credential
  1408          *      in the set.  If the security check passes,
  1413          *      in the set.  If the security check passes,
  1409          *      the set is serialized.
  1414          *      the set is serialized.
  1410          */
  1415          */
       
  1416         @java.io.Serial
  1411         private void writeObject(java.io.ObjectOutputStream oos)
  1417         private void writeObject(java.io.ObjectOutputStream oos)
  1412                 throws java.io.IOException {
  1418                 throws java.io.IOException {
  1413 
  1419 
  1414             if (which == Subject.PRIV_CREDENTIAL_SET) {
  1420             if (which == Subject.PRIV_CREDENTIAL_SET) {
  1415                 // check permissions before serializing
  1421                 // check permissions before serializing
  1424             fields.put("which", which);
  1430             fields.put("which", which);
  1425             oos.writeFields();
  1431             oos.writeFields();
  1426         }
  1432         }
  1427 
  1433 
  1428         @SuppressWarnings("unchecked")
  1434         @SuppressWarnings("unchecked")
       
  1435         @java.io.Serial
  1429         private void readObject(ObjectInputStream ois)
  1436         private void readObject(ObjectInputStream ois)
  1430             throws IOException, ClassNotFoundException
  1437             throws IOException, ClassNotFoundException
  1431         {
  1438         {
  1432             ObjectInputStream.GetField fields = ois.readFields();
  1439             ObjectInputStream.GetField fields = ois.readFields();
  1433             subject = (Subject) fields.get("this$0", null);
  1440             subject = (Subject) fields.get("this$0", null);