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