From 6d897ac7a88cbca14bd67ac62c02509c823d8b8a Mon Sep 17 00:00:00 2001 From: Athijegannathan Sundararajan Date: Thu, 30 Jan 2014 18:49:47 +0530 Subject: [PATCH] 8032954: Nashorn: extend Java.extend Reviewed-by: jlaskey, attila, ahgross --- .../runtime/linker/JavaAdapterFactory.java | 2 ++ nashorn/test/script/sandbox/classloader.js | 22 +++++++++++++++++++ .../script/sandbox/classloader.js.EXPECTED | 2 ++ 3 files changed, 26 insertions(+) diff --git a/nashorn/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java b/nashorn/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java index b221d000034..878c0058c76 100644 --- a/nashorn/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java +++ b/nashorn/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java @@ -110,6 +110,8 @@ public final class JavaAdapterFactory { for (Class type : types) { // check for restricted package access Context.checkPackageAccess(type); + // check for classes, interfaces in reflection + ReflectionCheckLinker.checkReflectionAccess(type); } } return getAdapterInfo(types).getAdapterClassFor(classOverrides); diff --git a/nashorn/test/script/sandbox/classloader.js b/nashorn/test/script/sandbox/classloader.js index 7676496060d..9de1a5c37f2 100644 --- a/nashorn/test/script/sandbox/classloader.js +++ b/nashorn/test/script/sandbox/classloader.js @@ -26,6 +26,7 @@ * * @test * @security + * @bug JDK-8032954: Nashorn: extend Java.extend */ try { @@ -39,3 +40,24 @@ try { } } +try { + Java.extend(Java.type('java.lang.ClassLoader')); + fail("should have thrown SecurityException"); +} catch (e) { + if (e instanceof java.lang.SecurityException) { + print(e); + } else { + fail("expected SecurityException, got " + e); + } +} + +try { + Java.extend(Java.type("javax.management.loading.MLet")); + fail("should have thrown SecurityException"); +} catch (e) { + if (e instanceof java.lang.SecurityException) { + print(e); + } else { + fail("expected SecurityException, got " + e); + } +} diff --git a/nashorn/test/script/sandbox/classloader.js.EXPECTED b/nashorn/test/script/sandbox/classloader.js.EXPECTED index 356053d4e1d..8c241912f36 100644 --- a/nashorn/test/script/sandbox/classloader.js.EXPECTED +++ b/nashorn/test/script/sandbox/classloader.js.EXPECTED @@ -1 +1,3 @@ java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection") +java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection") +java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection")