33 import java.security.AccessControlException;
34 import java.security.Permission;
35 import java.util.Set;
36
37 public class NoAccess {
38 private static final Module M3 = NoAccess.class.getModule();
39 private static final Path MODS_DIR1 = Paths.get("mods1");
40 private static final Path MODS_DIR2 = Paths.get("mods2");
41 public static void main(String[] args) throws Exception {
42 // disable security manager until Class.forName is called.
43 SecurityManager sm = System.getSecurityManager();
44 if (sm != null) {
45 System.setSecurityManager(null);
46 }
47
48 ModuleFinder finder = ModuleFinder.of(Paths.get("mods1"), Paths.get("mods2"));
49
50 Layer bootLayer = Layer.boot();
51 Configuration parent = bootLayer.configuration();
52
53 Configuration cf = parent.resolveRequiresAndUses(finder,
54 ModuleFinder.of(),
55 Set.of("m1", "m2"));
56
57 ClassLoader scl = ClassLoader.getSystemClassLoader();
58 Layer layer = bootLayer.defineModulesWithManyLoaders(cf, scl);
59
60 if (sm != null) {
61 System.setSecurityManager(sm);
62 }
63
64 Module m1 = bootLayer.findModule("m1").get();
65 Module m2 = bootLayer.findModule("m2").get();
66 Module m3 = bootLayer.findModule("m3").get();
67
68 findClass(m1, "p1.internal.B");
69 findClass(m2, "p2.C");
70 findClass(m3, "p3.internal.Foo");
71
72 // permissions granted
73 findClass(m1, "p1.A");
|
33 import java.security.AccessControlException;
34 import java.security.Permission;
35 import java.util.Set;
36
37 public class NoAccess {
38 private static final Module M3 = NoAccess.class.getModule();
39 private static final Path MODS_DIR1 = Paths.get("mods1");
40 private static final Path MODS_DIR2 = Paths.get("mods2");
41 public static void main(String[] args) throws Exception {
42 // disable security manager until Class.forName is called.
43 SecurityManager sm = System.getSecurityManager();
44 if (sm != null) {
45 System.setSecurityManager(null);
46 }
47
48 ModuleFinder finder = ModuleFinder.of(Paths.get("mods1"), Paths.get("mods2"));
49
50 Layer bootLayer = Layer.boot();
51 Configuration parent = bootLayer.configuration();
52
53 Configuration cf = parent.resolveAndBind(finder,
54 ModuleFinder.of(),
55 Set.of("m1", "m2"));
56
57 ClassLoader scl = ClassLoader.getSystemClassLoader();
58 Layer layer = bootLayer.defineModulesWithManyLoaders(cf, scl);
59
60 if (sm != null) {
61 System.setSecurityManager(sm);
62 }
63
64 Module m1 = bootLayer.findModule("m1").get();
65 Module m2 = bootLayer.findModule("m2").get();
66 Module m3 = bootLayer.findModule("m3").get();
67
68 findClass(m1, "p1.internal.B");
69 findClass(m2, "p2.C");
70 findClass(m3, "p3.internal.Foo");
71
72 // permissions granted
73 findClass(m1, "p1.A");
|