From f40b961c6c82ebc9ae9863635e5fe19c0b07c116 Mon Sep 17 00:00:00 2001 From: Andrew Haley Date: Tue, 28 Nov 2006 09:27:42 +0000 Subject: 2006-11-28 Andrew Haley * vm/reference/sun/reflect/misc/ReflectUtil.java (checkPackageAccess): Implement. --- ChangeLog | 5 +++++ vm/reference/sun/reflect/misc/ReflectUtil.java | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cb214e8d5..1ac124999 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-11-28 Andrew Haley + + * vm/reference/sun/reflect/misc/ReflectUtil.java + (checkPackageAccess): Implement. + 2006-11-27 Andrew John Hughes * java/lang/Enum.java: diff --git a/vm/reference/sun/reflect/misc/ReflectUtil.java b/vm/reference/sun/reflect/misc/ReflectUtil.java index 547427748..88a6f2515 100644 --- a/vm/reference/sun/reflect/misc/ReflectUtil.java +++ b/vm/reference/sun/reflect/misc/ReflectUtil.java @@ -51,9 +51,29 @@ public class ReflectUtil { } + /** + * Check if the current thread is allowed to access the package of + * the declaringClass. + * + * @param declaringClass class name to check access to + * @throws SecurityException if permission is denied + * @throws NullPointerException if declaringClass is null + */ public static void checkPackageAccess(Class declaringClass) { - // FIXME: not sure what to check here. + SecurityManager sm; + if ((sm = System.getSecurityManager()) != null) + { + while (declaringClass.isArray()) + declaringClass = declaringClass.getComponentType(); + String name = declaringClass.getName(); + int i = name.lastIndexOf('.'); + if (i != -1) // if declaringClass is a member of a package + { + name = name.substring(0, i); + sm.checkPackageAccess(name); + } + } } /** -- cgit v1.2.1