15
15
import org .elasticsearch .entitlement .runtime .api .ElasticsearchEntitlementChecker ;
16
16
import org .elasticsearch .entitlement .runtime .policy .PathLookup ;
17
17
import org .elasticsearch .entitlement .runtime .policy .Policy ;
18
+ import org .elasticsearch .entitlement .runtime .policy .PolicyChecker ;
19
+ import org .elasticsearch .entitlement .runtime .policy .PolicyCheckerImpl ;
18
20
import org .elasticsearch .entitlement .runtime .policy .PolicyManager ;
19
21
20
22
import java .lang .instrument .Instrumentation ;
@@ -75,25 +77,6 @@ public static void initialize(Instrumentation inst) throws Exception {
75
77
);
76
78
}
77
79
78
- private static PolicyManager createPolicyManager () {
79
- EntitlementBootstrap .BootstrapArgs bootstrapArgs = EntitlementBootstrap .bootstrapArgs ();
80
- Map <String , Policy > pluginPolicies = bootstrapArgs .pluginPolicies ();
81
- PathLookup pathLookup = bootstrapArgs .pathLookup ();
82
-
83
- FilesEntitlementsValidation .validate (pluginPolicies , pathLookup );
84
-
85
- return new PolicyManager (
86
- HardcodedEntitlements .serverPolicy (pathLookup .pidFile (), bootstrapArgs .serverPolicyPatch ()),
87
- HardcodedEntitlements .agentEntitlements (),
88
- pluginPolicies ,
89
- EntitlementBootstrap .bootstrapArgs ().scopeResolver (),
90
- EntitlementBootstrap .bootstrapArgs ().sourcePaths (),
91
- ENTITLEMENTS_MODULE ,
92
- pathLookup ,
93
- bootstrapArgs .suppressFailureLogPackages ()
94
- );
95
- }
96
-
97
80
/**
98
81
* If bytecode verification is enabled, ensure these classes get loaded before transforming/retransforming them.
99
82
* For these classes, the order in which we transform and verify them matters. Verification during class transformation is at least an
@@ -113,7 +96,7 @@ private static void ensureClassesSensitiveToVerificationAreInitialized() {
113
96
}
114
97
115
98
private static ElasticsearchEntitlementChecker initChecker () {
116
- final PolicyManager policyManager = createPolicyManager ();
99
+ final PolicyChecker policyChecker = createPolicyChecker ();
117
100
118
101
final Class <?> clazz = EntitlementCheckerUtils .getVersionSpecificCheckerClass (
119
102
ElasticsearchEntitlementChecker .class ,
@@ -122,14 +105,38 @@ private static ElasticsearchEntitlementChecker initChecker() {
122
105
123
106
Constructor <?> constructor ;
124
107
try {
125
- constructor = clazz .getConstructor (PolicyManager .class );
108
+ constructor = clazz .getConstructor (PolicyChecker .class );
126
109
} catch (NoSuchMethodException e ) {
127
- throw new AssertionError ("entitlement impl is missing no arg constructor" , e );
110
+ throw new AssertionError ("entitlement impl is missing required constructor: [" + clazz . getName () + "] " , e );
128
111
}
129
112
try {
130
- return (ElasticsearchEntitlementChecker ) constructor .newInstance (policyManager );
113
+ return (ElasticsearchEntitlementChecker ) constructor .newInstance (policyChecker );
131
114
} catch (IllegalAccessException | InvocationTargetException | InstantiationException e ) {
132
115
throw new AssertionError (e );
133
116
}
134
117
}
118
+
119
+ private static PolicyCheckerImpl createPolicyChecker () {
120
+ EntitlementBootstrap .BootstrapArgs bootstrapArgs = EntitlementBootstrap .bootstrapArgs ();
121
+ Map <String , Policy > pluginPolicies = bootstrapArgs .pluginPolicies ();
122
+ PathLookup pathLookup = bootstrapArgs .pathLookup ();
123
+
124
+ FilesEntitlementsValidation .validate (pluginPolicies , pathLookup );
125
+
126
+ PolicyManager policyManager = new PolicyManager (
127
+ HardcodedEntitlements .serverPolicy (pathLookup .pidFile (), bootstrapArgs .serverPolicyPatch ()),
128
+ HardcodedEntitlements .agentEntitlements (),
129
+ pluginPolicies ,
130
+ EntitlementBootstrap .bootstrapArgs ().scopeResolver (),
131
+ EntitlementBootstrap .bootstrapArgs ().sourcePaths (),
132
+ pathLookup
133
+ );
134
+ return new PolicyCheckerImpl (
135
+ bootstrapArgs .suppressFailureLogPackages (),
136
+ ENTITLEMENTS_MODULE ,
137
+ policyManager ,
138
+ bootstrapArgs .pathLookup ()
139
+ );
140
+ }
141
+
135
142
}
0 commit comments