forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add java version variants of entitlements checker (elastic#116878)
As each version of Java is released, there may be additional methods we want to instrument for entitlements. Since new methods won't exist in the base version of Java that Elasticsearch is compiled with, we need to hava different classes and compilation for each version. This commit adds a scaffolding for adding the classes for new versions of Java. Unfortunately it requires several classes in different locations. But hopefully these are infrequent enough that the boilerplate is ok. We could consider adding a helper Gradle task to templatize the new classes in the future if it is too cumbersome. Note that the example for Java23 does not have anything meaningful in it yet, it's only meant as an example until we find go through classes and methods that were added after Java 21.
- Loading branch information
Showing
10 changed files
with
201 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/HandleLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.entitlement.bridge; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
class HandleLoader { | ||
|
||
static <T extends EntitlementChecker> T load(Class<T> checkerClass) { | ||
String initClassName = "org.elasticsearch.entitlement.initialization.EntitlementInitialization"; | ||
final Class<?> initClazz; | ||
try { | ||
initClazz = ClassLoader.getSystemClassLoader().loadClass(initClassName); | ||
} catch (ClassNotFoundException e) { | ||
throw new AssertionError("java.base cannot find entitlement initialization", e); | ||
} | ||
final Method checkerMethod; | ||
try { | ||
checkerMethod = initClazz.getMethod("checker"); | ||
} catch (NoSuchMethodException e) { | ||
throw new AssertionError("EntitlementInitialization is missing checker() method", e); | ||
} | ||
try { | ||
return checkerClass.cast(checkerMethod.invoke(null)); | ||
} catch (IllegalAccessException | InvocationTargetException e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
|
||
// no instance | ||
private HandleLoader() {} | ||
} |
12 changes: 12 additions & 0 deletions
12
...bridge/src/main23/java/org/elasticsearch/entitlement/bridge/Java23EntitlementChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.entitlement.bridge; | ||
|
||
public interface Java23EntitlementChecker extends EntitlementChecker {} |
27 changes: 27 additions & 0 deletions
27
.../src/main23/java/org/elasticsearch/entitlement/bridge/Java23EntitlementCheckerHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.entitlement.bridge; | ||
|
||
/** | ||
* Java23 variant of {@link EntitlementChecker} handle holder. | ||
*/ | ||
public class Java23EntitlementCheckerHandle { | ||
|
||
public static Java23EntitlementChecker instance() { | ||
return Holder.instance; | ||
} | ||
|
||
private static class Holder { | ||
private static final Java23EntitlementChecker instance = HandleLoader.load(Java23EntitlementChecker.class); | ||
} | ||
|
||
// no construction | ||
private Java23EntitlementCheckerHandle() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...java/org/elasticsearch/entitlement/runtime/api/Java23ElasticsearchEntitlementChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.entitlement.runtime.api; | ||
|
||
import org.elasticsearch.entitlement.bridge.Java23EntitlementChecker; | ||
import org.elasticsearch.entitlement.runtime.policy.PolicyManager; | ||
|
||
public class Java23ElasticsearchEntitlementChecker extends ElasticsearchEntitlementChecker implements Java23EntitlementChecker { | ||
|
||
public Java23ElasticsearchEntitlementChecker(PolicyManager policyManager) { | ||
super(policyManager); | ||
} | ||
|
||
@Override | ||
public void check$java_lang_System$exit(Class<?> callerClass, int status) { | ||
// TODO: this is just an example, we shouldn't really override a method implemented in the superclass | ||
super.check$java_lang_System$exit(callerClass, status); | ||
} | ||
} |