src/java.base/share/classes/java/security/AllPermission.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58659 4113f16d5109
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
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.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The AllPermission is a permission that implies all other permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <b>Note:</b> Granting AllPermission should be done with extreme care,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * as it implies all other permissions. Thus, it grants code the ability
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * to run with security
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * disabled.  Extreme caution should be taken before granting such
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * a permission to code.  This permission should be used only during testing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * or in extremely rare cases where an application or applet is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * completely trusted and adding the necessary permissions to the policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * is prohibitively cumbersome.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @see java.security.Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @see java.security.AccessController
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see java.security.Permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see java.security.PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see java.lang.SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Roland Schemers
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 30033
diff changeset
    54
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @serial exclude
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public final class AllPermission extends Permission {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
    61
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final long serialVersionUID = -2916474571451318075L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Creates a new AllPermission object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
    67
    public AllPermission() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        super("<all permissions>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Creates a new AllPermission object. This
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 14342
diff changeset
    74
     * constructor exists for use by the {@code Policy} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * to instantiate new Permission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param name ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param actions ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
    80
    public AllPermission(String name, String actions) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Checks if the specified permission is "implied" by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * this object. This method always returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param p the permission to check against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @return return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public boolean implies(Permission p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Checks two AllPermission objects for equality. Two AllPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * objects are always equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param obj the object we are testing for equality with this object.
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   101
     * @return true if {@code obj} is an AllPermission, false otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return (obj instanceof AllPermission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Returns the hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the canonical string representation of the actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @return the actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
   122
    public String getActions() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return "<all actions>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Returns a new PermissionCollection object for storing AllPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @return a new PermissionCollection object suitable for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * storing AllPermissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public PermissionCollection newPermissionCollection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return new AllPermissionCollection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * A AllPermissionCollection stores a collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * of AllPermission permissions. AllPermission objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * must be stored in a manner that allows them to be inserted in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * order, but enable the implies function to evaluate the implies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * method in an efficient (and consistent) manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * @see java.security.Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * @see java.security.Permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * @author Roland Schemers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * @serial include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
final class AllPermissionCollection
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
   156
    extends PermissionCollection
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
   157
    implements java.io.Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    // use serialVersionUID from JDK 1.2.2 for interoperability
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
   161
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private static final long serialVersionUID = -4023755556366636806L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private boolean all_allowed; // true if any all permissions have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Create an empty AllPermissions object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public AllPermissionCollection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        all_allowed = false;
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
     * Adds a permission to the AllPermissions. The key for the hash is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * permission.path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param permission the Permission object to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
58659
4113f16d5109 8231859: Extra dash after the exception name in @throws clause of javadoc
igerasim
parents: 58242
diff changeset
   181
     * @throws    IllegalArgumentException   if the permission is not an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *                                       AllPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
58659
4113f16d5109 8231859: Extra dash after the exception name in @throws clause of javadoc
igerasim
parents: 58242
diff changeset
   184
     * @throws    SecurityException   if this AllPermissionCollection object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *                                has been marked readonly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
   188
    public void add(Permission permission) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (! (permission instanceof AllPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new IllegalArgumentException("invalid permission: "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                               permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (isReadOnly())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        all_allowed = true; // No sync; staleness OK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Check and see if this set of permissions implies the permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * expressed in "permission".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
   202
     * @param permission the Permission object to compare
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return always returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
   207
    public boolean implies(Permission permission) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return all_allowed; // No sync; staleness OK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Returns an enumeration of all the AllPermission objects in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return an enumeration of all the AllPermission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
   217
    public Enumeration<Permission> elements() {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 29492
diff changeset
   218
        return new Enumeration<>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            private boolean hasMore = all_allowed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            public boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                return hasMore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            public Permission nextElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                hasMore = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                return SecurityConstants.ALL_PERMISSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
}