-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Create equivalents of JSM's AccessController in the java agent #18346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
5beafae
e8248de
9afced3
a0a0d9f
cc5a240
a172f67
366406f
53be672
18ccef4
44eb148
00c22c7
3678956
0d6e1b3
d79bdc1
71ba997
9cfa314
435fe93
995c66c
5b04b59
f054131
7e2a98d
cca10f5
1348eeb
9c44efb
e81fdf5
e735773
293fd83
2c8e511
9dc5780
fc6a21b
dc7eafd
9a3f3f2
8950858
c6a61fc
5c32ba2
235bd69
e7270f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.javaagent.bootstrap; | ||
|
||
|
|
||
| import java.util.concurrent.Callable; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * Utility class to run code in a privileged block. | ||
cwperks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public final class AccessController { | ||
| /** | ||
| * Don't allow instantiation an {@code AccessController} | ||
| */ | ||
| private AccessController() {} | ||
|
|
||
| /** | ||
| * Performs the specified action in a privileged block. | ||
| * | ||
| * <p> If the action's {@code run} method throws an (unchecked) | ||
| * exception, it will propagate through this method. | ||
| * | ||
| * @param action the action to be performed | ||
| */ | ||
| public static void doPrivileged(Runnable action) { | ||
| action.run(); | ||
| } | ||
|
Check warning on line 33 in libs/agent-sm/bootstrap/src/main/java/org/opensearch/javaagent/bootstrap/AccessController.java
|
||
|
|
||
| /** | ||
| * Performs the specified action. | ||
| * | ||
| * <p> If the action's {@code run} method throws an <i>unchecked</i> | ||
| * exception, it will propagate through this method. | ||
| * | ||
| * @param <T> the type of the value returned by the | ||
| * PrivilegedExceptionAction's {@code run} method | ||
| * | ||
| * @param action the action to be performed | ||
| * | ||
| * @return the value returned by the action's {@code run} method | ||
| */ | ||
| public static <T> T doPrivileged(Supplier<T> action) { | ||
| return action.get(); | ||
|
Check warning on line 49 in libs/agent-sm/bootstrap/src/main/java/org/opensearch/javaagent/bootstrap/AccessController.java
|
||
| } | ||
|
|
||
| /** | ||
| * Performs the specified action. | ||
| * | ||
| * <p> If the action's {@code run} method throws an <i>unchecked</i> | ||
| * exception, it will propagate through this method. | ||
| * | ||
| * @param <T> the type of the value returned by the | ||
| * PrivilegedExceptionAction's {@code run} method | ||
| * | ||
| * @param action the action to be performed | ||
| * | ||
| * @return the value returned by the action's {@code run} method | ||
| * | ||
| * @throws Exception if the specified action's | ||
| * {@code call} method threw a <i>checked</i> exception | ||
| */ | ||
| public static <T> T doPrivilegedChecked(Callable<T> action) throws Exception { | ||
| return action.call(); | ||
|
Check warning on line 69 in libs/agent-sm/bootstrap/src/main/java/org/opensearch/javaagent/bootstrap/AccessController.java
|
||
| } | ||
|
|
||
| /** | ||
| * Performs the specified action in a privileged block. | ||
| * | ||
| * <p> If the action's {@code run} method throws an (unchecked) | ||
| * exception, it will propagate through this method. | ||
| * | ||
| * @param action the action to be performed | ||
| * | ||
| * @throws T if the specified action's | ||
| * {@code call} method threw a <i>checked</i> exception | ||
| */ | ||
| public static <T extends Exception> void doPrivilegedChecked(CheckedRunnable<T> action) throws T { | ||
| action.run(); | ||
| } | ||
|
Check warning on line 85 in libs/agent-sm/bootstrap/src/main/java/org/opensearch/javaagent/bootstrap/AccessController.java
|
||
|
|
||
| /** | ||
| * A functional interface that represents a runnable action that can throw a checked exception. | ||
| * | ||
| * @param <E> the type of the exception that can be thrown | ||
| */ | ||
| public interface CheckedRunnable<E extends Exception> { | ||
|
|
||
| /** | ||
| * Executes the action. | ||
| * | ||
| * @throws E | ||
| */ | ||
| void run() throws E; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.