< prev index next >

## src/java.base/share/classes/java/security/UnresolvedPermission.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
    504
    505     public PermissionCollection newPermissionCollection() {
    506         return new UnresolvedPermissionCollection();
    507     }
    508
    509     /**
    510      * Writes this object out to a stream (i.e., serializes it).
    511      *
    512      * @serialData An initial {@code String} denoting the
    513      * {@code type} is followed by a {@code String} denoting the
    514      * {@code name} is followed by a {@code String} denoting the
    515      * {@code actions} is followed by an {@code int} indicating the
    516      * number of certificates to follow
    517      * (a value of "zero" denotes that there are no certificates associated
    518      * with this object).
    519      * Each certificate is written out starting with a {@code String}
    520      * denoting the certificate type, followed by an
    521      * {@code int} specifying the length of the certificate encoding,
    522      * followed by the certificate encoding itself which is written out as an
    523      * array of bytes.

    524      */
    525     @java.io.Serial
    526     private void writeObject(java.io.ObjectOutputStream oos)
    527         throws IOException
    528     {
    529         oos.defaultWriteObject();
    530
    531         if (certs==null || certs.length==0) {
    532             oos.writeInt(0);
    533         } else {
    534             // write out the total number of certs
    535             oos.writeInt(certs.length);
    536             // write out each cert, including its type
    537             for (int i=0; i < certs.length; i++) {
    538                 java.security.cert.Certificate cert = certs[i];
    539                 try {
    540                     oos.writeUTF(cert.getType());
    541                     byte[] encoded = cert.getEncoded();
    542                     oos.writeInt(encoded.length);
    543                     oos.write(encoded);
    544                 } catch (CertificateEncodingException cee) {
    545                     throw new IOException(cee.getMessage());
    546                 }
    547             }
    548         }
    549     }
    550
    551     /**
    552      * Restores this object from a stream (i.e., deserializes it).

    553      */
    554     @java.io.Serial
    555     private void readObject(java.io.ObjectInputStream ois)
    556         throws IOException, ClassNotFoundException
    557     {
    558         CertificateFactory cf;
    559         Hashtable<String, CertificateFactory> cfs = null;
    560         List<Certificate> certList = null;
    561
    562         ois.defaultReadObject();
    563
    564         if (type == null)
    565                 throw new NullPointerException("type can't be null");
    566
    567         // process any new-style certs in the stream (if present)
    568         int size = ois.readInt();
    569         if (size > 0) {
    570             // we know of 3 different cert types: X.509, PGP, SDSI, which
    571             // could all be present in the stream at the same time
    572             cfs = new Hashtable<>(3);
      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
    504
    505     public PermissionCollection newPermissionCollection() {
    506         return new UnresolvedPermissionCollection();
    507     }
    508
    509     /**
    510      * Writes this object out to a stream (i.e., serializes it).
    511      *
    512      * @serialData An initial {@code String} denoting the
    513      * {@code type} is followed by a {@code String} denoting the
    514      * {@code name} is followed by a {@code String} denoting the
    515      * {@code actions} is followed by an {@code int} indicating the
    516      * number of certificates to follow
    517      * (a value of "zero" denotes that there are no certificates associated
    518      * with this object).
    519      * Each certificate is written out starting with a {@code String}
    520      * denoting the certificate type, followed by an
    521      * {@code int} specifying the length of the certificate encoding,
    522      * followed by the certificate encoding itself which is written out as an
    523      * array of bytes.
    524      *
    525      * @param  oos the {@code ObjectOutputStream} to which data is written
    526      * @throws IOException if an I/O error occurs
    527      */
    528     @java.io.Serial
    529     private void writeObject(java.io.ObjectOutputStream oos)
    530         throws IOException
    531     {
    532         oos.defaultWriteObject();
    533
    534         if (certs==null || certs.length==0) {
    535             oos.writeInt(0);
    536         } else {
    537             // write out the total number of certs
    538             oos.writeInt(certs.length);
    539             // write out each cert, including its type
    540             for (int i=0; i < certs.length; i++) {
    541                 java.security.cert.Certificate cert = certs[i];
    542                 try {
    543                     oos.writeUTF(cert.getType());
    544                     byte[] encoded = cert.getEncoded();
    545                     oos.writeInt(encoded.length);
    546                     oos.write(encoded);
    547                 } catch (CertificateEncodingException cee) {
    548                     throw new IOException(cee.getMessage());
    549                 }
    550             }
    551         }
    552     }
    553
    554     /**
    555      * Restores this object from a stream (i.e., deserializes it).
    556      *
    557      * @param  ois the {@code ObjectInputStream} from which data is read
    558      * @throws IOException if an I/O error occurs
    559      * @throws ClassNotFoundException if a serialized class cannot be loaded
    560      */
    561     @java.io.Serial
    562     private void readObject(java.io.ObjectInputStream ois)
    563         throws IOException, ClassNotFoundException
    564     {
    565         CertificateFactory cf;
    566         Hashtable<String, CertificateFactory> cfs = null;
    567         List<Certificate> certList = null;
    568
    569         ois.defaultReadObject();
    570
    571         if (type == null)
    572                 throw new NullPointerException("type can't be null");
    573
    574         // process any new-style certs in the stream (if present)
    575         int size = ois.readInt();
    576         if (size > 0) {
    577             // we know of 3 different cert types: X.509, PGP, SDSI, which
    578             // could all be present in the stream at the same time
    579             cfs = new Hashtable<>(3);

< prev index next >