mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-24 15:17:30 -04:00
Implementing the correct exit functions (Runtime) (#118657)
This commit is contained in:
parent
44a231acf2
commit
1bad1cf6b2
4 changed files with 25 additions and 9 deletions
|
@ -13,7 +13,11 @@ import java.net.URL;
|
|||
import java.net.URLStreamHandlerFactory;
|
||||
|
||||
public interface EntitlementChecker {
|
||||
void check$java_lang_System$exit(Class<?> callerClass, int status);
|
||||
|
||||
// Exit the JVM process
|
||||
void check$$exit(Class<?> callerClass, Runtime runtime, int status);
|
||||
|
||||
void check$$halt(Class<?> callerClass, Runtime runtime, int status);
|
||||
|
||||
// URLClassLoader ctor
|
||||
void check$java_net_URLClassLoader$(Class<?> callerClass, URL[] urls);
|
||||
|
|
|
@ -47,14 +47,21 @@ public class RestEntitlementsCheckAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
private static final Map<String, CheckAction> checkActions = Map.ofEntries(
|
||||
entry("system_exit", CheckAction.serverOnly(RestEntitlementsCheckAction::systemExit)),
|
||||
entry("runtime_exit", CheckAction.serverOnly(RestEntitlementsCheckAction::runtimeExit)),
|
||||
entry("runtime_halt", CheckAction.serverOnly(RestEntitlementsCheckAction::runtimeHalt)),
|
||||
entry("create_classloader", CheckAction.serverAndPlugin(RestEntitlementsCheckAction::createClassLoader))
|
||||
);
|
||||
|
||||
@SuppressForbidden(reason = "Specifically testing System.exit")
|
||||
private static void systemExit() {
|
||||
logger.info("Calling System.exit(123);");
|
||||
System.exit(123);
|
||||
@SuppressForbidden(reason = "Specifically testing Runtime.exit")
|
||||
private static void runtimeExit() {
|
||||
logger.info("Calling Runtime.exit;");
|
||||
Runtime.getRuntime().exit(123);
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "Specifically testing Runtime.halt")
|
||||
private static void runtimeHalt() {
|
||||
logger.info("Calling Runtime.halt;");
|
||||
Runtime.getRuntime().halt(123);
|
||||
}
|
||||
|
||||
private static void createClassLoader() {
|
||||
|
|
|
@ -28,7 +28,12 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void check$java_lang_System$exit(Class<?> callerClass, int status) {
|
||||
public void check$$exit(Class<?> callerClass, Runtime runtime, int status) {
|
||||
policyManager.checkExitVM(callerClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check$$halt(Class<?> callerClass, Runtime runtime, int status) {
|
||||
policyManager.checkExitVM(callerClass);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ public class Java23ElasticsearchEntitlementChecker extends ElasticsearchEntitlem
|
|||
}
|
||||
|
||||
@Override
|
||||
public void check$java_lang_System$exit(Class<?> callerClass, int status) {
|
||||
public void check$$exit(Class<?> callerClass, Runtime runtime, 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);
|
||||
super.check$$exit(callerClass, runtime, status);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue