src/java.base/share/classes/java/security/Policy.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58659 4113f16d5109
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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: 53018
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: 5183
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: 5183
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: 5183
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5183
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5183
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.WeakHashMap;
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
    31
import java.util.Objects;
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
    32
import sun.security.jca.GetInstance;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * A Policy object is responsible for determining whether code executing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * in the Java runtime environment has permission to perform a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * security-sensitive operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p> There is only one Policy object installed in the runtime at any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * given time.  A Policy object can be installed by calling the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
    44
 * {@code setPolicy} method.  The installed Policy object can be
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
    45
 * obtained by calling the {@code getPolicy} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p> If no Policy object has been installed in the runtime, a call to
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
    48
 * {@code getPolicy} installs an instance of the default Policy
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * implementation (a default subclass implementation of this abstract class).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The default Policy implementation can be changed by setting the value
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 11034
diff changeset
    51
 * of the {@code policy.provider} security property to the fully qualified
30444
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
    52
 * name of the desired Policy subclass implementation. The system class loader
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
    53
 * is used to load this class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p> Application code can directly subclass Policy to provide a custom
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * implementation.  In addition, an instance of a Policy object can be
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
    57
 * constructed by invoking one of the {@code getInstance} factory methods
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * with a standard type.  The default policy type is "JavaPolicy".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p> Once a Policy instance has been installed (either by default, or by
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
    61
 * calling {@code setPolicy}), the Java runtime invokes its
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
    62
 * {@code implies} method when it needs to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * determine whether executing code (encapsulated in a ProtectionDomain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * can perform SecurityManager-protected operations.  How a Policy object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * retrieves its policy data is up to the Policy implementation itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * The policy data may be stored, for example, in a flat ASCII file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * in a serialized binary file of the Policy class, or in a database.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
    69
 * <p> The {@code refresh} method causes the policy object to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * refresh/reload its data.  This operation is implementation-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * For example, if the policy object stores its data in configuration files,
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
    72
 * calling {@code refresh} will cause it to re-read the configuration
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * policy files.  If a refresh operation is not supported, this method does
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * nothing.  Note that refreshed policy may not have an effect on classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * in a particular ProtectionDomain. This is dependent on the Policy
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
    76
 * provider's implementation of the {@code implies}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * method and its PermissionCollection caching strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @author Roland Schemers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @author Gary Ellison
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 45118
diff changeset
    81
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see java.security.ProtectionDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @see java.security.Permission
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 11034
diff changeset
    85
 * @see java.security.Security security properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
public abstract class Policy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * A read-only empty PermissionCollection instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static final PermissionCollection UNSUPPORTED_EMPTY_COLLECTION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        new UnsupportedEmptyCollection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
    97
    // Information about the system-wide policy.
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
    98
    private static class PolicyInfo {
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
    99
        // the system-wide policy
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   100
        final Policy policy;
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   101
        // a flag indicating if the system-wide policy has been initialized
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   102
        final boolean initialized;
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   103
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   104
        PolicyInfo(Policy policy, boolean initialized) {
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   105
            this.policy = policy;
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   106
            this.initialized = initialized;
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   107
        }
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   108
    }
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   109
42951
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   110
    // PolicyInfo is volatile since we apply DCL during initialization.
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   111
    // For correctness, care must be taken to read the field only once and only
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   112
    // write to it after any other initialization action has taken place.
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   113
    private static volatile PolicyInfo policyInfo = new PolicyInfo(null, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static final Debug debug = Debug.getInstance("policy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
30444
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   117
    // Default policy provider
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   118
    private static final String DEFAULT_POLICY =
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   119
        "sun.security.provider.PolicyFile";
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   120
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   121
    // Cache mapping ProtectionDomain.Key to PermissionCollection
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   122
    private WeakHashMap<ProtectionDomain.Key, PermissionCollection> pdMapping;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   124
    /** package private for AccessControlContext and ProtectionDomain */
42951
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   125
    static boolean isSet() {
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   126
        PolicyInfo pi = policyInfo;
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   127
        return pi.policy != null && pi.initialized == true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private static void checkPermission(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            sm.checkPermission(new SecurityPermission("createPolicy." + type));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Returns the installed Policy object. This value should not be cached,
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   139
     * as it may be changed by a call to {@code setPolicy}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * This method first calls
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   141
     * {@code SecurityManager.checkPermission} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   142
     * {@code SecurityPermission("getPolicy")} permission
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   143
     * to ensure it's ok to get the Policy object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return the installed Policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *        if a security manager exists and its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   149
     *        {@code checkPermission} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *        getting the Policy object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see SecurityManager#checkPermission(Permission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see #setPolicy(java.security.Policy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public static Policy getPolicy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (sm != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            sm.checkPermission(SecurityConstants.GET_POLICY_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return getPolicyNoCheck();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Returns the installed Policy object, skipping the security check.
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   165
     * Used by ProtectionDomain and getPolicy.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @return the installed Policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   169
    static Policy getPolicyNoCheck()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    {
42951
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   171
        PolicyInfo pi = policyInfo;
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   172
        // Use double-check idiom to avoid locking if system-wide policy is
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   173
        // already initialized
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   174
        if (pi.initialized == false || pi.policy == null) {
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   175
            synchronized (Policy.class) {
42951
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   176
                pi = policyInfo;
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   177
                if (pi.policy == null) {
30444
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   178
                    return loadPolicyProvider();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   182
        return pi.policy;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
30444
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   186
     * Loads and instantiates a Policy implementation specified by the
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   187
     * policy.provider security property. Note that this method should only
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   188
     * be called by getPolicyNoCheck and from within a synchronized block with
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   189
     * an intrinsic lock on the Policy.class.
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   190
     */
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   191
    private static Policy loadPolicyProvider() {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   192
        String policyProvider =
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   193
            AccessController.doPrivileged(new PrivilegedAction<>() {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   194
                @Override
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   195
                public String run() {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   196
                    return Security.getProperty("policy.provider");
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   197
                }
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   198
            });
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   199
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   200
        /*
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   201
         * If policy.provider is not set or is set to the default provider,
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   202
         * simply instantiate it and return.
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   203
         */
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   204
        if (policyProvider == null || policyProvider.isEmpty() ||
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   205
            policyProvider.equals(DEFAULT_POLICY))
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   206
        {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   207
            Policy polFile = new sun.security.provider.PolicyFile();
42951
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   208
            policyInfo = new PolicyInfo(polFile, true);
30444
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   209
            return polFile;
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   210
        }
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   211
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   212
        /*
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   213
         * Locate, load, and instantiate the policy.provider impl using
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   214
         * the system class loader. While doing so, install the bootstrap
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   215
         * provider to avoid potential recursion.
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   216
         */
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   217
        Policy polFile = new sun.security.provider.PolicyFile();
42951
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   218
        policyInfo = new PolicyInfo(polFile, false);
30444
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   219
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   220
        Policy pol = AccessController.doPrivileged(new PrivilegedAction<>() {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   221
            @Override
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   222
            public Policy run() {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   223
                try {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   224
                    ClassLoader scl = ClassLoader.getSystemClassLoader();
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37348
diff changeset
   225
                    @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37348
diff changeset
   226
                    Object o = Class.forName(policyProvider, true, scl).newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37348
diff changeset
   227
                    return (Policy)o;
30444
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   228
                } catch (Exception e) {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   229
                    if (debug != null) {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   230
                        debug.println("policy provider " + policyProvider +
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   231
                                      " not available");
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   232
                        e.printStackTrace();
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   233
                    }
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   234
                    return null;
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   235
                }
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   236
            }
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   237
        });
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   238
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   239
        if (pol == null) {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   240
            // Fallback and use the system default implementation
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   241
            if (debug != null) {
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   242
                debug.println("using " + DEFAULT_POLICY);
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   243
            }
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   244
            pol = polFile;
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   245
        }
42951
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   246
        policyInfo = new PolicyInfo(pol, true);
30444
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   247
        return pol;
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   248
    }
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   249
054604aed79c 8075706: Policy implementation does not allow policy.provider to be on the class path
mullan
parents: 30033
diff changeset
   250
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Sets the system-wide Policy object. This method first calls
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   252
     * {@code SecurityManager.checkPermission} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   253
     * {@code SecurityPermission("setPolicy")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * permission to ensure it's ok to set the Policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param p the new system Policy object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *        if a security manager exists and its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   260
     *        {@code checkPermission} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *        setting the Policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @see SecurityManager#checkPermission(Permission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see #getPolicy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public static void setPolicy(Policy p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (sm != null) sm.checkPermission(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                 new SecurityPermission("setPolicy"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            initPolicy(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        synchronized (Policy.class) {
42951
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   276
            policyInfo = new PolicyInfo(p, p != null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Initialize superclass state such that a legacy provider can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * handle queries for itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private static void initPolicy (final Policy p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         * A policy provider not on the bootclasspath could trigger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         * security checks fulfilling a call to either Policy.implies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         * or Policy.getPermissions. If this does occur the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         * must be able to answer for it's own ProtectionDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         * without triggering additional security checks, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         * the policy implementation will end up in an infinite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         * recursion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         * To mitigate this, the provider can collect it's own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         * ProtectionDomain and associate a PermissionCollection while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * it is being installed. The currently installed policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * provider (if there is one) will handle calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         * Policy.implies or Policy.getPermissions during this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
         * process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
         * This Policy superclass caches away the ProtectionDomain and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
         * statically binds permissions so that legacy Policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
         * implementations will continue to function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        ProtectionDomain policyDomain =
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   309
        AccessController.doPrivileged(new PrivilegedAction<>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            public ProtectionDomain run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                return p.getClass().getProtectionDomain();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         * Collect the permissions granted to this protection domain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         * so that the provider can be security checked while processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
         * calls to Policy.implies or Policy.getPermissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        PermissionCollection policyPerms = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        synchronized (p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (p.pdMapping == null) {
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   323
                p.pdMapping = new WeakHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (policyDomain.getCodeSource() != null) {
42951
fb59ca170643 8172048: Re-examine use of AtomicReference in java.security.Policy
redestad
parents: 41826
diff changeset
   328
            Policy pol = policyInfo.policy;
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   329
            if (pol != null) {
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   330
                policyPerms = pol.getPermissions(policyDomain);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            if (policyPerms == null) { // assume it has all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                policyPerms = new Permissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                policyPerms.add(SecurityConstants.ALL_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            synchronized (p.pdMapping) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                // cache of pd to permissions
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   340
                p.pdMapping.put(policyDomain.key, policyPerms);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Returns a Policy object of the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * <p> This method traverses the list of registered security providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * A new Policy object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * PolicySpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Provider that supports the specified type is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 30444
diff changeset
   359
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 30444
diff changeset
   360
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   361
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   362
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 30444
diff changeset
   363
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 30444
diff changeset
   364
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 30444
diff changeset
   365
     * {@link Security#getProviders() Security.getProviders()}.
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 30444
diff changeset
   366
     *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   367
     * @param type the specified Policy type.  See the Policy section in the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   368
     *    <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42951
diff changeset
   369
     *    "{@docRoot}/../specs/security/standard-names.html#policy-types">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42951
diff changeset
   370
     *    Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *    for a list of standard Policy types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param params parameters for the Policy, which may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   375
     * @return the new {@code Policy} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   377
     * @throws IllegalArgumentException if the specified parameters
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   378
     *         are not understood by the {@code PolicySpi} implementation
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   379
     *         from the selected {@code Provider}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   381
     * @throws NoSuchAlgorithmException if no {@code Provider} supports
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   382
     *         a {@code PolicySpi} implementation for the specified type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   384
     * @throws NullPointerException if {@code type} is {@code null}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   385
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   386
     * @throws SecurityException if the caller does not have permission
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   387
     *         to get a {@code Policy} instance for the specified type.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public static Policy getInstance(String type, Policy.Parameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                throws NoSuchAlgorithmException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   394
        Objects.requireNonNull(type, "null type name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        checkPermission(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            GetInstance.Instance instance = GetInstance.getInstance("Policy",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                                        PolicySpi.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                                        params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return new PolicyDelegate((PolicySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                                        instance.provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                                                        params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return handleException(nsae);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Returns a Policy object of the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <p> A new Policy object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * PolicySpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * is returned.   The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   421
     * @param type the specified Policy type.  See the Policy section in the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   422
     *    <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42951
diff changeset
   423
     *    "{@docRoot}/../specs/security/standard-names.html#policy-types">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42951
diff changeset
   424
     *    Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *    for a list of standard Policy types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @param params parameters for the Policy, which may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   431
     * @return the new {@code Policy} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   433
     * @throws IllegalArgumentException if the specified provider
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   434
     *         is {@code null} or empty, or if the specified parameters are
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   435
     *         not understood by the {@code PolicySpi} implementation from
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   436
     *         the specified provider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   438
     * @throws NoSuchAlgorithmException if the specified provider does not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   439
     *         support a {@code PolicySpi} implementation for the specified
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   440
     *         type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   442
     * @throws NoSuchProviderException if the specified provider is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   443
     *         registered in the security provider list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   445
     * @throws NullPointerException if {@code type} is {@code null}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   446
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   447
     * @throws SecurityException if the caller does not have permission
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   448
     *         to get a {@code Policy} instance for the specified type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public static Policy getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                                Policy.Parameters params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                                String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                throws NoSuchProviderException, NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   458
        Objects.requireNonNull(type, "null type name");
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   459
        if (provider == null || provider.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        checkPermission(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            GetInstance.Instance instance = GetInstance.getInstance("Policy",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                                        PolicySpi.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                                        params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                        provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            return new PolicyDelegate((PolicySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                                        instance.provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                                                        params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        } catch (NoSuchAlgorithmException nsae) {
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   475
            return handleException(nsae);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * Returns a Policy object of the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * <p> A new Policy object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * PolicySpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   487
     * @param type the specified Policy type.  See the Policy section in the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   488
     *    <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42951
diff changeset
   489
     *    "{@docRoot}/../specs/security/standard-names.html#policy-types">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 42951
diff changeset
   490
     *    Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *    for a list of standard Policy types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @param params parameters for the Policy, which may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @param provider the Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   497
     * @return the new {@code Policy} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   499
     * @throws IllegalArgumentException if the specified {@code Provider}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   500
     *         is {@code null}, or if the specified parameters are not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   501
     *         understood by the {@code PolicySpi} implementation from the
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   502
     *         specified {@code Provider}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   504
     * @throws NoSuchAlgorithmException if the specified {@code Provider}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   505
     *         does not support a {@code PolicySpi} implementation for
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   506
     *         the specified type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   508
     * @throws NullPointerException if {@code type} is {@code null}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   509
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   510
     * @throws SecurityException if the caller does not have permission
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   511
     *         to get a {@code Policy} instance for the specified type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public static Policy getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                Policy.Parameters params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                Provider provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37782
diff changeset
   521
        Objects.requireNonNull(type, "null type name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (provider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        checkPermission(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            GetInstance.Instance instance = GetInstance.getInstance("Policy",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                                        PolicySpi.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                                        params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                                                        provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            return new PolicyDelegate((PolicySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                                                        instance.provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                                        params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        } catch (NoSuchAlgorithmException nsae) {
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   538
            return handleException(nsae);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    private static Policy handleException(NoSuchAlgorithmException nsae)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        Throwable cause = nsae.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if (cause instanceof IllegalArgumentException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            throw (IllegalArgumentException)cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        throw nsae;
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
     * Return the Provider of this Policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * <p> This Policy instance will only have a Provider if it
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   555
     * was obtained via a call to {@code Policy.getInstance}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * Otherwise this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @return the Provider of this Policy, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    public Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * Return the type of this Policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * <p> This Policy instance will only have a type if it
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   570
     * was obtained via a call to {@code Policy.getInstance}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * Otherwise this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @return the type of this Policy, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    public String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Return Policy parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * <p> This Policy instance will only have parameters if it
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   585
     * was obtained via a call to {@code Policy.getInstance}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * Otherwise this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @return Policy parameters, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    public Policy.Parameters getParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * Return a PermissionCollection object containing the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * permissions granted to the specified CodeSource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * <p> Applications are discouraged from calling this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * since this operation may not be supported by all policy implementations.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   602
     * Applications should solely rely on the {@code implies} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * to perform policy checks.  If an application absolutely must call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * a getPermissions method, it should call
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   605
     * {@code getPermissions(ProtectionDomain)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * <p> The default implementation of this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Policy.UNSUPPORTED_EMPTY_COLLECTION.  This method can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * overridden if the policy implementation can return a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * permissions granted to a CodeSource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @param codesource the CodeSource to which the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *          PermissionCollection has been granted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @return a set of permissions granted to the specified CodeSource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *          If this operation is supported, the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *          set of permissions must be a new mutable instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     *          and it must support heterogeneous Permission types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *          If this operation is not supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *          Policy.UNSUPPORTED_EMPTY_COLLECTION is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public PermissionCollection getPermissions(CodeSource codesource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return Policy.UNSUPPORTED_EMPTY_COLLECTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * Return a PermissionCollection object containing the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * permissions granted to the specified ProtectionDomain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * <p> Applications are discouraged from calling this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * since this operation may not be supported by all policy implementations.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   632
     * Applications should rely on the {@code implies} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * to perform policy checks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * <p> The default implementation of this method first retrieves
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   636
     * the permissions returned via {@code getPermissions(CodeSource)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * (the CodeSource is taken from the specified ProtectionDomain),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * as well as the permissions located inside the specified ProtectionDomain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * All of these permissions are then combined and returned in a new
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   640
     * PermissionCollection object.  If {@code getPermissions(CodeSource)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * returns Policy.UNSUPPORTED_EMPTY_COLLECTION, then this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * returns the permissions contained inside the specified ProtectionDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * in a new PermissionCollection object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * <p> This method can be overridden if the policy implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * supports returning a set of permissions granted to a ProtectionDomain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @param domain the ProtectionDomain to which the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *          PermissionCollection has been granted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @return a set of permissions granted to the specified ProtectionDomain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *          If this operation is supported, the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *          set of permissions must be a new mutable instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *          and it must support heterogeneous Permission types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *          If this operation is not supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *          Policy.UNSUPPORTED_EMPTY_COLLECTION is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public PermissionCollection getPermissions(ProtectionDomain domain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        PermissionCollection pc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        if (domain == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            return new Permissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        if (pdMapping == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            initPolicy(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        synchronized (pdMapping) {
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   671
            pc = pdMapping.get(domain.key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        if (pc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            Permissions perms = new Permissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            synchronized (pc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                for (Enumeration<Permission> e = pc.elements() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    perms.add(e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            return perms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        pc = getPermissions(domain.getCodeSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        if (pc == null || pc == UNSUPPORTED_EMPTY_COLLECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            pc = new Permissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        addStaticPerms(pc, domain.getPermissions());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * add static permissions to provided permission collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    private void addStaticPerms(PermissionCollection perms,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                                PermissionCollection statics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        if (statics != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            synchronized (statics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                Enumeration<Permission> e = statics.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    perms.add(e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Evaluates the global policy for the permissions granted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * the ProtectionDomain and tests whether the permission is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * granted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @param domain the ProtectionDomain to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @param permission the Permission object to be tested for implication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @return true if "permission" is a proper subset of a permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * granted to this ProtectionDomain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @see java.security.ProtectionDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    public boolean implies(ProtectionDomain domain, Permission permission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        PermissionCollection pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        if (pdMapping == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            initPolicy(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        synchronized (pdMapping) {
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   730
            pc = pdMapping.get(domain.key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        if (pc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            return pc.implies(permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        pc = getPermissions(domain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        if (pc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        synchronized (pdMapping) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            // cache it
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   744
            pdMapping.put(domain.key, pc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        return pc.implies(permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * Refreshes/reloads the policy configuration. The behavior of this method
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   752
     * depends on the implementation. For example, calling {@code refresh}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * on a file-based policy will cause the file to be re-read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * <p> The default implementation of this method does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * This method should be overridden if a refresh operation is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * by the policy implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    public void refresh() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * This subclass is returned by the getInstance calls.  All Policy calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * are delegated to the underlying PolicySpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    private static class PolicyDelegate extends Policy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        private PolicySpi spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        private Provider p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        private Policy.Parameters params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        private PolicyDelegate(PolicySpi spi, Provider p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                        String type, Policy.Parameters params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            this.spi = spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            this.p = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            this.params = params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   780
        @Override public String getType() { return type; }
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   781
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   782
        @Override public Policy.Parameters getParameters() { return params; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   784
        @Override public Provider getProvider() { return p; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   786
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        public PermissionCollection getPermissions(CodeSource codesource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            return spi.engineGetPermissions(codesource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   790
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        public PermissionCollection getPermissions(ProtectionDomain domain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            return spi.engineGetPermissions(domain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   794
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        public boolean implies(ProtectionDomain domain, Permission perm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            return spi.engineImplies(domain, perm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        }
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   798
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        public void refresh() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            spi.engineRefresh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * This represents a marker interface for Policy parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    public static interface Parameters { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * This class represents a read-only empty PermissionCollection object that
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   813
     * is returned from the {@code getPermissions(CodeSource)} and
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14775
diff changeset
   814
     * {@code getPermissions(ProtectionDomain)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * methods in the Policy class when those operations are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * supported by the Policy implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    private static class UnsupportedEmptyCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        extends PermissionCollection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 53018
diff changeset
   821
        @java.io.Serial
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   822
        private static final long serialVersionUID = -8492269157353014774L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   823
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        private Permissions perms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
         * Create a read-only empty PermissionCollection object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        public UnsupportedEmptyCollection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            this.perms = new Permissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            perms.setReadOnly();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
         * Adds a permission object to the current collection of permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
         * objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
         * @param permission the Permission object to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
         *
58659
4113f16d5109 8231859: Extra dash after the exception name in @throws clause of javadoc
igerasim
parents: 58242
diff changeset
   840
         * @throws    SecurityException   if this PermissionCollection object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
         *                                has been marked readonly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
         */
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   843
        @Override public void add(Permission permission) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            perms.add(permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
         * Checks to see if the specified permission is implied by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
         * collection of Permission objects held in this PermissionCollection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
         * @param permission the Permission object to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
         *
11034
6ec8b7a32dbc 7093090: Reduce synchronization in java.security.Policy.getPolicyNoCheck
mullan
parents: 10336
diff changeset
   853
         * @return true if "permission" is implied by the permissions in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         * the collection, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
         */
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   856
        @Override public boolean implies(Permission permission) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            return perms.implies(permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
         * Returns an enumeration of all the Permission objects in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
         * collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
         * @return an enumeration of all the Permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
         */
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2
diff changeset
   866
        @Override public Enumeration<Permission> elements() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            return perms.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
}