src/java.base/share/classes/javax/crypto/CryptoPermission.java
author darcy
Wed, 09 Oct 2019 09:57:41 -0700
changeset 58519 6e017b301287
parent 57950 4612a3cfb927
child 58679 9c3209ff7550
permissions -rw-r--r--
8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes Reviewed-by: mullan, chegar
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: 47216
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.crypto;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.spec.AlgorithmParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.crypto.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The CryptoPermission class extends the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * java.security.Permission class. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * CryptoPermission object is used to represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * the ability of an application/applet to use certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * algorithms with certain key sizes and other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * restrictions in certain environments. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @see java.security.Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Sharon Liu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
class CryptoPermission extends java.security.Permission {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
    52
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final long serialVersionUID = 8987399626114087514L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private String alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private int maxKeySize = Integer.MAX_VALUE; // no restriction on maxKeySize
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private String exemptionMechanism = null;
58519
6e017b301287 8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents: 57950
diff changeset
    58
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private AlgorithmParameterSpec algParamSpec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private boolean checkParam = false; // no restriction on param
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static final String ALG_NAME_WILDCARD = "*";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Constructor that takes an algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * This constructor implies that the given algorithm can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * used without any restrictions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param alg the algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    CryptoPermission(String alg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this.alg = alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Constructor that takes an algorithm name and a maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * key size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * This constructor implies that the given algorithm can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * used with a key size up to <code>maxKeySize</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param alg the algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param maxKeySize the maximum allowable key size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * specified in number of bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    CryptoPermission(String alg, int maxKeySize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        this.alg = alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        this.maxKeySize = maxKeySize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Constructor that takes an algorithm name, a maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * key size, and an AlgorithmParameterSpec object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * This constructor implies that the given algorithm can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * used with a key size up to <code>maxKeySize</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * parameters up to the limits set in <code>algParamSpec</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param alg the algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param maxKeySize the maximum allowable key size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * specified in number of bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param algParamSpec the limits for allowable algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    CryptoPermission(String alg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                     int maxKeySize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                     AlgorithmParameterSpec algParamSpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this.alg = alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        this.maxKeySize = maxKeySize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        this.checkParam = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.algParamSpec = algParamSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Constructor that takes an algorithm name and the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * an exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * This constructor implies that the given algorithm can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * used without any key size or algorithm parameter restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * provided that the specified exemption mechanism is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param alg the algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param exemptionMechanism the name of the exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    CryptoPermission(String alg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                     String exemptionMechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        this.alg = alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        this.exemptionMechanism = exemptionMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Constructor that takes an algorithm name, a maximum key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * size, and the name of an exemption mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * This constructor implies that the given algorithm can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * used with a key size up to <code>maxKeySize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * provided that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * specified exemption mechanism is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param alg the algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param maxKeySize the maximum allowable key size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * specified in number of bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @param exemptionMechanism the name of the exemption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    CryptoPermission(String alg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                     int maxKeySize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                     String exemptionMechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        this.alg = alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        this.exemptionMechanism = exemptionMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        this.maxKeySize = maxKeySize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Constructor that takes an algorithm name, a maximum key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * size, the name of an exemption mechanism, and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * AlgorithmParameterSpec object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * This constructor implies that the given algorithm can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * used with a key size up to <code>maxKeySize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * and algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * parameters up to the limits set in <code>algParamSpec</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * provided that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * the specified exemption mechanism is enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param alg the algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param maxKeySize the maximum allowable key size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * specified in number of bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param algParamSpec the limit for allowable algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *  parameter spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param exemptionMechanism the name of the exemption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    CryptoPermission(String alg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                     int maxKeySize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                     AlgorithmParameterSpec algParamSpec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                     String exemptionMechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this.alg = alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        this.exemptionMechanism = exemptionMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        this.maxKeySize = maxKeySize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        this.checkParam = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        this.algParamSpec = algParamSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Checks if the specified permission is "implied" by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <p>
44999
b1c62cd70983 8178014: CryptoPolicyParser's API comment contains < and > characters
wetmore
parents: 25859
diff changeset
   201
     * More specifically, this method returns true if:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <ul>
44999
b1c62cd70983 8178014: CryptoPolicyParser's API comment contains < and > characters
wetmore
parents: 25859
diff changeset
   203
     * <li> <i>p</i> is an instance of CryptoPermission, and</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <li> <i>p</i>'s algorithm name equals or (in the case of wildcards)
44999
b1c62cd70983 8178014: CryptoPolicyParser's API comment contains < and > characters
wetmore
parents: 25859
diff changeset
   205
     *       is implied by this permission's algorithm name, and</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * <li> <i>p</i>'s maximum allowable key size is less or
44999
b1c62cd70983 8178014: CryptoPolicyParser's API comment contains < and > characters
wetmore
parents: 25859
diff changeset
   207
     *       equal to this permission's maximum allowable key size, and</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * <li> <i>p</i>'s algorithm parameter spec equals or is
44999
b1c62cd70983 8178014: CryptoPolicyParser's API comment contains < and > characters
wetmore
parents: 25859
diff changeset
   209
     *        implied by this permission's algorithm parameter spec, and</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * <li> <i>p</i>'s exemptionMechanism equals or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *        is implied by this permission's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *        exemptionMechanism (a <code>null</code> exemption mechanism
44999
b1c62cd70983 8178014: CryptoPolicyParser's API comment contains < and > characters
wetmore
parents: 25859
diff changeset
   213
     *        implies any other exemption mechanism).</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param p the permission to check against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @return true if the specified permission is equal to or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * implied by this permission, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public boolean implies(Permission p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (!(p instanceof CryptoPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        CryptoPermission cp = (CryptoPermission)p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if ((!alg.equalsIgnoreCase(cp.alg)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            (!alg.equalsIgnoreCase(ALG_NAME_WILDCARD))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        // alg is the same as cp's alg or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        // alg is a wildcard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (cp.maxKeySize <= this.maxKeySize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // check algParamSpec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (!impliesParameterSpec(cp.checkParam, cp.algParamSpec)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            // check exemptionMechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (impliesExemptionMechanism(cp.exemptionMechanism)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Checks two CryptoPermission objects for equality. Checks that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <code>obj</code> is a CryptoPermission, and has the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * algorithm name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * exemption mechanism name, maximum allowable key size and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * algorithm parameter spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param obj the object to test for equality with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return true if <code>obj</code> is equal to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (obj == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (!(obj instanceof CryptoPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        CryptoPermission that = (CryptoPermission) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (!(alg.equalsIgnoreCase(that.alg)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            (maxKeySize != that.maxKeySize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (this.checkParam != that.checkParam) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return (equalObjects(this.exemptionMechanism,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                             that.exemptionMechanism) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                equalObjects(this.algParamSpec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                             that.algParamSpec));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Returns the hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        int retval = alg.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        retval ^= maxKeySize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (exemptionMechanism != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            retval ^= exemptionMechanism.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (checkParam) retval ^= 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (algParamSpec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            retval ^= algParamSpec.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * There is no action defined for a CryptoPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * onject.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public String getActions()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Returns a new PermissionCollection object for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * CryptoPermission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @return a new PermissionCollection object suitable for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * CryptoPermissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public PermissionCollection newPermissionCollection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return new CryptoPermissionCollection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Returns the algorithm name associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * this CryptoPermission object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Returns the exemption mechanism name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * associated with this CryptoPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    final String getExemptionMechanism() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return exemptionMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Returns the maximum allowable key size associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * with this CryptoPermission object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    final int getMaxKeySize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return maxKeySize;
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 true if there is a limitation on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * AlgorithmParameterSpec associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * CryptoPermission object and false if otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    final boolean getCheckParam() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return checkParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Returns the AlgorithmParameterSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * associated with this CryptoPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    final AlgorithmParameterSpec getAlgorithmParameterSpec() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return algParamSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Returns a string describing this CryptoPermission.  The convention is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * specify the class name, the algorithm name, the maximum allowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * key size, and the name of the exemption mechanism, in the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * format: '("ClassName" "algorithm" "keysize" "exemption_mechanism")'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @return information about this CryptoPermission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        StringBuilder buf = new StringBuilder(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        buf.append("(CryptoPermission " + alg + " " + maxKeySize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (algParamSpec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            if (algParamSpec instanceof RC2ParameterSpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                buf.append(" , effective " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    ((RC2ParameterSpec)algParamSpec).getEffectiveKeyBits());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            } else if (algParamSpec instanceof RC5ParameterSpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                buf.append(" , rounds " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    ((RC5ParameterSpec)algParamSpec).getRounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (exemptionMechanism != null) { // OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            buf.append(" " + exemptionMechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        buf.append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    private boolean impliesExemptionMechanism(String exemptionMechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if (this.exemptionMechanism == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if (exemptionMechanism == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (this.exemptionMechanism.equals(exemptionMechanism)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    private boolean impliesParameterSpec(boolean checkParam,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                         AlgorithmParameterSpec algParamSpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if ((this.checkParam) && checkParam) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (algParamSpec == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            } else if (this.algParamSpec == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if (this.algParamSpec.getClass() != algParamSpec.getClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            if (algParamSpec instanceof RC2ParameterSpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                if (((RC2ParameterSpec)algParamSpec).getEffectiveKeyBits() <=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    ((RC2ParameterSpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                     (this.algParamSpec)).getEffectiveKeyBits()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            if (algParamSpec instanceof RC5ParameterSpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                if (((RC5ParameterSpec)algParamSpec).getRounds() <=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    ((RC5ParameterSpec)this.algParamSpec).getRounds()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            if (algParamSpec instanceof PBEParameterSpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                if (((PBEParameterSpec)algParamSpec).getIterationCount() <=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    ((PBEParameterSpec)this.algParamSpec).getIterationCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            // For classes we don't know, the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            // may be the best try.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            if (this.algParamSpec.equals(algParamSpec)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        } else if (this.checkParam) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    private boolean equalObjects(Object obj1, Object obj2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (obj1 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return (obj2 == null ? true : false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return obj1.equals(obj2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 * A CryptoPermissionCollection stores a set of CryptoPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
 * permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
 * @see java.security.Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
 * @see java.security.Permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
 * @see java.security.PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
 * @author Sharon Liu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
final class CryptoPermissionCollection extends PermissionCollection
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10336
diff changeset
   476
    implements Serializable
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10336
diff changeset
   477
{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    private static final long serialVersionUID = -511215555898802763L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   480
    private Vector<Permission> permissions;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Creates an empty CryptoPermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    CryptoPermissionCollection() {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   487
        permissions = new Vector<Permission>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * Adds a permission to the CryptoPermissionCollection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @param permission the Permission object to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @exception SecurityException - if this CryptoPermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * object has been marked <i>readOnly</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10336
diff changeset
   498
    public void add(Permission permission) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        if (isReadOnly())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            throw new SecurityException("attempt to add a Permission " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                        "to a readonly PermissionCollection");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (!(permission instanceof CryptoPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        permissions.addElement(permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10336
diff changeset
   510
     * Check and see if this CryptoPermission object implies
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10336
diff changeset
   511
     * the given Permission object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10336
diff changeset
   513
     * @param permission the Permission object to compare
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @return true if the given permission  is implied by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * CryptoPermissionCollection, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    public boolean implies(Permission permission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (!(permission instanceof CryptoPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        CryptoPermission cp = (CryptoPermission)permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   524
        Enumeration<Permission> e = permissions.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            CryptoPermission x = (CryptoPermission) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            if (x.implies(cp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Returns an enumeration of all the CryptoPermission objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * in the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @return an enumeration of all the CryptoPermission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10336
diff changeset
   542
    public Enumeration<Permission> elements() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return permissions.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
}