38 39 // set security policy to allow access 40 if (allow) { 41 String testSrc = System.getProperty("test.src"); 42 if (testSrc == null) 43 testSrc = "."; 44 Path policyFile = Paths.get(testSrc, "java.policy"); 45 System.setProperty("java.security.policy", policyFile.toString()); 46 } 47 48 // make sure that jrt:/ has been created before we have a security manager 49 FileSystems.getFileSystem(URI.create("jrt:/")); 50 51 System.setSecurityManager(new SecurityManager()); 52 53 // check FileSystems.getFileSystem 54 try { 55 FileSystems.getFileSystem(URI.create("jrt:/")); 56 if (!allow) throw new RuntimeException("access not expected"); 57 } catch (SecurityException se) { 58 if (allow) throw new RuntimeException("access expected"); 59 } 60 61 // check FileSystems.newFileSystem 62 try { 63 FileSystems.newFileSystem(URI.create("jrt:/"), null); 64 if (!allow) throw new RuntimeException("access not expected"); 65 } catch (SecurityException se) { 66 if (allow) throw new RuntimeException("access expected"); 67 } 68 69 // check Paths.get 70 try { 71 Paths.get(URI.create("jrt:/java.base/java/lang/Object.class")); 72 if (!allow) throw new RuntimeException("access not expected"); 73 } catch (SecurityException se) { 74 if (allow) throw new RuntimeException("access expected"); 75 } 76 } 77 } | 38 39 // set security policy to allow access 40 if (allow) { 41 String testSrc = System.getProperty("test.src"); 42 if (testSrc == null) 43 testSrc = "."; 44 Path policyFile = Paths.get(testSrc, "java.policy"); 45 System.setProperty("java.security.policy", policyFile.toString()); 46 } 47 48 // make sure that jrt:/ has been created before we have a security manager 49 FileSystems.getFileSystem(URI.create("jrt:/")); 50 51 System.setSecurityManager(new SecurityManager()); 52 53 // check FileSystems.getFileSystem 54 try { 55 FileSystems.getFileSystem(URI.create("jrt:/")); 56 if (!allow) throw new RuntimeException("access not expected"); 57 } catch (SecurityException se) { 58 if (allow) 59 throw se; 60 } 61 62 // check FileSystems.newFileSystem 63 try { 64 FileSystems.newFileSystem(URI.create("jrt:/"), null); 65 if (!allow) throw new RuntimeException("access not expected"); 66 } catch (SecurityException se) { 67 if (allow) 68 throw se; 69 } 70 71 // check Paths.get 72 try { 73 Paths.get(URI.create("jrt:/java.base/java/lang/Object.class")); 74 if (!allow) throw new RuntimeException("access not expected"); 75 } catch (SecurityException se) { 76 if (allow) 77 throw se; 78 } 79 } 80 } |