< prev index next >

## src/java.base/share/classes/java/security/UnresolvedPermissionCollection.java

Print this page

      1 /*
      2  * Copyright (c) 1997, 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
    137         return Collections.enumeration(results);
    138     }
    139
    140     @java.io.Serial
    141     private static final long serialVersionUID = -7176153071733132400L;
    142
    143     // Need to maintain serialization interoperability with earlier releases,
    144     // which had the serializable field:
    145     // private Hashtable permissions; // keyed on type
    146
    147     /**
    148      * @serialField permissions java.util.Hashtable
    149      *     A table of the UnresolvedPermissions keyed on type, value is Vector
    150      *     of permissions
    151      */
    152     @java.io.Serial
    153     private static final ObjectStreamField[] serialPersistentFields = {
    154         new ObjectStreamField("permissions", Hashtable.class),
    155     };
    156
    157     /**
    158      * @serialData Default field.
    159      */
    160     /*

    161      * Writes the contents of the perms field out as a Hashtable
    162      * in which the values are Vectors for
    163      * serialization compatibility with earlier releases.

    164      */
    165     @java.io.Serial
    166     private void writeObject(ObjectOutputStream out) throws IOException {
    167         // Don't call out.defaultWriteObject()
    168
    169         // Copy perms into a Hashtable
    170         Hashtable<String, Vector<UnresolvedPermission>> permissions =
    171             new Hashtable<>(perms.size()*2);
    172
    173         // Convert each entry (List) into a Vector
    174         Set<Map.Entry<String, List<UnresolvedPermission>>> set = perms.entrySet();
    175         for (Map.Entry<String, List<UnresolvedPermission>> e : set) {
    176             // Convert list into Vector
    177             List<UnresolvedPermission> list = e.getValue();
    178             Vector<UnresolvedPermission> vec = new Vector<>(list);
    179
    180             // Add to Hashtable being serialized
    181             permissions.put(e.getKey(), vec);
    182         }
    183
    184         // Write out serializable fields
    185         ObjectOutputStream.PutField pfields = out.putFields();
    186         pfields.put("permissions", permissions);
    187         out.writeFields();
    188     }
    189
    190     /*
    191      * Reads in a Hashtable in which the values are Vectors of
    192      * UnresolvedPermissions and saves them in the perms field.

    193      */
    194     @java.io.Serial
    195     private void readObject(ObjectInputStream in) throws IOException,
    196     ClassNotFoundException {
    197         // Don't call defaultReadObject()
    198
    199         // Read in serialized fields
    200         ObjectInputStream.GetField gfields = in.readFields();
    201
    202         // Get permissions
    203         @SuppressWarnings("unchecked")
    204         // writeObject writes a Hashtable<String, Vector<UnresolvedPermission>>
    205         // for the permissions key, so this cast is safe, unless the data is corrupt.
    206         Hashtable<String, Vector<UnresolvedPermission>> permissions =
    207                 (Hashtable<String, Vector<UnresolvedPermission>>)
    208                 gfields.get("permissions", null);
    209         perms = new ConcurrentHashMap<>(permissions.size()*2);
    210
    211         // Convert each entry (Vector) into a List
    212         Set<Map.Entry<String, Vector<UnresolvedPermission>>> set = permissions.entrySet();
      1 /*
      2  * Copyright (c) 1997, 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
    137         return Collections.enumeration(results);
    138     }
    139
    140     @java.io.Serial
    141     private static final long serialVersionUID = -7176153071733132400L;
    142
    143     // Need to maintain serialization interoperability with earlier releases,
    144     // which had the serializable field:
    145     // private Hashtable permissions; // keyed on type
    146
    147     /**
    148      * @serialField permissions java.util.Hashtable
    149      *     A table of the UnresolvedPermissions keyed on type, value is Vector
    150      *     of permissions
    151      */
    152     @java.io.Serial
    153     private static final ObjectStreamField[] serialPersistentFields = {
    154         new ObjectStreamField("permissions", Hashtable.class),
    155     };
    156
    157     /*
    158      * @serialData Default field.
    159      */
    160
    161     /**
    162      * Writes the contents of the perms field out as a Hashtable
    163      * in which the values are Vectors for
    164      * serialization compatibility with earlier releases.
    165      *
    166      * @param  out the {@code ObjectOutputStream} to which data is written
    167      * @throws IOException if an I/O error occurs
    168      */
    169     @java.io.Serial
    170     private void writeObject(ObjectOutputStream out) throws IOException {
    171         // Don't call out.defaultWriteObject()
    172
    173         // Copy perms into a Hashtable
    174         Hashtable<String, Vector<UnresolvedPermission>> permissions =
    175             new Hashtable<>(perms.size()*2);
    176
    177         // Convert each entry (List) into a Vector
    178         Set<Map.Entry<String, List<UnresolvedPermission>>> set = perms.entrySet();
    179         for (Map.Entry<String, List<UnresolvedPermission>> e : set) {
    180             // Convert list into Vector
    181             List<UnresolvedPermission> list = e.getValue();
    182             Vector<UnresolvedPermission> vec = new Vector<>(list);
    183
    184             // Add to Hashtable being serialized
    185             permissions.put(e.getKey(), vec);
    186         }
    187
    188         // Write out serializable fields
    189         ObjectOutputStream.PutField pfields = out.putFields();
    190         pfields.put("permissions", permissions);
    191         out.writeFields();
    192     }
    193
    194     /**
    195      * Reads in a Hashtable in which the values are Vectors of
    196      * UnresolvedPermissions and saves them in the perms field.
    197      *
    198      * @param  in the {@code ObjectInputStream} from which data is read
    199      * @throws IOException if an I/O error occurs
    200      * @throws ClassNotFoundException if a serialized class cannot be loaded
    201      */
    202     @java.io.Serial
    203     private void readObject(ObjectInputStream in) throws IOException,
    204     ClassNotFoundException {
    205         // Don't call defaultReadObject()
    206
    207         // Read in serialized fields
    208         ObjectInputStream.GetField gfields = in.readFields();
    209
    210         // Get permissions
    211         @SuppressWarnings("unchecked")
    212         // writeObject writes a Hashtable<String, Vector<UnresolvedPermission>>
    213         // for the permissions key, so this cast is safe, unless the data is corrupt.
    214         Hashtable<String, Vector<UnresolvedPermission>> permissions =
    215                 (Hashtable<String, Vector<UnresolvedPermission>>)
    216                 gfields.get("permissions", null);
    217         perms = new ConcurrentHashMap<>(permissions.size()*2);
    218
    219         // Convert each entry (Vector) into a List
    220         Set<Map.Entry<String, Vector<UnresolvedPermission>>> set = permissions.entrySet();

< prev index next >