Java Code Examples for java.security.Permissions#implies()

The following examples show how to use java.security.Permissions#implies() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityTest.java    From groovy with Apache License 2.0 5 votes vote down vote up
public void setUp() {
    forbidden = new Permissions();
    forbidden.add(new ReflectPermission("suppressAccessChecks"));
    restrictiveSecurityManager = new SecurityManager() {

        @Override
        public void checkPermission(Permission perm) {
            if (forbidden.implies(perm))
                throw new AccessControlException(perm.getName());
        }
    };
}
 
Example 2
Source File: LoaderHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 3
Source File: LoaderHandler.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 4
Source File: LoaderHandler.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 5
Source File: LoaderHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 6
Source File: LoaderHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 7
Source File: LoaderHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 8
Source File: LoaderHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 9
Source File: LoaderHandler.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 10
Source File: LoaderHandler.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 11
Source File: LoaderHandler.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 12
Source File: LoaderHandler.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 13
Source File: LoaderHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}
 
Example 14
Source File: LoaderHandler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the class annotation (representing the location for
 * a class) that RMI will use to annotate the call stream when
 * marshalling objects of the given class.
 */
public static String getClassAnnotation(Class<?> cl) {
    String name = cl.getName();

    /*
     * Class objects for arrays of primitive types never need an
     * annotation, because they never need to be (or can be) downloaded.
     *
     * REMIND: should we (not) be annotating classes that are in
     * "java.*" packages?
     */
    int nameLength = name.length();
    if (nameLength > 0 && name.charAt(0) == '[') {
        // skip past all '[' characters (see bugid 4211906)
        int i = 1;
        while (nameLength > i && name.charAt(i) == '[') {
            i++;
        }
        if (nameLength > i && name.charAt(i) != 'L') {
            return null;
        }
    }

    /*
     * Get the class's class loader.  If it is null, the system class
     * loader, an ancestor of the base class loader (such as the loader
     * for installed extensions), return the value of the
     * "java.rmi.server.codebase" property.
     */
    ClassLoader loader = cl.getClassLoader();
    if (loader == null || codebaseLoaders.containsKey(loader)) {
        return codebaseProperty;
    }

    /*
     * Get the codebase URL path for the class loader, if it supports
     * such a notion (i.e., if it is a URLClassLoader or subclass).
     */
    String annotation = null;
    if (loader instanceof Loader) {
        /*
         * If the class loader is one of our RMI class loaders, we have
         * already computed the class annotation string, and no
         * permissions are required to know the URLs.
         */
        annotation = ((Loader) loader).getClassAnnotation();

    } else if (loader instanceof URLClassLoader) {
        try {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            if (urls != null) {
                /*
                 * If the class loader is not one of our RMI class loaders,
                 * we must verify that the current access control context
                 * has permission to know all of these URLs.
                 */
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    Permissions perms = new Permissions();
                    for (int i = 0; i < urls.length; i++) {
                        Permission p =
                            urls[i].openConnection().getPermission();
                        if (p != null) {
                            if (!perms.implies(p)) {
                                sm.checkPermission(p);
                                perms.add(p);
                            }
                        }
                    }
                }

                annotation = urlsToPath(urls);
            }
        } catch (SecurityException | IOException e) {
            /*
             * SecurityException: If access was denied to the knowledge of
             * the class loader's URLs, fall back to the default behavior.
             *
             * IOException: This shouldn't happen, although it is declared
             * to be thrown by openConnection() and getPermission().  If it
             * does happen, forget about this class loader's URLs and
             * fall back to the default behavior.
             */
        }
    }

    if (annotation != null) {
        return annotation;
    } else {
        return codebaseProperty;    // REMIND: does this make sense??
    }
}