changeset 6688:c919b499eb96

8017300: Improve Interface Implementation Reviewed-by: ahgross, jlaskey, mchung
author sundar
date Tue, 16 Jul 2013 23:02:21 +0530
parents 1d42f8941555
children 269dc6aa6b62 ba3da584814b
files src/share/classes/com/sun/script/util/InterfaceImplementor.java src/share/lib/security/java.security-linux src/share/lib/security/java.security-macosx src/share/lib/security/java.security-solaris src/share/lib/security/java.security-windows test/java/lang/SecurityManager/CheckPackageAccess.java
diffstat 6 files changed, 38 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/script/util/InterfaceImplementor.java	Tue Jul 16 21:00:34 2013 +0400
+++ b/src/share/classes/com/sun/script/util/InterfaceImplementor.java	Tue Jul 16 23:02:21 2013 +0530
@@ -28,6 +28,7 @@
 import javax.script.*;
 import java.lang.reflect.*;
 import java.security.*;
+import sun.reflect.misc.ReflectUtil;
 
 /*
  * java.lang.reflect.Proxy based interface implementor. This is meant
@@ -85,8 +86,18 @@
         if (! isImplemented(thiz, iface)) {
             return null;
         }
+
+        if (System.getSecurityManager() != null &&
+           !Modifier.isPublic(iface.getModifiers())) {
+            throw new SecurityException("attempt to implement non-public interface");
+        }
+
+        // make sure restricted package interfaces are not attempted.
+        ReflectUtil.checkPackageAccess(iface.getName());
+
         AccessControlContext accCtxt = AccessController.getContext();
-        return iface.cast(Proxy.newProxyInstance(iface.getClassLoader(),
+        return iface.cast(Proxy.newProxyInstance(
+            getLoaderForProxy(iface),
             new Class[]{iface},
             new InterfaceImplementorInvocationHandler(thiz, accCtxt)));
     }
@@ -108,4 +119,20 @@
         // default is identity conversion
         return args;
     }
+
+    // get appropriate ClassLoader for generated Proxy class
+    private static ClassLoader getLoaderForProxy(Class<?> iface) {
+        ClassLoader loader = iface.getClassLoader();
+
+        // if bootstrap class, try TCCL
+        if (loader == null) {
+            loader = Thread.currentThread().getContextClassLoader();
+        }
+
+        // if TCCL is also null, try System class loader
+        if (loader == null) {
+            loader = ClassLoader.getSystemClassLoader();
+        }
+        return loader;
+    }
 }
--- a/src/share/lib/security/java.security-linux	Tue Jul 16 21:00:34 2013 +0400
+++ b/src/share/lib/security/java.security-linux	Tue Jul 16 23:02:21 2013 +0530
@@ -130,6 +130,7 @@
                com.sun.istack.internal.,\
                com.sun.jmx.,\
                com.sun.proxy.,\
+               com.sun.script.,\
                com.sun.org.apache.bcel.internal.,\
                com.sun.org.apache.regexp.internal.,\
                com.sun.org.apache.xerces.internal.,\
@@ -168,6 +169,7 @@
                    com.sun.istack.internal.,\
                    com.sun.jmx.,\
                    com.sun.proxy.,\
+                   com.sun.script.,\
                    com.sun.org.apache.bcel.internal.,\
                    com.sun.org.apache.regexp.internal.,\
                    com.sun.org.apache.xerces.internal.,\
--- a/src/share/lib/security/java.security-macosx	Tue Jul 16 21:00:34 2013 +0400
+++ b/src/share/lib/security/java.security-macosx	Tue Jul 16 23:02:21 2013 +0530
@@ -131,6 +131,7 @@
                com.sun.istack.internal.,\
                com.sun.jmx.,\
                com.sun.proxy.,\
+               com.sun.script.,\
                com.sun.org.apache.bcel.internal.,\
                com.sun.org.apache.regexp.internal.,\
                com.sun.org.apache.xerces.internal.,\
@@ -171,6 +172,7 @@
                    com.sun.istack.internal.,\
                    com.sun.jmx.,\
                    com.sun.proxy.,\
+                   com.sun.script.,\
                    com.sun.org.apache.bcel.internal.,\
                    com.sun.org.apache.regexp.internal.,\
                    com.sun.org.apache.xerces.internal.,\
--- a/src/share/lib/security/java.security-solaris	Tue Jul 16 21:00:34 2013 +0400
+++ b/src/share/lib/security/java.security-solaris	Tue Jul 16 23:02:21 2013 +0530
@@ -132,6 +132,7 @@
                com.sun.istack.internal.,\
                com.sun.jmx.,\
                com.sun.proxy.,\
+               com.sun.script.,\
                com.sun.org.apache.bcel.internal.,\
                com.sun.org.apache.regexp.internal.,\
                com.sun.org.apache.xerces.internal.,\
@@ -171,6 +172,7 @@
                    com.sun.istack.internal.,\
                    com.sun.jmx.,\
                    com.sun.proxy.,\
+                   com.sun.script.,\
                    com.sun.org.apache.bcel.internal.,\
                    com.sun.org.apache.regexp.internal.,\
                    com.sun.org.apache.xerces.internal.,\
--- a/src/share/lib/security/java.security-windows	Tue Jul 16 21:00:34 2013 +0400
+++ b/src/share/lib/security/java.security-windows	Tue Jul 16 23:02:21 2013 +0530
@@ -131,6 +131,7 @@
                com.sun.istack.internal.,\
                com.sun.jmx.,\
                com.sun.proxy.,\
+               com.sun.script.,\
                com.sun.org.apache.bcel.internal.,\
                com.sun.org.apache.regexp.internal.,\
                com.sun.org.apache.xerces.internal.,\
@@ -171,6 +172,7 @@
                    com.sun.istack.internal.,\
                    com.sun.jmx.,\
                    com.sun.proxy.,\
+                   com.sun.script.,\
                    com.sun.org.apache.bcel.internal.,\
                    com.sun.org.apache.regexp.internal.,\
                    com.sun.org.apache.xerces.internal.,\
--- a/test/java/lang/SecurityManager/CheckPackageAccess.java	Tue Jul 16 21:00:34 2013 +0400
+++ b/test/java/lang/SecurityManager/CheckPackageAccess.java	Tue Jul 16 23:02:21 2013 +0530
@@ -34,7 +34,8 @@
         String[] pkgs = new String[] {
             "com.sun.corba.se.impl.",
             "com.sun.org.apache.xerces.internal.utils.",
-            "com.sun.org.apache.xalan.internal.utils." };
+            "com.sun.org.apache.xalan.internal.utils.",
+            "com.sun.script." };
         SecurityManager sm = new SecurityManager();
         System.setSecurityManager(sm);
         for (String pkg : pkgs) {