Java Code Examples for java.rmi.server.RMIClassLoader#getClassLoader()
The following examples show how to use
java.rmi.server.RMIClassLoader#getClassLoader() .
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: NoSecurityManager.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 2
Source File: NoSecurityManager.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 3
Source File: NoSecurityManager.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 4
Source File: NoSecurityManager.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 5
Source File: NoSecurityManager.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 6
Source File: CodebaseAwareObjectInputStream.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override protected ClassLoader getFallbackClassLoader() throws IOException { return RMIClassLoader.getClassLoader(this.codebaseUrl); }
Example 7
Source File: NoSecurityManager.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 8
Source File: NoSecurityManager.java From hottub with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 9
Source File: NoSecurityManager.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 10
Source File: CodebaseAwareObjectInputStream.java From spring-analysis-note with MIT License | 4 votes |
@Override protected ClassLoader getFallbackClassLoader() throws IOException { return RMIClassLoader.getClassLoader(this.codebaseUrl); }
Example 11
Source File: NoSecurityManager.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 12
Source File: CodebaseAwareObjectInputStream.java From lams with GNU General Public License v2.0 | 4 votes |
@Override protected ClassLoader getFallbackClassLoader() throws IOException { return RMIClassLoader.getClassLoader(this.codebaseUrl); }
Example 13
Source File: NoSecurityManager.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 14
Source File: NoSecurityManager.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 15
Source File: CodebaseAwareObjectInputStream.java From java-technology-stack with MIT License | 4 votes |
@Override protected ClassLoader getFallbackClassLoader() throws IOException { return RMIClassLoader.getClassLoader(this.codebaseUrl); }
Example 16
Source File: NoSecurityManager.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }
Example 17
Source File: NoSecurityManager.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* * Specify the file to contain the class definition. * Make sure that there is a "classes" subdirectory underneath * the working directory to be used as the codebase for the * class definition to be located. */ File dstDir = new File(System.getProperty("user.dir"), "codebase"); if (!dstDir.exists()) { if (!dstDir.mkdir()) { throw new RuntimeException( "could not create codebase directory"); } } File dstFile = new File(dstDir, classFileName); /* * Specify where we will copy the class definition from, if * necessary. After the test is built, the class file can be * found in the "test.classes" directory. */ File srcDir = new File(System.getProperty("test.classes", ".")); File srcFile = new File(srcDir, classFileName); /* * If the class definition is not already located at the codebase, * copy it there from the test build area. */ if (!dstFile.exists()) { if (!srcFile.exists()) { throw new RuntimeException( "could not find class file to install in codebase " + "(try rebuilding the test)"); } if (!srcFile.renameTo(dstFile)) { throw new RuntimeException( "could not install class file in codebase"); } } /* * After the class definition is successfully installed at the * codebase, delete it from the test's CLASSPATH, so that it will * not be found there first before the codebase is searched. */ if (srcFile.exists()) { if (!srcFile.delete()) { throw new RuntimeException( "could not delete duplicate class file in CLASSPATH"); } } /* * Obtain the URL for the codebase. */ URL codebaseURL = new URL("file", "", dstDir.getAbsolutePath().replace(File.separatorChar, '/') + "/"); /* * No security manager has been set: verify that we cannot load * a class from a specified codebase (that is not in the class path). */ try { RMIClassLoader.loadClass(codebaseURL, className); throw new RuntimeException( "TEST FAILED: class loaded successfully from codebase"); } catch (ClassNotFoundException e) { System.err.println(e.toString()); } /* * No security manager has been set: verify that we can still * load a class available in the context class loader (class path). */ RMIClassLoader.loadClass(codebaseURL, "LocalDummy"); System.err.println("TEST PASSED: local class loaded successfully"); /* * Verify that getClassLoader returns context class loader * if no security manager is set. */ System.err.println("/nTest getClassLoader with no security manager set"); ClassLoader loader = RMIClassLoader.getClassLoader("http://codebase"); if (loader == Thread.currentThread().getContextClassLoader()) { System.err.println("TEST PASSED: returned context class loader"); } else { throw new RuntimeException( "TEST FAILED: returned RMI-created class loader"); } }