src/java.base/share/classes/java/security/UnresolvedPermission.java
author darcy
Thu, 29 Aug 2019 10:52:21 -0700
changeset 57950 4612a3cfb927
parent 47418 6993f9f1ff83
permissions -rw-r--r--
8229999: Apply java.io.Serial annotations to security types in java.base Reviewed-by: rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47418
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
47418
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
    28
import sun.security.util.IOUtils;
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
    29
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ByteArrayInputStream;
47418
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
    32
import java.security.cert.Certificate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.cert.*;
47418
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
    37
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The UnresolvedPermission class is used to hold Permissions that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * were "unresolved" when the Policy was initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * An unresolved permission is one whose actual Permission class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * does not yet exist at the time the Policy is initialized (see below).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>The policy for a Java runtime (specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * which permissions are available for code from various principals)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * is represented by a Policy object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Whenever a Policy is initialized or refreshed, Permission objects of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * appropriate classes are created for all permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * allowed by the Policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>Many permission class types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * referenced by the policy configuration are ones that exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * locally (i.e., ones that can be found on CLASSPATH).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Objects for such permissions can be instantiated during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Policy initialization. For example, it is always possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * to instantiate a java.io.FilePermission, since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * FilePermission class is found on the CLASSPATH.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>Other permission classes may not yet exist during Policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * initialization. For example, a referenced permission class may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * be in a JAR file that will later be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * For each such class, an UnresolvedPermission is instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Thus, an UnresolvedPermission is essentially a "placeholder"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * containing information about the permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>Later, when code calls AccessController.checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * on a permission of a type that was previously unresolved,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * but whose class has since been loaded, previously-unresolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * permissions of that type are "resolved". That is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * for each such UnresolvedPermission, a new object of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * the appropriate class type is instantiated, based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * information in the UnresolvedPermission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p> To instantiate the new class, UnresolvedPermission assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * the class provides a zero, one, and/or two-argument constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * The zero-argument constructor would be used to instantiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * a permission without a name and without actions.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    79
 * A one-arg constructor is assumed to take a {@code String}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * name as input, and a two-arg constructor is assumed to take a
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    81
 * {@code String} name and {@code String} actions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * as input.  UnresolvedPermission may invoke a
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    83
 * constructor with a {@code null} name and/or actions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * If an appropriate permission constructor is not available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * the UnresolvedPermission is ignored and the relevant permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * will not be granted to executing code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <p> The newly created permission object replaces the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * UnresolvedPermission, which is removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    91
 * <p> Note that the {@code getName} method for an
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    92
 * {@code UnresolvedPermission} returns the
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    93
 * {@code type} (class name) for the underlying permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * that has not been resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @see java.security.Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @see java.security.Permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * @see java.security.PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @see java.security.Policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * @author Roland Schemers
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 31538
diff changeset
   103
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
public final class UnresolvedPermission extends Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
implements java.io.Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47418
diff changeset
   110
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final long serialVersionUID = -4821973115467008846L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static final sun.security.util.Debug debug =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        sun.security.util.Debug.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        ("policy,access", "UnresolvedPermission");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * The class name of the Permission class that will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * created when this unresolved permission is resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * The permission name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * The actions of the permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private String actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   139
    private transient java.security.cert.Certificate[] certs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Creates a new UnresolvedPermission containing the permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * information needed later to actually create a Permission of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * specified class, when the permission is resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param type the class name of the Permission class that will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * created when this unresolved permission is resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param name the name of the permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param actions the actions of the permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param certs the certificates the permission's class was signed with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * This is a list of certificate chains, where each chain is composed of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * signer certificate and optionally its supporting certificate chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Each chain is ordered bottom-to-top (i.e., with the signer certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * first and the (root) certificate authority last). The signer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * certificates are copied from the array. Subsequent changes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * the array will not affect this UnsolvedPermission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public UnresolvedPermission(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                String actions,
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   161
                                java.security.cert.Certificate[] certs)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        super(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (type == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                throw new NullPointerException("type can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        this.actions = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (certs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            // Extract the signer certs from the list of certificates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            for (int i=0; i<certs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                if (!(certs[i] instanceof X509Certificate)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    // there is no concept of signer certs, so we store the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    // entire cert array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    this.certs = certs.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (this.certs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                // Go through the list of certs and see if all the certs are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                // signer certs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                while (i < certs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    while (((i+1) < certs.length) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                           ((X509Certificate)certs[i]).getIssuerDN().equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                               ((X509Certificate)certs[i+1]).getSubjectDN())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                if (count == certs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    // All the certs are signer certs, so we store the entire
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    // array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    this.certs = certs.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if (this.certs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    // extract the signer certs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    ArrayList<java.security.cert.Certificate> signerCerts =
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
   205
                        new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    while (i < certs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        signerCerts.add(certs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                        while (((i+1) < certs.length) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                            ((X509Certificate)certs[i]).getIssuerDN().equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                              ((X509Certificate)certs[i+1]).getSubjectDN())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    this.certs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        new java.security.cert.Certificate[signerCerts.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    signerCerts.toArray(this.certs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
22117
1efafbb25acb 8031302: Fix raw types lint warnings in java.security
darcy
parents: 21278
diff changeset
   225
    private static final Class<?>[] PARAMS0 = { };
1efafbb25acb 8031302: Fix raw types lint warnings in java.security
darcy
parents: 21278
diff changeset
   226
    private static final Class<?>[] PARAMS1 = { String.class };
1efafbb25acb 8031302: Fix raw types lint warnings in java.security
darcy
parents: 21278
diff changeset
   227
    private static final Class<?>[] PARAMS2 = { String.class, String.class };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * try and resolve this permission using the class loader of the permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * that was passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   233
    Permission resolve(Permission p, java.security.cert.Certificate[] certs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (this.certs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // if p wasn't signed, we don't have a match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (certs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            // all certs in this.certs must be present in certs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            boolean match;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            for (int i = 0; i < this.certs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                match = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                for (int j = 0; j < certs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    if (this.certs[i].equals(certs[j])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        match = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                if (!match) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   254
            Class<?> pc = p.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            if (name == null && actions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   258
                    Constructor<?> c = pc.getConstructor(PARAMS0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    return (Permission)c.newInstance(new Object[] {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                } catch (NoSuchMethodException ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   262
                        Constructor<?> c = pc.getConstructor(PARAMS1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        return (Permission) c.newInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                              new Object[] { name});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    } catch (NoSuchMethodException ne1) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   266
                        Constructor<?> c = pc.getConstructor(PARAMS2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                        return (Permission) c.newInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                              new Object[] { name, actions });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                if (name != null && actions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   274
                        Constructor<?> c = pc.getConstructor(PARAMS1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        return (Permission) c.newInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                              new Object[] { name});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    } catch (NoSuchMethodException ne) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   278
                        Constructor<?> c = pc.getConstructor(PARAMS2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        return (Permission) c.newInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                              new Object[] { name, actions });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                } else {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   283
                    Constructor<?> c = pc.getConstructor(PARAMS2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    return (Permission) c.newInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                          new Object[] { name, actions });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        } catch (NoSuchMethodException nsme) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            if (debug != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                debug.println("NoSuchMethodException:\n  could not find " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        "proper constructor for " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                nsme.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (debug != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                debug.println("unable to instantiate " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * This method always returns false for unresolved permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * That is, an UnresolvedPermission is never considered to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * imply another permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @param p the permission to check against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public boolean implies(Permission p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Checks two UnresolvedPermission objects for equality.
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   319
     * Checks that {@code obj} is an UnresolvedPermission, and has
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * the same type (class) name, permission name, actions, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * certificates as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * <p> To determine certificate equality, this method only compares
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * actual signer certificates.  Supporting certificate chains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * are not taken into consideration by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param obj the object we are testing for equality with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @return true if obj is an UnresolvedPermission, and has the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * type (class) name, permission name, actions, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * certificates as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (obj == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (! (obj instanceof UnresolvedPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        UnresolvedPermission that = (UnresolvedPermission) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        // check type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (!this.type.equals(that.type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // check name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (this.name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            if (that.name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        } else if (!this.name.equals(that.name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        // check actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (this.actions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (that.actions != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            if (!this.actions.equals(that.actions)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        // check certs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if ((this.certs == null && that.certs != null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            (this.certs != null && that.certs == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            (this.certs != null && that.certs != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                this.certs.length != that.certs.length)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        int i,j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        boolean match;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        for (i = 0; this.certs != null && i < this.certs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            match = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            for (j = 0; j < that.certs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                if (this.certs[i].equals(that.certs[j])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    match = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            if (!match) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        for (i = 0; that.certs != null && i < that.certs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            match = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            for (j = 0; j < this.certs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                if (that.certs[i].equals(this.certs[j])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    match = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            if (!match) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Returns the hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        int hash = type.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if (name != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            hash ^= name.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (actions != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            hash ^= actions.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * Returns the canonical string representation of the actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * which currently is the empty string "", since there are no actions for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * an UnresolvedPermission. That is, the actions for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * permission that will be created when this UnresolvedPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * is resolved may be non-null, but an UnresolvedPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * itself is never considered to have any actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @return the empty string "".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public String getActions()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Get the type (class name) of the underlying permission that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * has not been resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @return the type (class name) of the underlying permission that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *  has not been resolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public String getUnresolvedType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Get the target name of the underlying permission that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * has not been resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @return the target name of the underlying permission that
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   449
     *          has not been resolved, or {@code null},
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18579
diff changeset
   450
     *          if there is no target name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public String getUnresolvedName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Get the actions for the underlying permission that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * has not been resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @return the actions for the underlying permission that
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   463
     *          has not been resolved, or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *          if there are no actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public String getUnresolvedActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Get the signer certificates (without any supporting chain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * for the underlying permission that has not been resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @return the signer certificates for the underlying permission that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * has not been resolved, or null, if there are no signer certificates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Returns a new array each time this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public java.security.cert.Certificate[] getUnresolvedCerts() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return (certs == null) ? null : certs.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Returns a string describing this UnresolvedPermission.  The convention
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * is to specify the class name, the permission name, and the actions, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * the following format: '(unresolved "ClassName" "name" "actions")'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @return information about this UnresolvedPermission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return "(unresolved " + type + " " + name + " " + actions + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Returns a new PermissionCollection object for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * UnresolvedPermission  objects.
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   500
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @return a new PermissionCollection object suitable for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * storing UnresolvedPermissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public PermissionCollection newPermissionCollection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return new UnresolvedPermissionCollection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Writes this object out to a stream (i.e., serializes it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   512
     * @serialData An initial {@code String} denoting the
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   513
     * {@code type} is followed by a {@code String} denoting the
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   514
     * {@code name} is followed by a {@code String} denoting the
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   515
     * {@code actions} is followed by an {@code int} indicating the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * number of certificates to follow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * (a value of "zero" denotes that there are no certificates associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * with this object).
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   519
     * Each certificate is written out starting with a {@code String}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * denoting the certificate type, followed by an
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   521
     * {@code int} specifying the length of the certificate encoding,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * followed by the certificate encoding itself which is written out as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * array of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     */
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47418
diff changeset
   525
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    private void writeObject(java.io.ObjectOutputStream oos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        oos.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (certs==null || certs.length==0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            oos.writeInt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            // write out the total number of certs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            oos.writeInt(certs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            // write out each cert, including its type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            for (int i=0; i < certs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                java.security.cert.Certificate cert = certs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    oos.writeUTF(cert.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    byte[] encoded = cert.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    oos.writeInt(encoded.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    oos.write(encoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                } catch (CertificateEncodingException cee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    throw new IOException(cee.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * Restores this object from a stream (i.e., deserializes it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     */
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47418
diff changeset
   554
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    private void readObject(java.io.ObjectInputStream ois)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        CertificateFactory cf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        Hashtable<String, CertificateFactory> cfs = null;
47418
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   560
        List<Certificate> certList = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        ois.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (type == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                throw new NullPointerException("type can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        // process any new-style certs in the stream (if present)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        int size = ois.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if (size > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            // we know of 3 different cert types: X.509, PGP, SDSI, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            // could all be present in the stream at the same time
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 29492
diff changeset
   572
            cfs = new Hashtable<>(3);
47418
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   573
            certList = new ArrayList<>(size > 20 ? 20 : size);
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   574
        } else if (size < 0) {
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   575
            throw new IOException("size cannot be negative");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        for (int i=0; i<size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            // read the certificate type, and instantiate a certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            // factory of that type (reuse existing factory if possible)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            String certType = ois.readUTF();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            if (cfs.containsKey(certType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                // reuse certificate factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                cf = cfs.get(certType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                // create new certificate factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    cf = CertificateFactory.getInstance(certType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                } catch (CertificateException ce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    throw new ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        ("Certificate factory for "+certType+" not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                // store the certificate factory so we can reuse it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                cfs.put(certType, cf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            // parse the certificate
47418
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   597
            byte[] encoded = IOUtils.readNBytes(ois, ois.readInt());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            try {
47418
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   600
                certList.add(cf.generateCertificate(bais));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            } catch (CertificateException ce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                throw new IOException(ce.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            bais.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
47418
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   606
        if (certList != null) {
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   607
            this.certs = certList.toArray(
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   608
                    new java.security.cert.Certificate[size]);
6993f9f1ff83 8181432: Better processing of unresolved permissions
weijun
parents: 47216
diff changeset
   609
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
}