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 *
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.
24 */
25
26 package java.security;
27
28 import java.util.Map;
29 import java.util.Objects;
30 import java.util.concurrent.ConcurrentHashMap;
31 import java.util.function.Function;
32
33 /**
34 * This class extends {@code ClassLoader} with additional support for defining
35 * classes with an associated code source and permissions.
36 *
37 * @apiNote
38 * Permissions cannot be used for controlling access to resources
39 * as the Security Manager is no longer supported.
40 *
41 * @author Li Gong
42 * @author Roland Schemers
43 * @since 1.2
44 */
45 public class SecureClassLoader extends ClassLoader {
46
47 /*
48 * Map that maps the CodeSource to a ProtectionDomain. The key is a
49 * CodeSourceKey class that uses a {@code String} instead of a URL to avoid
50 * potential expensive name service lookups. This does mean that URLs that
51 * are equivalent after nameservice lookup will be placed in separate
212 return Objects.hashCode(cs.getLocationNoFragString());
213 }
214
215 @Override
216 public boolean equals(Object obj) {
217 if (obj == this) {
218 return true;
219 }
220
221 return obj instanceof CodeSourceKey other
222 && Objects.equals(cs.getLocationNoFragString(),
223 other.cs.getLocationNoFragString())
224 && cs.matchCerts(other.cs, true);
225 }
226 }
227
228 /**
229 * Called by the VM, during -Xshare:dump
230 */
231 private void resetArchivedStates() {
232 pdcache.clear();
233 }
234 }
|
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 *
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.
24 */
25
26 package java.security;
27
28 import java.util.Map;
29 import java.util.Objects;
30 import java.util.concurrent.ConcurrentHashMap;
31 import java.util.function.Function;
32 import jdk.internal.misc.CDS;
33
34 /**
35 * This class extends {@code ClassLoader} with additional support for defining
36 * classes with an associated code source and permissions.
37 *
38 * @apiNote
39 * Permissions cannot be used for controlling access to resources
40 * as the Security Manager is no longer supported.
41 *
42 * @author Li Gong
43 * @author Roland Schemers
44 * @since 1.2
45 */
46 public class SecureClassLoader extends ClassLoader {
47
48 /*
49 * Map that maps the CodeSource to a ProtectionDomain. The key is a
50 * CodeSourceKey class that uses a {@code String} instead of a URL to avoid
51 * potential expensive name service lookups. This does mean that URLs that
52 * are equivalent after nameservice lookup will be placed in separate
213 return Objects.hashCode(cs.getLocationNoFragString());
214 }
215
216 @Override
217 public boolean equals(Object obj) {
218 if (obj == this) {
219 return true;
220 }
221
222 return obj instanceof CodeSourceKey other
223 && Objects.equals(cs.getLocationNoFragString(),
224 other.cs.getLocationNoFragString())
225 && cs.matchCerts(other.cs, true);
226 }
227 }
228
229 /**
230 * Called by the VM, during -Xshare:dump
231 */
232 private void resetArchivedStates() {
233 if (CDS.isDumpingProtectionDomains()) {
234 if (System.getProperty("cds.debug.archived.protection.domains") != null) {
235 for (Map.Entry<CodeSourceKey, ProtectionDomain> entry : pdcache.entrySet()) {
236 CodeSourceKey key = entry.getKey();
237 System.out.println("Archiving ProtectionDomain " + key.cs + " for " + this);
238 }
239 }
240 } else {
241 pdcache.clear();
242 }
243 }
244 }
|