Class AccessController

java.lang.Object
org.opensearch.secure_sm.AccessController

public final class AccessController extends Object
A utility class that provides methods to perform actions in a privileged context. This class is a replacement for Java's java.security.AccessController functionality which is marked for removal. All new code should use this class instead of the JDK's AccessController. Running code in a privileged context will ensure that the code has the necessary permissions without traversing through the entire call stack. See org.opensearch.javaagent.StackCallerProtectionDomainChainExtractor Example usages:
 
 AccessController.doPrivileged(() -> {
     // code that requires privileges
 });
 
 
Example usage with a return value and checked exception:
 
 T something = AccessController.doPrivilegedChecked(() -> {
     // code that requires privileges and may throw a checked exception
     return something;
     // or
     throw new Exception();
 });
 
 
  • Method Details

    • doPrivileged

      public static void doPrivileged(Runnable action)
      Performs the specified action in a privileged block.

      If the action's run method throws an (unchecked) exception, it will propagate through this method.

      Parameters:
      action - the action to be performed
    • doPrivileged

      public static <T> T doPrivileged(Supplier<T> action)
      Performs the specified action.

      If the action's run method throws an unchecked exception, it will propagate through this method.

      Type Parameters:
      T - the type of the value returned by the PrivilegedExceptionAction's run method
      Parameters:
      action - the action to be performed
      Returns:
      the value returned by the action's run method
    • doPrivilegedChecked

      public static <T> T doPrivilegedChecked(Callable<T> action) throws Exception
      Performs the specified action.

      If the action's run method throws an unchecked exception, it will propagate through this method.

      Type Parameters:
      T - the type of the value returned by the PrivilegedExceptionAction's run method
      Parameters:
      action - the action to be performed
      Returns:
      the value returned by the action's run method
      Throws:
      Exception - if the specified action's call method threw a checked exception
    • doPrivilegedChecked

      public static <T extends Exception> void doPrivilegedChecked(AccessController.CheckedRunnable<T> action) throws T
      Performs the specified action in a privileged block.

      If the action's run method throws an (unchecked) exception, it will propagate through this method.

      Parameters:
      action - the action to be performed
      Throws:
      T - if the specified action's call method threw a checked exception