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