< prev index next >

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

Print this page

      1 /*
      2  * Copyright (c) 1997, 2020, 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
    243     /**
    244      * Returns a new PermissionCollection object for storing BasicPermission
    245      * objects.
    246      *
    247      * <p>BasicPermission objects must be stored in a manner that allows them
    248      * to be inserted in any order, but that also enables the
    249      * PermissionCollection {@code implies} method
    250      * to be implemented in an efficient (and consistent) manner.
    251      *
    252      * @return a new PermissionCollection object suitable for
    253      * storing BasicPermissions.
    254      */
    255     @Override
    256     public PermissionCollection newPermissionCollection() {
    257         return new BasicPermissionCollection(this.getClass());
    258     }
    259
    260     /**
    261      * readObject is called to restore the state of the BasicPermission from
    262      * a stream.

    263      */
    264     @java.io.Serial
    265     private void readObject(ObjectInputStream s)
    266          throws IOException, ClassNotFoundException
    267     {
    268         s.defaultReadObject();
    269         // init is called to initialize the rest of the values.
    270         init(getName());
    271     }
    272
    273     /**
    274      * Returns the canonical name of this BasicPermission.
    275      * All internal invocations of getName should invoke this method, so
    276      * that the pre-JDK 1.6 "exitVM" and current "exitVM.*" permission are
    277      * equivalent in equals/hashCode methods.
    278      *
    279      * @return the canonical name of this BasicPermission.
    280      */
    281     final String getCanonicalName() {
    282         return exitVM ? "exitVM.*" : getName();
    471     /**
    472      * @serialField permissions java.util.Hashtable
    473      *    The BasicPermissions in this BasicPermissionCollection.
    474      *    All BasicPermissions in the collection must belong to the same class.
    475      *    The Hashtable is indexed by the BasicPermission name; the value
    476      *    of the Hashtable entry is the permission.
    477      * @serialField all_allowed boolean
    478      *   This is set to {@code true} if this BasicPermissionCollection
    479      *   contains a BasicPermission with '*' as its permission name.
    480      * @serialField permClass java.lang.Class
    481      *   The class to which all BasicPermissions in this
    482      *   BasicPermissionCollection belongs.
    483      */
    484     @java.io.Serial
    485     private static final ObjectStreamField[] serialPersistentFields = {
    486         new ObjectStreamField("permissions", Hashtable.class),
    487         new ObjectStreamField("all_allowed", Boolean.TYPE),
    488         new ObjectStreamField("permClass", Class.class),
    489     };
    490
    491     /**
    492      * @serialData Default fields.
    493      */
    494     /*

    495      * Writes the contents of the perms field out as a Hashtable for
    496      * serialization compatibility with earlier releases. all_allowed
    497      * and permClass unchanged.

    498      */
    499     @java.io.Serial
    500     private void writeObject(ObjectOutputStream out) throws IOException {
    501         // Don't call out.defaultWriteObject()
    502
    503         // Copy perms into a Hashtable
    504         Hashtable<String, Permission> permissions =
    505                 new Hashtable<>(perms.size()*2);
    506
    507         permissions.putAll(perms);
    508
    509         // Write out serializable fields
    510         ObjectOutputStream.PutField pfields = out.putFields();
    511         pfields.put("all_allowed", all_allowed);
    512         pfields.put("permissions", permissions);
    513         pfields.put("permClass", permClass);
    514         out.writeFields();
    515     }
    516
    517     /**
    518      * readObject is called to restore the state of the
    519      * BasicPermissionCollection from a stream.

    520      */
    521     @java.io.Serial
    522     private void readObject(java.io.ObjectInputStream in)
    523          throws IOException, ClassNotFoundException
    524     {
    525         // Don't call defaultReadObject()
    526
    527         // Read in serialized fields
    528         ObjectInputStream.GetField gfields = in.readFields();
    529
    530         // Get permissions
    531         // writeObject writes a Hashtable<String, Permission> for the
    532         // permissions key, so this cast is safe, unless the data is corrupt.
    533         @SuppressWarnings("unchecked")
    534         Hashtable<String, Permission> permissions =
    535                 (Hashtable<String, Permission>)gfields.get("permissions", null);
    536         perms = new ConcurrentHashMap<>(permissions.size()*2);
    537         perms.putAll(permissions);
    538
    539         // Get all_allowed
      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
    243     /**
    244      * Returns a new PermissionCollection object for storing BasicPermission
    245      * objects.
    246      *
    247      * <p>BasicPermission objects must be stored in a manner that allows them
    248      * to be inserted in any order, but that also enables the
    249      * PermissionCollection {@code implies} method
    250      * to be implemented in an efficient (and consistent) manner.
    251      *
    252      * @return a new PermissionCollection object suitable for
    253      * storing BasicPermissions.
    254      */
    255     @Override
    256     public PermissionCollection newPermissionCollection() {
    257         return new BasicPermissionCollection(this.getClass());
    258     }
    259
    260     /**
    261      * readObject is called to restore the state of the BasicPermission from
    262      * a stream.
    263      *
    264      * @param  s the {@code ObjectInputStream} from which data is read
    265      * @throws IOException if an I/O error occurs
    266      * @throws ClassNotFoundException if a serialized class cannot be loaded
    267      */
    268     @java.io.Serial
    269     private void readObject(ObjectInputStream s)
    270          throws IOException, ClassNotFoundException
    271     {
    272         s.defaultReadObject();
    273         // init is called to initialize the rest of the values.
    274         init(getName());
    275     }
    276
    277     /**
    278      * Returns the canonical name of this BasicPermission.
    279      * All internal invocations of getName should invoke this method, so
    280      * that the pre-JDK 1.6 "exitVM" and current "exitVM.*" permission are
    281      * equivalent in equals/hashCode methods.
    282      *
    283      * @return the canonical name of this BasicPermission.
    284      */
    285     final String getCanonicalName() {
    286         return exitVM ? "exitVM.*" : getName();
    475     /**
    476      * @serialField permissions java.util.Hashtable
    477      *    The BasicPermissions in this BasicPermissionCollection.
    478      *    All BasicPermissions in the collection must belong to the same class.
    479      *    The Hashtable is indexed by the BasicPermission name; the value
    480      *    of the Hashtable entry is the permission.
    481      * @serialField all_allowed boolean
    482      *   This is set to {@code true} if this BasicPermissionCollection
    483      *   contains a BasicPermission with '*' as its permission name.
    484      * @serialField permClass java.lang.Class
    485      *   The class to which all BasicPermissions in this
    486      *   BasicPermissionCollection belongs.
    487      */
    488     @java.io.Serial
    489     private static final ObjectStreamField[] serialPersistentFields = {
    490         new ObjectStreamField("permissions", Hashtable.class),
    491         new ObjectStreamField("all_allowed", Boolean.TYPE),
    492         new ObjectStreamField("permClass", Class.class),
    493     };
    494
    495     /*
    496      * @serialData Default fields.
    497      */
    498
    499     /**
    500      * Writes the contents of the perms field out as a Hashtable for
    501      * serialization compatibility with earlier releases. all_allowed
    502      * and permClass unchanged.
    503      *
    504      * @param  out the {@code ObjectOutputStream} to which data is written
    505      * @throws IOException if an I/O error occurs
    506      */
    507     @java.io.Serial
    508     private void writeObject(ObjectOutputStream out) throws IOException {
    509         // Don't call out.defaultWriteObject()
    510
    511         // Copy perms into a Hashtable
    512         Hashtable<String, Permission> permissions =
    513                 new Hashtable<>(perms.size()*2);
    514
    515         permissions.putAll(perms);
    516
    517         // Write out serializable fields
    518         ObjectOutputStream.PutField pfields = out.putFields();
    519         pfields.put("all_allowed", all_allowed);
    520         pfields.put("permissions", permissions);
    521         pfields.put("permClass", permClass);
    522         out.writeFields();
    523     }
    524
    525     /**
    526      * readObject is called to restore the state of the
    527      * BasicPermissionCollection from a stream.
    528      *
    529      * @param  in the {@code ObjectInputStream} from which data is read
    530      * @throws IOException if an I/O error occurs
    531      * @throws ClassNotFoundException if a serialized class cannot be loaded
    532      */
    533     @java.io.Serial
    534     private void readObject(java.io.ObjectInputStream in)
    535          throws IOException, ClassNotFoundException
    536     {
    537         // Don't call defaultReadObject()
    538
    539         // Read in serialized fields
    540         ObjectInputStream.GetField gfields = in.readFields();
    541
    542         // Get permissions
    543         // writeObject writes a Hashtable<String, Permission> for the
    544         // permissions key, so this cast is safe, unless the data is corrupt.
    545         @SuppressWarnings("unchecked")
    546         Hashtable<String, Permission> permissions =
    547                 (Hashtable<String, Permission>)gfields.get("permissions", null);
    548         perms = new ConcurrentHashMap<>(permissions.size()*2);
    549         perms.putAll(permissions);
    550
    551         // Get all_allowed

< prev index next >