Skip to content

Commit 7d17e07

Browse files
committed
Rename PolicyScope
1 parent 99a3d75 commit 7d17e07

File tree

5 files changed

+48
-48
lines changed

5 files changed

+48
-48
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/bootstrap/EntitlementBootstrap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class EntitlementBootstrap {
3737
public record BootstrapArgs(
3838
@Nullable Policy serverPolicyPatch,
3939
Map<String, Policy> pluginPolicies,
40-
Function<Class<?>, PolicyManager.ScopeInfo> scopeResolver,
40+
Function<Class<?>, PolicyManager.PolicyScope> scopeResolver,
4141
Function<String, Stream<String>> settingResolver,
4242
Path[] dataDirs,
4343
Path[] sharedRepoDirs,
@@ -100,7 +100,7 @@ public static BootstrapArgs bootstrapArgs() {
100100
public static void bootstrap(
101101
Policy serverPolicyPatch,
102102
Map<String, Policy> pluginPolicies,
103-
Function<Class<?>, PolicyManager.ScopeInfo> scopeResolver,
103+
Function<Class<?>, PolicyManager.PolicyScope> scopeResolver,
104104
Function<String, Stream<String>> settingResolver,
105105
Path[] dataDirs,
106106
Path[] sharedRepoDirs,

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyManager.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public class PolicyManager {
7474
static final Set<String> MODULES_EXCLUDED_FROM_SYSTEM_MODULES = Set.of("java.desktop");
7575

7676
/**
77-
* Identifies a particular entitlement {@link Scope} within a component.
77+
* Identifies a particular entitlement {@link Scope} within a {@link Policy}.
7878
* @param componentName
7979
* @param moduleName
8080
*/
81-
public record ScopeInfo(String componentName, String moduleName) {
82-
public ScopeInfo {
81+
public record PolicyScope(String componentName, String moduleName) {
82+
public PolicyScope {
8383
requireNonNull(componentName);
8484
requireNonNull(moduleName);
8585
}
@@ -148,7 +148,7 @@ ModuleEntitlements policyEntitlements(String componentName, Path componentPath,
148148
private final Map<String, List<Entitlement>> serverEntitlements;
149149
private final List<Entitlement> apmAgentEntitlements;
150150
private final Map<String, Map<String, List<Entitlement>>> pluginsEntitlements;
151-
private final Function<Class<?>, ScopeInfo> scopeResolver;
151+
private final Function<Class<?>, PolicyScope> scopeResolver;
152152
private final PathLookup pathLookup;
153153
private final Set<Class<?>> mutedClasses;
154154

@@ -201,7 +201,7 @@ public PolicyManager(
201201
Policy serverPolicy,
202202
List<Entitlement> apmAgentEntitlements,
203203
Map<String, Policy> pluginPolicies,
204-
Function<Class<?>, ScopeInfo> scopeResolver,
204+
Function<Class<?>, PolicyScope> scopeResolver,
205205
Map<String, Path> sourcePaths,
206206
Module entitlementsModule,
207207
PathLookup pathLookup,
@@ -615,9 +615,9 @@ ModuleEntitlements getEntitlements(Class<?> requestingClass) {
615615
}
616616

617617
private ModuleEntitlements computeEntitlements(Class<?> requestingClass) {
618-
var scopeInfo = scopeResolver.apply(requestingClass);
619-
var componentName = scopeInfo.componentName();
620-
var moduleName = scopeInfo.moduleName();
618+
var policyScope = scopeResolver.apply(requestingClass);
619+
var componentName = policyScope.componentName();
620+
var moduleName = policyScope.moduleName();
621621

622622
switch (componentName) {
623623
case SERVER_COMPONENT_NAME -> {

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyManagerTests.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.elasticsearch.common.settings.Settings;
1414
import org.elasticsearch.core.Strings;
1515
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.ModuleEntitlements;
16-
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.ScopeInfo;
16+
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.PolicyScope;
1717
import org.elasticsearch.entitlement.runtime.policy.agent.TestAgent;
1818
import org.elasticsearch.entitlement.runtime.policy.agent.inner.TestInnerAgent;
1919
import org.elasticsearch.entitlement.runtime.policy.entitlements.CreateClassLoaderEntitlement;
@@ -91,7 +91,7 @@ public void testGetEntitlementsThrowsOnMissingPluginUnnamedModule() {
9191
createEmptyTestServerPolicy(),
9292
List.of(),
9393
Map.of("plugin1", createPluginPolicy("plugin.module")),
94-
c -> new ScopeInfo("plugin1", moduleName(c)),
94+
c -> new PolicyScope("plugin1", moduleName(c)),
9595
Map.of("plugin1", plugin1SourcePath),
9696
NO_ENTITLEMENTS_MODULE,
9797
TEST_PATH_LOOKUP,
@@ -120,7 +120,7 @@ public void testGetEntitlementsThrowsOnMissingPolicyForPlugin() {
120120
createEmptyTestServerPolicy(),
121121
List.of(),
122122
Map.of(),
123-
c -> new ScopeInfo("plugin1", moduleName(c)),
123+
c -> new PolicyScope("plugin1", moduleName(c)),
124124
Map.of("plugin1", plugin1SourcePath),
125125
NO_ENTITLEMENTS_MODULE,
126126
TEST_PATH_LOOKUP,
@@ -149,7 +149,7 @@ public void testGetEntitlementsFailureIsCached() {
149149
createEmptyTestServerPolicy(),
150150
List.of(),
151151
Map.of(),
152-
c -> new ScopeInfo("plugin1", moduleName(c)),
152+
c -> new PolicyScope("plugin1", moduleName(c)),
153153
Map.of("plugin1", plugin1SourcePath),
154154
NO_ENTITLEMENTS_MODULE,
155155
TEST_PATH_LOOKUP,
@@ -187,7 +187,7 @@ public void testGetEntitlementsReturnsEntitlementsForPluginUnnamedModule() {
187187
createEmptyTestServerPolicy(),
188188
List.of(),
189189
Map.ofEntries(entry("plugin2", createPluginPolicy(ALL_UNNAMED))),
190-
c -> new ScopeInfo("plugin2", moduleName(c)),
190+
c -> new PolicyScope("plugin2", moduleName(c)),
191191
Map.of("plugin2", Path.of("modules", "plugin2")),
192192
NO_ENTITLEMENTS_MODULE,
193193
TEST_PATH_LOOKUP,
@@ -206,7 +206,7 @@ public void testGetEntitlementsReturnsDefaultOnMissingPolicyForServer() throws C
206206
createTestServerPolicy("example"),
207207
List.of(),
208208
Map.of(),
209-
c -> new ScopeInfo(SERVER_COMPONENT_NAME, moduleName(c)),
209+
c -> new PolicyScope(SERVER_COMPONENT_NAME, moduleName(c)),
210210
Map.of(),
211211
NO_ENTITLEMENTS_MODULE,
212212
TEST_PATH_LOOKUP,
@@ -238,7 +238,7 @@ public void testGetEntitlementsReturnsEntitlementsForServerModule() throws Class
238238
createTestServerPolicy(httpserverModuleName),
239239
List.of(),
240240
Map.of(),
241-
c -> new ScopeInfo(SERVER_COMPONENT_NAME, moduleName(c)),
241+
c -> new PolicyScope(SERVER_COMPONENT_NAME, moduleName(c)),
242242
Map.of(),
243243
NO_ENTITLEMENTS_MODULE,
244244
TEST_PATH_LOOKUP,
@@ -263,7 +263,7 @@ public void testGetEntitlementsReturnsEntitlementsForPluginModule() throws IOExc
263263
createEmptyTestServerPolicy(),
264264
List.of(),
265265
Map.of("mock-plugin", createPluginPolicy("org.example.plugin")),
266-
c -> new ScopeInfo("mock-plugin", moduleName(c)),
266+
c -> new PolicyScope("mock-plugin", moduleName(c)),
267267
Map.of("mock-plugin", Path.of("modules", "mock-plugin")),
268268
NO_ENTITLEMENTS_MODULE,
269269
TEST_PATH_LOOKUP,
@@ -283,7 +283,7 @@ public void testGetEntitlementsResultIsCached() {
283283
createEmptyTestServerPolicy(),
284284
List.of(),
285285
Map.ofEntries(entry("plugin2", createPluginPolicy(ALL_UNNAMED))),
286-
c -> new ScopeInfo("plugin2", moduleName(c)),
286+
c -> new PolicyScope("plugin2", moduleName(c)),
287287
Map.of("plugin2", Path.of("modules", "plugin2")),
288288
NO_ENTITLEMENTS_MODULE,
289289
TEST_PATH_LOOKUP,
@@ -347,8 +347,8 @@ public void testAgentsEntitlements() throws IOException, ClassNotFoundException
347347
List.of(new CreateClassLoaderEntitlement()),
348348
Map.of(),
349349
c -> c.getPackageName().startsWith(TEST_AGENTS_PACKAGE_NAME)
350-
? new ScopeInfo(APM_AGENT_COMPONENT_NAME, "test.agent.module")
351-
: new ScopeInfo("test", "test.plugin.module"),
350+
? new PolicyScope(APM_AGENT_COMPONENT_NAME, "test.agent.module")
351+
: new PolicyScope("test", "test.plugin.module"),
352352
Map.of(),
353353
NO_ENTITLEMENTS_MODULE,
354354
TEST_PATH_LOOKUP,
@@ -377,7 +377,7 @@ public void testDuplicateEntitlements() {
377377
),
378378
List.of(),
379379
Map.of(),
380-
c -> new ScopeInfo("test", moduleName(c)),
380+
c -> new PolicyScope("test", moduleName(c)),
381381
Map.of(),
382382
NO_ENTITLEMENTS_MODULE,
383383
TEST_PATH_LOOKUP,
@@ -395,7 +395,7 @@ public void testDuplicateEntitlements() {
395395
createEmptyTestServerPolicy(),
396396
List.of(new CreateClassLoaderEntitlement(), new CreateClassLoaderEntitlement()),
397397
Map.of(),
398-
c -> new ScopeInfo("test", moduleName(c)),
398+
c -> new PolicyScope("test", moduleName(c)),
399399
Map.of(),
400400
NO_ENTITLEMENTS_MODULE,
401401
TEST_PATH_LOOKUP,
@@ -433,7 +433,7 @@ public void testDuplicateEntitlements() {
433433
)
434434
)
435435
),
436-
c -> new ScopeInfo("plugin1", moduleName(c)),
436+
c -> new PolicyScope("plugin1", moduleName(c)),
437437
Map.of("plugin1", Path.of("modules", "plugin1")),
438438
NO_ENTITLEMENTS_MODULE,
439439
TEST_PATH_LOOKUP,
@@ -485,7 +485,7 @@ public void testFilesEntitlementsWithExclusive() {
485485
)
486486
)
487487
),
488-
c -> new ScopeInfo("", moduleName(c)),
488+
c -> new PolicyScope("", moduleName(c)),
489489
Map.of("plugin1", Path.of("modules", "plugin1"), "plugin2", Path.of("modules", "plugin2")),
490490
NO_ENTITLEMENTS_MODULE,
491491
TEST_PATH_LOOKUP,
@@ -538,7 +538,7 @@ public void testFilesEntitlementsWithExclusive() {
538538
)
539539
)
540540
),
541-
c -> new ScopeInfo("", moduleName(c)),
541+
c -> new PolicyScope("", moduleName(c)),
542542
Map.of(),
543543
NO_ENTITLEMENTS_MODULE,
544544
TEST_PATH_LOOKUP,
@@ -564,7 +564,7 @@ public void testPluginResolverOverridesAgents() {
564564
createEmptyTestServerPolicy(),
565565
List.of(new CreateClassLoaderEntitlement()),
566566
Map.of(),
567-
c -> new ScopeInfo("test", moduleName(c)), // Insist that the class is in a plugin
567+
c -> new PolicyScope("test", moduleName(c)), // Insist that the class is in a plugin
568568
Map.of(),
569569
NO_ENTITLEMENTS_MODULE,
570570
TEST_PATH_LOOKUP,
@@ -586,7 +586,7 @@ private static PolicyManager policyManager(Module entitlementsModule) {
586586
createEmptyTestServerPolicy(),
587587
List.of(),
588588
Map.of(),
589-
c -> new ScopeInfo("test", moduleName(c)),
589+
c -> new PolicyScope("test", moduleName(c)),
590590
Map.of(),
591591
entitlementsModule,
592592
TEST_PATH_LOOKUP,

server/src/main/java/org/elasticsearch/bootstrap/ScopeResolver.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
package org.elasticsearch.bootstrap;
1111

12-
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.ScopeInfo;
12+
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.PolicyScope;
1313
import org.elasticsearch.plugins.PluginsLoader;
1414

1515
import java.util.HashMap;
@@ -53,21 +53,21 @@ public static ScopeResolver create(Stream<PluginsLoader.PluginLayer> pluginLayer
5353
return new ScopeResolver(pluginNameByModule, apmAgentPackageName);
5454
}
5555

56-
public ScopeInfo resolveClassToScope(Class<?> clazz) {
56+
public PolicyScope resolveClassToScope(Class<?> clazz) {
5757
var module = clazz.getModule();
5858
var scopeName = getScopeName(module);
5959
if (isServerModule(module)) {
60-
return new ScopeInfo(SERVER_COMPONENT_NAME, scopeName);
60+
return new PolicyScope(SERVER_COMPONENT_NAME, scopeName);
6161
}
6262
String pluginName = pluginNameByModule.get(module);
6363
if (pluginName != null) {
64-
return new ScopeInfo(pluginName, scopeName);
64+
return new PolicyScope(pluginName, scopeName);
6565
}
6666
if (module.isNamed() == false && clazz.getPackageName().startsWith(apmAgentPackageName)) {
6767
// The APM agent is the only thing running non-modular in the system classloader
68-
return new ScopeInfo(APM_AGENT_COMPONENT_NAME, ALL_UNNAMED);
68+
return new PolicyScope(APM_AGENT_COMPONENT_NAME, ALL_UNNAMED);
6969
}
70-
return new ScopeInfo(UNKNOWN_COMPONENT_NAME, scopeName);
70+
return new PolicyScope(UNKNOWN_COMPONENT_NAME, scopeName);
7171
}
7272

7373
private static boolean isServerModule(Module requestingModule) {

server/src/test/java/org/elasticsearch/bootstrap/ScopeResolverTests.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
package org.elasticsearch.bootstrap;
1111

12-
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.ScopeInfo;
12+
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.PolicyScope;
1313
import org.elasticsearch.plugins.PluginBundle;
1414
import org.elasticsearch.plugins.PluginDescriptor;
1515
import org.elasticsearch.plugins.PluginsLoader;
@@ -56,7 +56,7 @@ public void testBootLayer() throws ClassNotFoundException {
5656
// loaded too early) to mimic a class that would be in the server module.
5757
var mockServerClass = ModuleLayer.boot().findLoader("jdk.httpserver").loadClass("com.sun.net.httpserver.HttpServer");
5858

59-
assertEquals(new ScopeInfo(SERVER_COMPONENT_NAME, "jdk.httpserver"), scopeResolver.resolveClassToScope(mockServerClass));
59+
assertEquals(new PolicyScope(SERVER_COMPONENT_NAME, "jdk.httpserver"), scopeResolver.resolveClassToScope(mockServerClass));
6060
}
6161

6262
public void testResolveModularPlugin() throws IOException, ClassNotFoundException {
@@ -74,9 +74,9 @@ public void testResolveModularPlugin() throws IOException, ClassNotFoundExceptio
7474
Stream<PluginsLoader.PluginLayer> pluginLayers = Stream.of(new TestPluginLayer(bundle, loader, layer));
7575
ScopeResolver scopeResolver = ScopeResolver.create(pluginLayers, TEST_AGENTS_PACKAGE_NAME);
7676

77-
assertEquals(new ScopeInfo(pluginName, moduleName), scopeResolver.resolveClassToScope(loader.loadClass("p.A")));
78-
assertEquals(new ScopeInfo(UNKNOWN_COMPONENT_NAME, ALL_UNNAMED), scopeResolver.resolveClassToScope(ScopeResolver.class));
79-
assertEquals(new ScopeInfo(SERVER_COMPONENT_NAME, "java.base"), scopeResolver.resolveClassToScope(String.class));
77+
assertEquals(new PolicyScope(pluginName, moduleName), scopeResolver.resolveClassToScope(loader.loadClass("p.A")));
78+
assertEquals(new PolicyScope(UNKNOWN_COMPONENT_NAME, ALL_UNNAMED), scopeResolver.resolveClassToScope(ScopeResolver.class));
79+
assertEquals(new PolicyScope(SERVER_COMPONENT_NAME, "java.base"), scopeResolver.resolveClassToScope(String.class));
8080
}
8181

8282
public void testResolveMultipleModularPlugins() throws IOException, ClassNotFoundException {
@@ -98,8 +98,8 @@ public void testResolveMultipleModularPlugins() throws IOException, ClassNotFoun
9898
);
9999
ScopeResolver scopeResolver = ScopeResolver.create(pluginLayers, TEST_AGENTS_PACKAGE_NAME);
100100

101-
assertEquals(new ScopeInfo("plugin1", "module.one"), scopeResolver.resolveClassToScope(loader1.loadClass("p.A")));
102-
assertEquals(new ScopeInfo("plugin2", "module.two"), scopeResolver.resolveClassToScope(loader2.loadClass("q.B")));
101+
assertEquals(new PolicyScope("plugin1", "module.one"), scopeResolver.resolveClassToScope(loader1.loadClass("p.A")));
102+
assertEquals(new PolicyScope("plugin2", "module.two"), scopeResolver.resolveClassToScope(loader2.loadClass("q.B")));
103103
}
104104

105105
public void testResolveReferencedModulesInModularPlugins() throws IOException, ClassNotFoundException {
@@ -126,8 +126,8 @@ public void testResolveReferencedModulesInModularPlugins() throws IOException, C
126126
Stream<PluginsLoader.PluginLayer> pluginLayers = Stream.of(new TestPluginLayer(bundle, loader, layer));
127127
ScopeResolver scopeResolver = ScopeResolver.create(pluginLayers, TEST_AGENTS_PACKAGE_NAME);
128128

129-
assertEquals(new ScopeInfo("plugin2", "module.one"), scopeResolver.resolveClassToScope(loader.loadClass("p.A")));
130-
assertEquals(new ScopeInfo("plugin2", "module.two"), scopeResolver.resolveClassToScope(loader.loadClass("q.B")));
129+
assertEquals(new PolicyScope("plugin2", "module.one"), scopeResolver.resolveClassToScope(loader.loadClass("p.A")));
130+
assertEquals(new PolicyScope("plugin2", "module.two"), scopeResolver.resolveClassToScope(loader.loadClass("q.B")));
131131
}
132132

133133
public void testResolveMultipleNonModularPlugins() throws IOException, ClassNotFoundException {
@@ -145,8 +145,8 @@ public void testResolveMultipleNonModularPlugins() throws IOException, ClassNotF
145145
);
146146
ScopeResolver scopeResolver = ScopeResolver.create(pluginLayers, TEST_AGENTS_PACKAGE_NAME);
147147

148-
assertEquals(new ScopeInfo("plugin1", ALL_UNNAMED), scopeResolver.resolveClassToScope(loader1.loadClass("p.A")));
149-
assertEquals(new ScopeInfo("plugin2", ALL_UNNAMED), scopeResolver.resolveClassToScope(loader2.loadClass("q.B")));
148+
assertEquals(new PolicyScope("plugin1", ALL_UNNAMED), scopeResolver.resolveClassToScope(loader1.loadClass("p.A")));
149+
assertEquals(new PolicyScope("plugin2", ALL_UNNAMED), scopeResolver.resolveClassToScope(loader2.loadClass("q.B")));
150150
}
151151
}
152152

@@ -162,9 +162,9 @@ public void testResolveNonModularPlugin() throws IOException, ClassNotFoundExcep
162162
Stream<PluginsLoader.PluginLayer> pluginLayers = Stream.of(new TestPluginLayer(bundle, loader, ModuleLayer.boot()));
163163
ScopeResolver scopeResolver = ScopeResolver.create(pluginLayers, TEST_AGENTS_PACKAGE_NAME);
164164

165-
assertEquals(new ScopeInfo(pluginName, ALL_UNNAMED), scopeResolver.resolveClassToScope(loader.loadClass("p.A")));
166-
assertEquals(new ScopeInfo(UNKNOWN_COMPONENT_NAME, ALL_UNNAMED), scopeResolver.resolveClassToScope(ScopeResolver.class));
167-
assertEquals(new ScopeInfo(SERVER_COMPONENT_NAME, "java.base"), scopeResolver.resolveClassToScope(String.class));
165+
assertEquals(new PolicyScope(pluginName, ALL_UNNAMED), scopeResolver.resolveClassToScope(loader.loadClass("p.A")));
166+
assertEquals(new PolicyScope(UNKNOWN_COMPONENT_NAME, ALL_UNNAMED), scopeResolver.resolveClassToScope(ScopeResolver.class));
167+
assertEquals(new PolicyScope(SERVER_COMPONENT_NAME, "java.base"), scopeResolver.resolveClassToScope(String.class));
168168
}
169169
}
170170

0 commit comments

Comments
 (0)