< prev index next >

## src/java.base/share/classes/java/security/Permissions.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
    559      */
    560     @Override
    561     public Enumeration<Permission> elements() {
    562         return permsMap.elements();
    563     }
    564
    565     @java.io.Serial
    566     private static final long serialVersionUID = -8491988220802933440L;
    567     // Need to maintain serialization interoperability with earlier releases,
    568     // which had the serializable field:
    569     // private Hashtable perms;
    570     /**
    571      * @serialField perms java.util.Hashtable
    572      *     A table of the Permissions (both key and value are same).
    573      */
    574     @java.io.Serial
    575     private static final ObjectStreamField[] serialPersistentFields = {
    576         new ObjectStreamField("perms", Hashtable.class),
    577     };
    578
    579     /**
    580      * @serialData Default fields.
    581      */
    582     /*

    583      * Writes the contents of the permsMap field out as a Hashtable for
    584      * serialization compatibility with earlier releases.

    585      */
    586     @java.io.Serial
    587     private void writeObject(ObjectOutputStream out) throws IOException {
    588         // Don't call out.defaultWriteObject()
    589
    590         // Copy perms into a Hashtable
    591         Hashtable<Permission, Permission> perms =
    592                 new Hashtable<>(permsMap.size()*2);
    593         perms.putAll(permsMap);
    594
    595         // Write out serializable fields
    596         ObjectOutputStream.PutField pfields = out.putFields();
    597         pfields.put("perms", perms);
    598         out.writeFields();
    599     }
    600
    601     /*
    602      * Reads in a Hashtable of Permission/Permission and saves them in the
    603      * permsMap field.

    604      */
    605     @java.io.Serial
    606     private void readObject(ObjectInputStream in) throws IOException,
    607     ClassNotFoundException {
    608         // Don't call defaultReadObject()
    609
    610         // Read in serialized fields
    611         ObjectInputStream.GetField gfields = in.readFields();
    612
    613         // Get permissions
    614         // writeObject writes a Hashtable<Class<?>, PermissionCollection> for
    615         // the perms key, so this cast is safe, unless the data is corrupt.
    616         @SuppressWarnings("unchecked")
    617         Hashtable<Permission, Permission> perms =
    618                 (Hashtable<Permission, Permission>)gfields.get("perms", null);
    619         permsMap = new ConcurrentHashMap<>(perms.size()*2);
    620         permsMap.putAll(perms);
    621
    622         // check that the Permission key and value are the same object
    623         for (Map.Entry<Permission, Permission> e : perms.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
    559      */
    560     @Override
    561     public Enumeration<Permission> elements() {
    562         return permsMap.elements();
    563     }
    564
    565     @java.io.Serial
    566     private static final long serialVersionUID = -8491988220802933440L;
    567     // Need to maintain serialization interoperability with earlier releases,
    568     // which had the serializable field:
    569     // private Hashtable perms;
    570     /**
    571      * @serialField perms java.util.Hashtable
    572      *     A table of the Permissions (both key and value are same).
    573      */
    574     @java.io.Serial
    575     private static final ObjectStreamField[] serialPersistentFields = {
    576         new ObjectStreamField("perms", Hashtable.class),
    577     };
    578
    579     /*
    580      * @serialData Default fields.
    581      */
    582
    583     /**
    584      * Writes the contents of the permsMap field out as a Hashtable for
    585      * serialization compatibility with earlier releases.
    586      *
    587      * @param  out the {@code ObjectOutputStream} to which data is written
    588      * @throws IOException if an I/O error occurs
    589      */
    590     @java.io.Serial
    591     private void writeObject(ObjectOutputStream out) throws IOException {
    592         // Don't call out.defaultWriteObject()
    593
    594         // Copy perms into a Hashtable
    595         Hashtable<Permission, Permission> perms =
    596                 new Hashtable<>(permsMap.size()*2);
    597         perms.putAll(permsMap);
    598
    599         // Write out serializable fields
    600         ObjectOutputStream.PutField pfields = out.putFields();
    601         pfields.put("perms", perms);
    602         out.writeFields();
    603     }
    604
    605     /**
    606      * Reads in a Hashtable of Permission/Permission and saves them in the
    607      * permsMap field.
    608      *
    609      * @param  in the {@code ObjectInputStream} from which data is read
    610      * @throws IOException if an I/O error occurs
    611      * @throws ClassNotFoundException if a serialized class cannot be loaded
    612      */
    613     @java.io.Serial
    614     private void readObject(ObjectInputStream in) throws IOException,
    615     ClassNotFoundException {
    616         // Don't call defaultReadObject()
    617
    618         // Read in serialized fields
    619         ObjectInputStream.GetField gfields = in.readFields();
    620
    621         // Get permissions
    622         // writeObject writes a Hashtable<Class<?>, PermissionCollection> for
    623         // the perms key, so this cast is safe, unless the data is corrupt.
    624         @SuppressWarnings("unchecked")
    625         Hashtable<Permission, Permission> perms =
    626                 (Hashtable<Permission, Permission>)gfields.get("perms", null);
    627         permsMap = new ConcurrentHashMap<>(perms.size()*2);
    628         permsMap.putAll(perms);
    629
    630         // check that the Permission key and value are the same object
    631         for (Map.Entry<Permission, Permission> e : perms.entrySet()) {

< prev index next >