|
34 | 34 | import java.lang.StackWalker.StackFrame; |
35 | 35 | import java.lang.module.ModuleFinder; |
36 | 36 | import java.lang.module.ModuleReference; |
37 | | -import java.lang.module.ResolvedModule; |
38 | 37 | import java.nio.file.Path; |
39 | 38 | import java.util.ArrayList; |
40 | 39 | import java.util.HashSet; |
@@ -124,10 +123,20 @@ ModuleEntitlements policyEntitlements(String componentName, String moduleName, L |
124 | 123 |
|
125 | 124 | public static final String ALL_UNNAMED = "ALL-UNNAMED"; |
126 | 125 |
|
127 | | - private static final Set<ModuleReference> systemModules = findSystemModules(); |
| 126 | + private static final Set<Module> systemModules = findSystemModules(); |
128 | 127 |
|
129 | | - private static Set<ModuleReference> findSystemModules() { |
130 | | - return ModuleFinder.ofSystem().findAll().stream().collect(Collectors.toUnmodifiableSet()); |
| 128 | + private static Set<Module> findSystemModules() { |
| 129 | + var systemModulesDescriptors = ModuleFinder.ofSystem() |
| 130 | + .findAll() |
| 131 | + .stream() |
| 132 | + .map(ModuleReference::descriptor) |
| 133 | + .collect(Collectors.toUnmodifiableSet()); |
| 134 | + return Stream.concat( |
| 135 | + // entitlements is a "system" module, we can do anything from it |
| 136 | + Stream.of(PolicyManager.class.getModule()), |
| 137 | + // anything in the boot layer is also part of the system |
| 138 | + ModuleLayer.boot().modules().stream().filter(m -> systemModulesDescriptors.contains(m.getDescriptor())) |
| 139 | + ).collect(Collectors.toUnmodifiableSet()); |
131 | 140 | } |
132 | 141 |
|
133 | 142 | /** |
@@ -606,31 +615,14 @@ private static boolean isTriviallyAllowed(Class<?> requestingClass) { |
606 | 615 | logger.debug("Entitlement trivially allowed: no caller frames outside the entitlement library"); |
607 | 616 | return true; |
608 | 617 | } |
609 | | - if (isSystemModule(requestingClass.getModule())) { |
| 618 | + if (systemModules.contains(requestingClass.getModule())) { |
610 | 619 | logger.debug("Entitlement trivially allowed from system module [{}]", requestingClass.getModule().getName()); |
611 | 620 | return true; |
612 | 621 | } |
613 | 622 | logger.trace("Entitlement not trivially allowed"); |
614 | 623 | return false; |
615 | 624 | } |
616 | 625 |
|
617 | | - /** |
618 | | - * Determines if the given {@link Module} is a system module. That is, a module that is included as part of the Java runtime. |
619 | | - */ |
620 | | - private static boolean isSystemModule(Module module) { |
621 | | - if (module.getLayer() == null) { |
622 | | - // This is an unnamed module, so not a system module |
623 | | - return false; |
624 | | - } |
625 | | - |
626 | | - ModuleReference moduleReference = module.getLayer() |
627 | | - .configuration() |
628 | | - .findModule(module.getName()) |
629 | | - .map(ResolvedModule::reference) |
630 | | - .orElse(null); |
631 | | - return module == PolicyManager.class.getModule() || (moduleReference != null && systemModules.contains(moduleReference)); |
632 | | - } |
633 | | - |
634 | 626 | @Override |
635 | 627 | public String toString() { |
636 | 628 | return "PolicyManager{" + "serverEntitlements=" + serverEntitlements + ", pluginsEntitlements=" + pluginsEntitlements + '}'; |
|
0 commit comments