Interface SecurityManagerWrapper


public interface SecurityManagerWrapper
A wrapper to handle the removal of Java's SecurityManger class.

This class is here to allow for pre-Java24 code that still uses a SecurityManager AccessController to work. There post-Java24 version of this class is in the coherence-core-24 module and is built into the multi-release coherence.jar.

Author:
Jonathan Knight 25/01/2025
  • Method Details

    • getCurrentSubject

      Subject getCurrentSubject()
      Returns the current subject.

      The current subject is installed by the callAs method. When callAs(subject, action) is called, action is executed with subject as its current subject which can be retrieved by this method. After action is finished, the current subject is reset to its previous value. The current subject is null before the first call of callAs().

      Returns:
      the current subject, or null if a current subject is not installed or the current subject is set to null
    • hasSecurityManager

      boolean hasSecurityManager()
      Return true if the JVM is running with a security manager enabled.
      Returns:
      true if the JVM is running with a security manager enabled
    • doIfSecure

      <T> T doIfSecure(PrivilegedAction<T> action)
      Performs the specified PrivilegedAction with privileges enabled or if the JVM is running without a security manager this method just calls PrivilegedAction.run().

      The action is performed with all the permissions possessed by the caller's protection domain. If the action's run method throws an (unchecked) exception, it will propagate through this method. Note that any DomainCombiner associated with the current AccessControlContext will be ignored while the action is performed.

      Type Parameters:
      T - the type of the value returned by the PrivilegedAction's run method.
      Parameters:
      action - the action to be performed.
      Returns:
      the value returned by the action's run method.
      Throws:
      NullPointerException - – if the action is null
    • doIfSecure

      <T> T doIfSecure(PrivilegedExceptionAction<T> action) throws Exception
      Performs the specified PrivilegedExceptionAction with privileges enabled or if the JVM is running without a security manager this method just calls PrivilegedAction.run().

      The action is performed with all the permissions possessed by the caller's protection domain. If the action's run method throws an unchecked exception, it will propagate through this method. Note that any DomainCombiner associated with the current AccessControlContext will be ignored while the action is performed.

      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:
      PrivilegedActionException - – if the specified action's run method threw a checked exception
      NullPointerException - – if the action is null
      Exception
    • doIfSecure

      void doIfSecure(PrivilegedAction<?> action, Runnable fallback)
      Performs the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run the fallback runnable.

      The action is performed with all the permissions possessed by the caller's protection domain. If the action's run method throws an (unchecked) exception, it will propagate through this method. Note that any DomainCombiner associated with the current AccessControlContext will be ignored while the action is performed.

      Parameters:
      action - the action to be performed.
      fallback - the Runnable to execute if the JVM is not running with a security manager
    • doIfSecure

      <T> T doIfSecure(PrivilegedAction<T> action, Supplier<T> fallback)
    • doPrivileged

      <T> T doPrivileged(PrivilegedAction<T> action)
      Performs the specified PrivilegedAction with privileges enabled. The action is performed with all the permissions possessed by the caller's protection domain. If the action's run method throws an (unchecked) exception, it will propagate through this method. Note that any DomainCombiner associated with the current AccessControlContext will be ignored while the action is performed.
      Type Parameters:
      T - the type of the value returned by the PrivilegedAction's run method.
      Parameters:
      action - the action to be performed.
      Returns:
      the value returned by the action's run method.
      Throws:
      NullPointerException - – if the action is null
    • doPrivileged

      <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException
      Performs the specified PrivilegedExceptionAction with privileges enabled. The action is performed with all the permissions possessed by the caller's protection domain. If the action's run method throws an unchecked exception, it will propagate through this method. Note that any DomainCombiner associated with the current AccessControlContext will be ignored while the action is performed.
      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:
      PrivilegedActionException - – if the specified action's run method threw a checked exception
      NullPointerException - – if the action is null
    • checkPermission

      void checkPermission(Supplier<Permission> supplier)
      Throws a SecurityException if the requested access, specified by the given permission, is not permitted based on the security policy currently in effect.

      This method calls AccessController.checkPermission with the given permission.

      Parameters:
      supplier - a Supplier to provide the permission to check
      Throws:
      SecurityException - if access is not permitted based on the current security policy.
      NullPointerException - if the permission argument is null.
    • checkPermission

      void checkPermission(Permission permission)
      Throws a SecurityException if the requested access, specified by the given permission, is not permitted based on the security policy currently in effect.

      This method calls AccessController.checkPermission with the given permission

      Parameters:
      permission - the requested permission.
      Throws:
      SecurityException - if access is not permitted based on the current security policy.
      NullPointerException - if the permission argument is null.