Class EntitlementInitialization
java.lang.Object
org.elasticsearch.entitlement.initialization.EntitlementInitialization
Called by the agent during
agentmain to configure the entitlement system,
instantiate and configure an EntitlementChecker,
make it available to the bootstrap library via checker(),
and then install the Instrumenter
to begin injecting our instrumentation.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic EntitlementCheckerchecker()static voidinitialize(Instrumentation inst) Initializes the Entitlement system: Finds the version-specific subclass ofEntitlementCheckerto use Builds the set of methods to instrument usingInstrumentationService.lookupMethods(java.lang.Class<?>)Augment this set “dynamically” usingInstrumentationService.lookupImplementationMethod(java.lang.Class<?>, java.lang.String, java.lang.Class<?>, java.lang.Class<?>, java.lang.String, java.lang.Class<?>...)Creates anInstrumenterviaInstrumentationService.newInstrumenter(java.lang.Class<?>, java.util.Map<org.elasticsearch.entitlement.instrumentation.MethodKey, org.elasticsearch.entitlement.instrumentation.CheckMethod>), and adds a newTransformer(derived fromClassFileTransformer) that uses it.
-
Constructor Details
-
EntitlementInitialization
public EntitlementInitialization()
-
-
Method Details
-
checker
-
initialize
Initializes the Entitlement system:-
Finds the version-specific subclass of
EntitlementCheckerto use -
Builds the set of methods to instrument using
InstrumentationService.lookupMethods(java.lang.Class<?>) -
Augment this set “dynamically” using
InstrumentationService.lookupImplementationMethod(java.lang.Class<?>, java.lang.String, java.lang.Class<?>, java.lang.Class<?>, java.lang.String, java.lang.Class<?>...) -
Creates an
InstrumenterviaInstrumentationService.newInstrumenter(java.lang.Class<?>, java.util.Map<org.elasticsearch.entitlement.instrumentation.MethodKey, org.elasticsearch.entitlement.instrumentation.CheckMethod>), and adds a newTransformer(derived fromClassFileTransformer) that uses it. Transformers are invoked when a class is about to load, after its bytes have been deserialized to memory but before the class is initialized. -
Re-transforms all already loaded classes: we force the
Instrumenterto run on classes that might have been already loaded before entitlement initialization by calling theInstrumentation.retransformClasses(java.lang.Class<?>...)method on all classes that were already loaded.
The third step is needed as the JDK exposes some API through interfaces that have different (internal) implementations depending on the JVM host platform. As we cannot instrument an interfaces, we find its concrete implementation. A prime example is
FileSystemProvider, which has different implementations (e.g.UnixFileSystemProviderorWindowsFileSystemProvider). At runtime, we find the implementation class which is currently used by the JVM, and add its methods to the set of methods to instrument. See e.g.fileSystemProviderChecks().NOTE: this method is referenced by the agent reflectively
- Parameters:
inst- the JVM instrumentation class instance- Throws:
Exception
-
Finds the version-specific subclass of
-