Class SecurityManagerWrapperImpl

java.lang.Object
com.tangosol.net.security.SecurityManagerWrapperImpl
All Implemented Interfaces:
SecurityManagerWrapper

public class SecurityManagerWrapperImpl extends Object implements 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 or 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

      public Subject getCurrentSubject()
      Description copied from interface: SecurityManagerWrapper
      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().

      Specified by:
      getCurrentSubject in interface SecurityManagerWrapper
      Returns:
      the current subject, or null if a current subject is not installed or the current subject is set to null
    • hasSecurityManager

      public boolean hasSecurityManager()
      Description copied from interface: SecurityManagerWrapper
      Return true if the JVM is running with a security manager enabled.
      Specified by:
      hasSecurityManager in interface SecurityManagerWrapper
      Returns:
      true if the JVM is running with a security manager enabled
    • doIfSecure

      public <T> T doIfSecure(PrivilegedAction<T> action)
      Description copied from interface: SecurityManagerWrapper
      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.

      Specified by:
      doIfSecure in interface SecurityManagerWrapper
      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.
    • doIfSecure

      public <T> T doIfSecure(PrivilegedExceptionAction<T> action) throws Exception
      Description copied from interface: SecurityManagerWrapper
      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.

      Specified by:
      doIfSecure in interface SecurityManagerWrapper
      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
    • doIfSecure

      public void doIfSecure(PrivilegedAction<?> action, Runnable fallback)
      Description copied from interface: SecurityManagerWrapper
      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.

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

      public <T> T doIfSecure(PrivilegedAction<T> action, Supplier<T> fallback)
      Specified by:
      doIfSecure in interface SecurityManagerWrapper
    • doPrivileged

      public <T> T doPrivileged(PrivilegedAction<T> action)
      Description copied from interface: SecurityManagerWrapper
      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.
      Specified by:
      doPrivileged in interface SecurityManagerWrapper
      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.
    • doPrivileged

      public <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException
      Description copied from interface: SecurityManagerWrapper
      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.
      Specified by:
      doPrivileged in interface SecurityManagerWrapper
      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
    • checkPermission

      public void checkPermission(Supplier<Permission> supplier)
      Description copied from interface: SecurityManagerWrapper
      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.

      Specified by:
      checkPermission in interface SecurityManagerWrapper
      Parameters:
      supplier - a Supplier to provide the permission to check
    • checkPermission

      public void checkPermission(Permission permission)
      Description copied from interface: SecurityManagerWrapper
      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

      Specified by:
      checkPermission in interface SecurityManagerWrapper
      Parameters:
      permission - the requested permission.