src/jdk/nashorn/internal/runtime/Context.java

Print this page




 631      * @see AccessorProperty
 632      * @see ScriptObject
 633      *
 634      * @param fullName  full name of class, e.g. jdk.nashorn.internal.objects.JO2P1 contains 2 fields and 1 parameter.
 635      *
 636      * @return the {@code Class<?>} for this structure
 637      *
 638      * @throws ClassNotFoundException if structure class cannot be resolved
 639      */
 640     public static Class<?> forStructureClass(final String fullName) throws ClassNotFoundException {
 641         if (System.getSecurityManager() != null && !StructureLoader.isStructureClass(fullName)) {
 642             throw new ClassNotFoundException(fullName);
 643         }
 644         return Class.forName(fullName, true, sharedLoader);
 645     }
 646 
 647     /**
 648      * Checks that the given Class can be accessed from no permissions context.
 649      *
 650      * @param clazz Class object
 651      * @throw SecurityException if not accessible
 652      */
 653     public static void checkPackageAccess(final Class<?> clazz) {
 654         final SecurityManager sm = System.getSecurityManager();
 655         if (sm != null) {
 656             Class<?> bottomClazz = clazz;
 657             while (bottomClazz.isArray()) {
 658                 bottomClazz = bottomClazz.getComponentType();
 659             }
 660             checkPackageAccess(sm, bottomClazz.getName());
 661         }
 662     }
 663 
 664     /**
 665      * Checks that the given package name can be accessed from no permissions context.
 666      *
 667      * @param pkgName package name
 668      * @throw SecurityException if not accessible
 669      */
 670     public static void checkPackageAccess(final String pkgName) {
 671         final SecurityManager sm = System.getSecurityManager();
 672         if (sm != null) {
 673             checkPackageAccess(sm, pkgName.endsWith(".") ? pkgName : pkgName + ".");
 674         }
 675     }
 676 
 677     /**
 678      * Checks that the given package can be accessed from no permissions context.
 679      *
 680      * @param sm current security manager instance
 681      * @param fullName fully qualified package name
 682      * @throw SecurityException if not accessible
 683      */
 684     private static void checkPackageAccess(final SecurityManager sm, final String fullName) {
 685         sm.getClass(); // null check
 686         final int index = fullName.lastIndexOf('.');
 687         if (index != -1) {
 688             final String pkgName = fullName.substring(0, index);




 631      * @see AccessorProperty
 632      * @see ScriptObject
 633      *
 634      * @param fullName  full name of class, e.g. jdk.nashorn.internal.objects.JO2P1 contains 2 fields and 1 parameter.
 635      *
 636      * @return the {@code Class<?>} for this structure
 637      *
 638      * @throws ClassNotFoundException if structure class cannot be resolved
 639      */
 640     public static Class<?> forStructureClass(final String fullName) throws ClassNotFoundException {
 641         if (System.getSecurityManager() != null && !StructureLoader.isStructureClass(fullName)) {
 642             throw new ClassNotFoundException(fullName);
 643         }
 644         return Class.forName(fullName, true, sharedLoader);
 645     }
 646 
 647     /**
 648      * Checks that the given Class can be accessed from no permissions context.
 649      *
 650      * @param clazz Class object
 651      * @throws SecurityException if not accessible
 652      */
 653     public static void checkPackageAccess(final Class<?> clazz) {
 654         final SecurityManager sm = System.getSecurityManager();
 655         if (sm != null) {
 656             Class<?> bottomClazz = clazz;
 657             while (bottomClazz.isArray()) {
 658                 bottomClazz = bottomClazz.getComponentType();
 659             }
 660             checkPackageAccess(sm, bottomClazz.getName());
 661         }
 662     }
 663 
 664     /**
 665      * Checks that the given package name can be accessed from no permissions context.
 666      *
 667      * @param pkgName package name
 668      * @throws SecurityException if not accessible
 669      */
 670     public static void checkPackageAccess(final String pkgName) {
 671         final SecurityManager sm = System.getSecurityManager();
 672         if (sm != null) {
 673             checkPackageAccess(sm, pkgName.endsWith(".") ? pkgName : pkgName + ".");
 674         }
 675     }
 676 
 677     /**
 678      * Checks that the given package can be accessed from no permissions context.
 679      *
 680      * @param sm current security manager instance
 681      * @param fullName fully qualified package name
 682      * @throw SecurityException if not accessible
 683      */
 684     private static void checkPackageAccess(final SecurityManager sm, final String fullName) {
 685         sm.getClass(); // null check
 686         final int index = fullName.lastIndexOf('.');
 687         if (index != -1) {
 688             final String pkgName = fullName.substring(0, index);