author | darcy |
Thu, 29 Aug 2019 10:52:21 -0700 | |
changeset 57950 | 4612a3cfb927 |
parent 47216 | 71c04702a3d5 |
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) 1999, 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 javax.crypto; |
|
27 |
||
28 |
import java.security.*; |
|
29 |
import java.util.Enumeration; |
|
30 |
import java.util.Vector; |
|
31 |
||
32 |
/** |
|
33 |
* The CryptoAllPermission is a permission that implies |
|
34 |
* any other crypto permissions. |
|
35 |
* <p> |
|
36 |
* |
|
37 |
* @see java.security.Permission |
|
38 |
* @see java.security.AllPermission |
|
39 |
* |
|
40 |
* @author Sharon Liu |
|
41 |
* @since 1.4 |
|
42 |
*/ |
|
43 |
||
44 |
final class CryptoAllPermission extends CryptoPermission { |
|
45 |
||
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
46 |
@java.io.Serial |
2 | 47 |
private static final long serialVersionUID = -5066513634293192112L; |
48 |
||
49 |
// This class is similar to java.security.AllPermission. |
|
50 |
static final String ALG_NAME = "CryptoAllPermission"; |
|
51 |
static final CryptoAllPermission INSTANCE = |
|
52 |
new CryptoAllPermission(); |
|
53 |
||
54 |
private CryptoAllPermission() { |
|
55 |
super(ALG_NAME); |
|
56 |
} |
|
57 |
||
58 |
/** |
|
59 |
* Checks if the specified permission is implied by |
|
60 |
* this object. |
|
61 |
* |
|
62 |
* @param p the permission to check against. |
|
63 |
* |
|
64 |
* @return true if the specified permission is an |
|
65 |
* instance of CryptoPermission. |
|
66 |
*/ |
|
67 |
public boolean implies(Permission p) { |
|
68 |
return (p instanceof CryptoPermission); |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Checks two CryptoAllPermission objects for equality. |
|
73 |
* Two CryptoAllPermission objects are always equal. |
|
74 |
* |
|
75 |
* @param obj the object to test for equality with this object. |
|
76 |
* |
|
77 |
* @return true if <i>obj</i> is a CryptoAllPermission object. |
|
78 |
*/ |
|
79 |
public boolean equals(Object obj) { |
|
80 |
return (obj == INSTANCE); |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* |
|
85 |
* Returns the hash code value for this object. |
|
86 |
* |
|
87 |
* @return a hash code value for this object. |
|
88 |
*/ |
|
89 |
public int hashCode() { |
|
90 |
return 1; |
|
91 |
} |
|
92 |
||
93 |
/** |
|
94 |
* Returns a new PermissionCollection object for storing |
|
95 |
* CryptoAllPermission objects. |
|
96 |
* <p> |
|
97 |
* |
|
98 |
* @return a new PermissionCollection object suitable for |
|
99 |
* storing CryptoAllPermissions. |
|
100 |
*/ |
|
101 |
public PermissionCollection newPermissionCollection() { |
|
102 |
return new CryptoAllPermissionCollection(); |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* A CryptoAllPermissionCollection stores a collection |
|
108 |
* of CryptoAllPermission permissions. |
|
109 |
* |
|
110 |
* @see java.security.Permission |
|
111 |
* @see java.security.Permissions |
|
112 |
* @see javax.crypto.CryptoPermission |
|
113 |
* |
|
114 |
* @author Sharon Liu |
|
115 |
*/ |
|
116 |
final class CryptoAllPermissionCollection extends PermissionCollection |
|
117 |
implements java.io.Serializable |
|
118 |
{ |
|
119 |
||
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
120 |
@java.io.Serial |
2 | 121 |
private static final long serialVersionUID = 7450076868380144072L; |
122 |
||
123 |
// true if a CryptoAllPermission has been added |
|
124 |
private boolean all_allowed; |
|
125 |
||
126 |
/** |
|
127 |
* Create an empty CryptoAllPermissions object. |
|
128 |
*/ |
|
129 |
CryptoAllPermissionCollection() { |
|
130 |
all_allowed = false; |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Adds a permission to the CryptoAllPermissions. |
|
135 |
* |
|
136 |
* @param permission the Permission object to add. |
|
137 |
* |
|
138 |
* @exception SecurityException - if this CryptoAllPermissionCollection |
|
139 |
* object has been marked readonly |
|
140 |
*/ |
|
14014 | 141 |
public void add(Permission permission) { |
2 | 142 |
if (isReadOnly()) |
143 |
throw new SecurityException("attempt to add a Permission to " + |
|
144 |
"a readonly PermissionCollection"); |
|
145 |
||
146 |
if (permission != CryptoAllPermission.INSTANCE) |
|
147 |
return; |
|
148 |
||
149 |
all_allowed = true; |
|
150 |
} |
|
151 |
||
152 |
/** |
|
153 |
* Check and see if this set of permissions implies the permissions |
|
154 |
* expressed in "permission". |
|
155 |
* |
|
14014 | 156 |
* @param permission the Permission object to compare |
2 | 157 |
* |
158 |
* @return true if the given permission is implied by this |
|
159 |
* CryptoAllPermissionCollection. |
|
160 |
*/ |
|
14014 | 161 |
public boolean implies(Permission permission) { |
2 | 162 |
if (!(permission instanceof CryptoPermission)) { |
163 |
return false; |
|
164 |
} |
|
165 |
return all_allowed; |
|
166 |
} |
|
167 |
||
168 |
/** |
|
169 |
* Returns an enumeration of all the CryptoAllPermission |
|
170 |
* objects in the container. |
|
171 |
* |
|
172 |
* @return an enumeration of all the CryptoAllPermission objects. |
|
173 |
*/ |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
5506
diff
changeset
|
174 |
public Enumeration<Permission> elements() { |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
5506
diff
changeset
|
175 |
Vector<Permission> v = new Vector<>(1); |
2 | 176 |
if (all_allowed) v.add(CryptoAllPermission.INSTANCE); |
177 |
return v.elements(); |
|
178 |
} |
|
179 |
} |