1515import org .elasticsearch .entitlement .runtime .api .ElasticsearchEntitlementChecker ;
1616import org .elasticsearch .entitlement .runtime .policy .PathLookup ;
1717import org .elasticsearch .entitlement .runtime .policy .Policy ;
18+ import org .elasticsearch .entitlement .runtime .policy .PolicyChecker ;
19+ import org .elasticsearch .entitlement .runtime .policy .PolicyCheckerImpl ;
1820import org .elasticsearch .entitlement .runtime .policy .PolicyManager ;
1921
2022import java .lang .instrument .Instrumentation ;
@@ -75,25 +77,6 @@ public static void initialize(Instrumentation inst) throws Exception {
7577 );
7678 }
7779
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-
9780 /**
9881 * If bytecode verification is enabled, ensure these classes get loaded before transforming/retransforming them.
9982 * 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() {
11396 }
11497
11598 private static ElasticsearchEntitlementChecker initChecker () {
116- final PolicyManager policyManager = createPolicyManager ();
99+ final PolicyChecker policyChecker = createPolicyChecker ();
117100
118101 final Class <?> clazz = EntitlementCheckerUtils .getVersionSpecificCheckerClass (
119102 ElasticsearchEntitlementChecker .class ,
@@ -122,14 +105,38 @@ private static ElasticsearchEntitlementChecker initChecker() {
122105
123106 Constructor <?> constructor ;
124107 try {
125- constructor = clazz .getConstructor (PolicyManager .class );
108+ constructor = clazz .getConstructor (PolicyChecker .class );
126109 } 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 );
128111 }
129112 try {
130- return (ElasticsearchEntitlementChecker ) constructor .newInstance (policyManager );
113+ return (ElasticsearchEntitlementChecker ) constructor .newInstance (policyChecker );
131114 } catch (IllegalAccessException | InvocationTargetException | InstantiationException e ) {
132115 throw new AssertionError (e );
133116 }
134117 }
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+
135142}
0 commit comments