author | igerasim |
Wed, 16 Oct 2019 18:47:11 -0700 | |
changeset 58659 | 4113f16d5109 |
parent 58242 | 94bb65cb37d3 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
2 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.security; |
|
27 |
||
28 |
import java.security.*; |
|
29 |
import java.util.Enumeration; |
|
30 |
import java.util.Hashtable; |
|
31 |
import java.util.StringTokenizer; |
|
32 |
import sun.security.util.SecurityConstants; |
|
33 |
||
34 |
/** |
|
35 |
* The AllPermission is a permission that implies all other permissions. |
|
36 |
* <p> |
|
37 |
* <b>Note:</b> Granting AllPermission should be done with extreme care, |
|
38 |
* as it implies all other permissions. Thus, it grants code the ability |
|
39 |
* to run with security |
|
40 |
* disabled. Extreme caution should be taken before granting such |
|
41 |
* a permission to code. This permission should be used only during testing, |
|
42 |
* or in extremely rare cases where an application or applet is |
|
43 |
* completely trusted and adding the necessary permissions to the policy |
|
44 |
* is prohibitively cumbersome. |
|
45 |
* |
|
46 |
* @see java.security.Permission |
|
47 |
* @see java.security.AccessController |
|
48 |
* @see java.security.Permissions |
|
49 |
* @see java.security.PermissionCollection |
|
50 |
* @see java.lang.SecurityManager |
|
51 |
* |
|
52 |
* |
|
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 | 55 |
* |
56 |
* @serial exclude |
|
57 |
*/ |
|
58 |
||
59 |
public final class AllPermission extends Permission { |
|
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 | 62 |
private static final long serialVersionUID = -2916474571451318075L; |
63 |
||
64 |
/** |
|
65 |
* Creates a new AllPermission object. |
|
66 |
*/ |
|
14014 | 67 |
public AllPermission() { |
2 | 68 |
super("<all permissions>"); |
69 |
} |
|
70 |
||
71 |
||
72 |
/** |
|
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 | 75 |
* to instantiate new Permission objects. |
76 |
* |
|
77 |
* @param name ignored |
|
78 |
* @param actions ignored. |
|
79 |
*/ |
|
14014 | 80 |
public AllPermission(String name, String actions) { |
2 | 81 |
this(); |
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Checks if the specified permission is "implied" by |
|
86 |
* this object. This method always returns true. |
|
87 |
* |
|
88 |
* @param p the permission to check against. |
|
89 |
* |
|
90 |
* @return return |
|
91 |
*/ |
|
92 |
public boolean implies(Permission p) { |
|
93 |
return true; |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* Checks two AllPermission objects for equality. Two AllPermission |
|
98 |
* objects are always equal. |
|
99 |
* |
|
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 | 102 |
*/ |
103 |
public boolean equals(Object obj) { |
|
104 |
return (obj instanceof AllPermission); |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Returns the hash code value for this object. |
|
109 |
* |
|
110 |
* @return a hash code value for this object. |
|
111 |
*/ |
|
112 |
||
113 |
public int hashCode() { |
|
114 |
return 1; |
|
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* Returns the canonical string representation of the actions. |
|
119 |
* |
|
120 |
* @return the actions. |
|
121 |
*/ |
|
14014 | 122 |
public String getActions() { |
2 | 123 |
return "<all actions>"; |
124 |
} |
|
125 |
||
126 |
/** |
|
127 |
* Returns a new PermissionCollection object for storing AllPermission |
|
128 |
* objects. |
|
129 |
* |
|
130 |
* @return a new PermissionCollection object suitable for |
|
131 |
* storing AllPermissions. |
|
132 |
*/ |
|
133 |
public PermissionCollection newPermissionCollection() { |
|
134 |
return new AllPermissionCollection(); |
|
135 |
} |
|
136 |
||
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* A AllPermissionCollection stores a collection |
|
141 |
* of AllPermission permissions. AllPermission objects |
|
142 |
* must be stored in a manner that allows them to be inserted in any |
|
143 |
* order, but enable the implies function to evaluate the implies |
|
144 |
* method in an efficient (and consistent) manner. |
|
145 |
* |
|
146 |
* @see java.security.Permission |
|
147 |
* @see java.security.Permissions |
|
148 |
* |
|
149 |
* |
|
150 |
* @author Roland Schemers |
|
151 |
* |
|
152 |
* @serial include |
|
153 |
*/ |
|
154 |
||
155 |
final class AllPermissionCollection |
|
14014 | 156 |
extends PermissionCollection |
157 |
implements java.io.Serializable |
|
2 | 158 |
{ |
159 |
||
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 | 162 |
private static final long serialVersionUID = -4023755556366636806L; |
163 |
||
164 |
private boolean all_allowed; // true if any all permissions have been added |
|
165 |
||
166 |
/** |
|
167 |
* Create an empty AllPermissions object. |
|
168 |
* |
|
169 |
*/ |
|
170 |
||
171 |
public AllPermissionCollection() { |
|
172 |
all_allowed = false; |
|
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
* Adds a permission to the AllPermissions. The key for the hash is |
|
177 |
* permission.path. |
|
178 |
* |
|
179 |
* @param permission the Permission object to add. |
|
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 | 182 |
* AllPermission |
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 | 185 |
* has been marked readonly |
186 |
*/ |
|
187 |
||
14014 | 188 |
public void add(Permission permission) { |
2 | 189 |
if (! (permission instanceof AllPermission)) |
190 |
throw new IllegalArgumentException("invalid permission: "+ |
|
191 |
permission); |
|
192 |
if (isReadOnly()) |
|
193 |
throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection"); |
|
194 |
||
195 |
all_allowed = true; // No sync; staleness OK |
|
196 |
} |
|
197 |
||
198 |
/** |
|
199 |
* Check and see if this set of permissions implies the permissions |
|
200 |
* expressed in "permission". |
|
201 |
* |
|
14014 | 202 |
* @param permission the Permission object to compare |
2 | 203 |
* |
204 |
* @return always returns true. |
|
205 |
*/ |
|
206 |
||
14014 | 207 |
public boolean implies(Permission permission) { |
2 | 208 |
return all_allowed; // No sync; staleness OK |
209 |
} |
|
210 |
||
211 |
/** |
|
212 |
* Returns an enumeration of all the AllPermission objects in the |
|
213 |
* container. |
|
214 |
* |
|
215 |
* @return an enumeration of all the AllPermission objects. |
|
216 |
*/ |
|
14014 | 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 | 219 |
private boolean hasMore = all_allowed; |
220 |
||
221 |
public boolean hasMoreElements() { |
|
222 |
return hasMore; |
|
223 |
} |
|
224 |
||
225 |
public Permission nextElement() { |
|
226 |
hasMore = false; |
|
227 |
return SecurityConstants.ALL_PERMISSION; |
|
228 |
} |
|
229 |
}; |
|
230 |
} |
|
231 |
} |