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
DynamicInstrumentation .initialize (inst , latestCheckerInterface , verifyBytecode );
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
@@ -117,7 +100,7 @@ private static void ensureClassesSensitiveToVerificationAreInitialized() {
117
100
}
118
101
119
102
private static ElasticsearchEntitlementChecker initChecker () {
120
- final PolicyManager policyManager = createPolicyManager ();
103
+ final PolicyChecker policyChecker = createPolicyChecker ();
121
104
122
105
final Class <?> clazz = EntitlementCheckerUtils .getVersionSpecificCheckerClass (
123
106
ElasticsearchEntitlementChecker .class ,
@@ -126,14 +109,38 @@ private static ElasticsearchEntitlementChecker initChecker() {
126
109
127
110
Constructor <?> constructor ;
128
111
try {
129
- constructor = clazz .getConstructor (PolicyManager .class );
112
+ constructor = clazz .getConstructor (PolicyChecker .class );
130
113
} catch (NoSuchMethodException e ) {
131
- throw new AssertionError ("entitlement impl is missing no arg constructor" , e );
114
+ throw new AssertionError ("entitlement impl is missing required constructor: [" + clazz . getName () + "] " , e );
132
115
}
133
116
try {
134
- return (ElasticsearchEntitlementChecker ) constructor .newInstance (policyManager );
117
+ return (ElasticsearchEntitlementChecker ) constructor .newInstance (policyChecker );
135
118
} catch (IllegalAccessException | InvocationTargetException | InstantiationException e ) {
136
119
throw new AssertionError (e );
137
120
}
138
121
}
122
+
123
+ private static PolicyCheckerImpl createPolicyChecker () {
124
+ EntitlementBootstrap .BootstrapArgs bootstrapArgs = EntitlementBootstrap .bootstrapArgs ();
125
+ Map <String , Policy > pluginPolicies = bootstrapArgs .pluginPolicies ();
126
+ PathLookup pathLookup = bootstrapArgs .pathLookup ();
127
+
128
+ FilesEntitlementsValidation .validate (pluginPolicies , pathLookup );
129
+
130
+ PolicyManager policyManager = new PolicyManager (
131
+ HardcodedEntitlements .serverPolicy (pathLookup .pidFile (), bootstrapArgs .serverPolicyPatch ()),
132
+ HardcodedEntitlements .agentEntitlements (),
133
+ pluginPolicies ,
134
+ EntitlementBootstrap .bootstrapArgs ().scopeResolver (),
135
+ EntitlementBootstrap .bootstrapArgs ().sourcePaths (),
136
+ pathLookup
137
+ );
138
+ return new PolicyCheckerImpl (
139
+ bootstrapArgs .suppressFailureLogPackages (),
140
+ ENTITLEMENTS_MODULE ,
141
+ policyManager ,
142
+ bootstrapArgs .pathLookup ()
143
+ );
144
+ }
145
+
139
146
}
0 commit comments