jdk/src/share/classes/javax/crypto/CryptoPermissions.java
author jjg
Mon, 15 Aug 2011 11:48:20 -0700
changeset 10336 0bb1999251f8
parent 5506 202f599c92aa
child 13557 f0156a32c08f
permissions -rw-r--r--
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror Reviewed-by: xuelei, mullan Contributed-by: alexandre.boulgakov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2011, 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.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.InputStreamReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This class contains CryptoPermission objects, organized into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * PermissionCollections according to algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>When the <code>add</code> method is called to add a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * CryptoPermission, the CryptoPermission is stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * appropriate PermissionCollection. If no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * collection exists yet, the algorithm name associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the CryptoPermission object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * determined and the <code>newPermissionCollection</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * is called on the CryptoPermission or CryptoAllPermission class to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * create the PermissionCollection and add it to the Permissions object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see javax.crypto.CryptoPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see java.security.PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see java.security.Permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author Sharon Liu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
final class CryptoPermissions extends PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final long serialVersionUID = 4946547168093391015L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // This class is similar to java.security.Permissions
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
    65
    private Hashtable<String, PermissionCollection> perms;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Creates a new CryptoPermissions object containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * no CryptoPermissionCollections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    CryptoPermissions() {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
    72
        perms = new Hashtable<String, PermissionCollection>(7);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Populates the crypto policy from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * InputStream into this CryptoPermissions object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param in the InputStream to load from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @exception SecurityException if cannot load
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * successfully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    void load(InputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        throws IOException, CryptoPolicyParser.ParsingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        CryptoPolicyParser parser = new CryptoPolicyParser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        parser.read(new BufferedReader(new InputStreamReader(in, "UTF-8")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        CryptoPermission[] parsingResult = parser.getPermissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        for (int i = 0; i < parsingResult.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            this.add(parsingResult[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
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
     * Returns true if this CryptoPermissions object doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * contain any CryptoPermission objects; otherwise, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return perms.isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Adds a permission object to the PermissionCollection for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * algorithm returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <code>(CryptoPermission)permission.getAlgorithm()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * This method creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * a new PermissionCollection object (and adds the permission to it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * if an appropriate collection does not yet exist. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param permission the Permission object to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @exception SecurityException if this CryptoPermissions object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * marked as readonly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see isReadOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public void add(Permission permission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (isReadOnly())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            throw new SecurityException("Attempt to add a Permission " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                        "to a readonly CryptoPermissions " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                        "object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (!(permission instanceof CryptoPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        CryptoPermission cryptoPerm = (CryptoPermission)permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        PermissionCollection pc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                        getPermissionCollection(cryptoPerm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        pc.add(cryptoPerm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        String alg = cryptoPerm.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (!perms.containsKey(alg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            perms.put(alg, pc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Checks if this object's PermissionCollection for permissons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * of the specified permission's algorithm implies the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * permission. Returns true if the checking succeeded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param permission the Permission object to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @return true if "permission" is implied by the permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * in the PermissionCollection it belongs to, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public boolean implies(Permission permission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (!(permission instanceof CryptoPermission)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        CryptoPermission cryptoPerm = (CryptoPermission)permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        PermissionCollection pc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            getPermissionCollection(cryptoPerm.getAlgorithm());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return pc.implies(cryptoPerm);
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 an enumeration of all the Permission objects in all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * PermissionCollections in this CryptoPermissions object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @return an enumeration of all the Permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   169
    public Enumeration<Permission> elements() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        // go through each Permissions in the hash table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        // and call their elements() function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return new PermissionsEnumerator(perms.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Returns a CryptoPermissions object which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * represents the minimum of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * CryptoPermissions object and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * CryptoPermissions object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param other the CryptoPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * object to compare with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    CryptoPermissions getMinimum(CryptoPermissions other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (other == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (this.perms.containsKey(CryptoAllPermission.ALG_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (other.perms.containsKey(CryptoAllPermission.ALG_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        CryptoPermissions ret = new CryptoPermissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        PermissionCollection thatWildcard =
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   201
                other.perms.get(CryptoPermission.ALG_NAME_WILDCARD);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        int maxKeySize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (thatWildcard != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            maxKeySize = ((CryptoPermission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    thatWildcard.elements().nextElement()).getMaxKeySize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // For each algorithm in this CryptoPermissions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // find out if there is anything we should add into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // ret.
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   210
        Enumeration<String> thisKeys = this.perms.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        while (thisKeys.hasMoreElements()) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   212
            String alg = thisKeys.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   214
            PermissionCollection thisPc = this.perms.get(alg);
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   215
            PermissionCollection thatPc = other.perms.get(alg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            CryptoPermission[] partialResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if (thatPc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                if (thatWildcard == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    // The other CryptoPermissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    // doesn't allow this given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    // algorithm at all. Just skip this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    // algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                partialResult = getMinimum(maxKeySize, thisPc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                partialResult = getMinimum(thisPc, thatPc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            for (int i = 0; i < partialResult.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                ret.add(partialResult[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        PermissionCollection thisWildcard =
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   238
                this.perms.get(CryptoPermission.ALG_NAME_WILDCARD);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        // If this CryptoPermissions doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        // have a wildcard, we are done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (thisWildcard == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        // Deal with the algorithms only appear
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // in the other CryptoPermissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        maxKeySize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            ((CryptoPermission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    thisWildcard.elements().nextElement()).getMaxKeySize();
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   251
        Enumeration<String> thatKeys = other.perms.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        while (thatKeys.hasMoreElements()) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   253
            String alg = thatKeys.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            if (this.perms.containsKey(alg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   259
            PermissionCollection thatPc = other.perms.get(alg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            CryptoPermission[] partialResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            partialResult = getMinimum(maxKeySize, thatPc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            for (int i = 0; i < partialResult.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                ret.add(partialResult[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Get the minimum of the two given PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <code>thisPc</code> and <code>thatPc</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param thisPc the first given PermissionColloection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param thatPc the second given PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private CryptoPermission[] getMinimum(PermissionCollection thisPc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                          PermissionCollection thatPc) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   284
        Vector<CryptoPermission> permVector = new Vector<>(2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   286
        Enumeration<Permission> thisPcPermissions = thisPc.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // For each CryptoPermission in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // thisPc object, do the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // 1) if this CryptoPermission is implied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        //     by thatPc, this CryptoPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        //     should be returned, and we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        //     move on to check the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        //     CryptoPermission in thisPc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        // 2) otherwise, we should return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        //     all CryptoPermissions in thatPc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        //     which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        //     are implied by this CryptoPermission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        //     Then we can move on to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        //     next CryptoPermission in thisPc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        while (thisPcPermissions.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            CryptoPermission thisCp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                (CryptoPermission)thisPcPermissions.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   305
            Enumeration<Permission> thatPcPermissions = thatPc.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            while (thatPcPermissions.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                CryptoPermission thatCp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    (CryptoPermission)thatPcPermissions.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                if (thatCp.implies(thisCp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    permVector.addElement(thisCp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                if (thisCp.implies(thatCp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    permVector.addElement(thatCp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        CryptoPermission[] ret = new CryptoPermission[permVector.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        permVector.copyInto(ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Returns all the CryptoPermission objects in the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * PermissionCollection object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * whose maximum keysize no greater than <code>maxKeySize</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * For all CryptoPermission objects with a maximum keysize greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * than <code>maxKeySize</code>, this method constructs a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * corresponding CryptoPermission object whose maximum keysize is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * set to <code>maxKeySize</code>, and includes that in the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param maxKeySize the given maximum key size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param pc the given PermissionCollection object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    private CryptoPermission[] getMinimum(int maxKeySize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                          PermissionCollection pc) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   340
        Vector<CryptoPermission> permVector = new Vector<>(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   342
        Enumeration<Permission> enum_ = pc.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        while (enum_.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            CryptoPermission cp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                (CryptoPermission)enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if (cp.getMaxKeySize() <= maxKeySize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                permVector.addElement(cp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                if (cp.getCheckParam()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    permVector.addElement(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                           new CryptoPermission(cp.getAlgorithm(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                                maxKeySize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                                cp.getAlgorithmParameterSpec(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                                cp.getExemptionMechanism()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    permVector.addElement(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                           new CryptoPermission(cp.getAlgorithm(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                                                maxKeySize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                                                cp.getExemptionMechanism()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        CryptoPermission[] ret = new CryptoPermission[permVector.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        permVector.copyInto(ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Returns the PermissionCollection for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * specified algorithm. Returns null if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * isn't such a PermissionCollection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @param alg the algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    PermissionCollection getPermissionCollection(String alg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // If this CryptoPermissions includes CryptoAllPermission,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        // we should return CryptoAllPermission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (perms.containsKey(CryptoAllPermission.ALG_NAME)) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   381
            return perms.get(CryptoAllPermission.ALG_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   384
        PermissionCollection pc = perms.get(alg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        // If there isn't a PermissionCollection for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        // the given algorithm,we should return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        // PermissionCollection for the wildcard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // if there is one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (pc == null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   391
            pc = perms.get(CryptoPermission.ALG_NAME_WILDCARD);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Returns the PermissionCollection for the algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * associated with the specified CryptoPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * object. Creates such a PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * if such a PermissionCollection does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * exist yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @param cryptoPerm the CryptoPermission object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    private PermissionCollection getPermissionCollection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                          CryptoPermission cryptoPerm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        String alg = cryptoPerm.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   410
        PermissionCollection pc = perms.get(alg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (pc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            pc = cryptoPerm.newPermissionCollection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   419
final class PermissionsEnumerator implements Enumeration<Permission> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    // all the perms
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   422
    private Enumeration<PermissionCollection> perms;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    // the current set
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   424
    private Enumeration<Permission> permset;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   426
    PermissionsEnumerator(Enumeration<PermissionCollection> e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        perms = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        permset = getNextEnumWithMore();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public synchronized boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        // if we enter with permissionimpl null, we know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // there are no more left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (permset == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            return  false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        // try to see if there are any left in the current one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (permset.hasMoreElements())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        // get the next one that has something in it...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        permset = getNextEnumWithMore();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        // if it is null, we are done!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return (permset != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   450
    public synchronized Permission nextElement() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        // hasMoreElements will update permset to the next permset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        // with something in it...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            return permset.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            throw new NoSuchElementException("PermissionsEnumerator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   462
    private Enumeration<Permission> getNextEnumWithMore() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        while (perms.hasMoreElements()) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   464
            PermissionCollection pc = perms.nextElement();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   465
            Enumeration<Permission> next = pc.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            if (next.hasMoreElements())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
}