732 } |
732 } |
733 |
733 |
734 private static void checkNewProxyPermission(Class<?> caller, Class<?> proxyClass) { |
734 private static void checkNewProxyPermission(Class<?> caller, Class<?> proxyClass) { |
735 SecurityManager sm = System.getSecurityManager(); |
735 SecurityManager sm = System.getSecurityManager(); |
736 if (sm != null) { |
736 if (sm != null) { |
737 String pcn = proxyClass.getName(); |
737 if (ReflectUtil.isNonPublicProxyClass(proxyClass)) { |
738 if (pcn.startsWith(ReflectUtil.PROXY_PACKAGE + ".")) { |
738 ClassLoader ccl = caller.getClassLoader(); |
739 // all proxy interfaces are public |
739 ClassLoader pcl = proxyClass.getClassLoader(); |
740 return; |
740 |
741 } |
741 // do permission check if the caller is in a different runtime package |
742 |
742 // of the proxy class |
743 ClassLoader ccl = caller.getClassLoader(); |
743 int n = proxyClass.getName().lastIndexOf('.'); |
744 ClassLoader pcl = proxyClass.getClassLoader(); |
744 String pkg = (n == -1) ? "" : proxyClass.getName().substring(0, n); |
745 |
745 |
746 // do permission check if the caller is in a different runtime package |
746 n = caller.getName().lastIndexOf('.'); |
747 // of the proxy class |
747 String callerPkg = (n == -1) ? "" : caller.getName().substring(0, n); |
748 int n = pcn.lastIndexOf('.'); |
748 |
749 String pkg = (n == -1) ? "" : pcn.substring(0, n); |
749 if (pcl != ccl || !pkg.equals(callerPkg)) { |
750 |
750 sm.checkPermission(new ReflectPermission("newProxyInPackage." + pkg)); |
751 n = caller.getName().lastIndexOf('.'); |
751 } |
752 String callerPkg = (n == -1) ? "" : caller.getName().substring(0, n); |
|
753 |
|
754 if (pcl != ccl || !pkg.equals(callerPkg)) { |
|
755 sm.checkPermission(new ReflectPermission("newProxyInPackage." + pkg)); |
|
756 } |
752 } |
757 } |
753 } |
758 } |
754 } |
759 |
755 |
760 private static Object newInstance(Constructor<?> cons, InvocationHandler h) { |
756 private static Object newInstance(Constructor<?> cons, InvocationHandler h) { |