javax.jdo

## Class LegacyJava

- java.lang.Object
- - javax.jdo.LegacyJava

-     public class LegacyJava
      extends Object

  This class provides wrapper implementations for the Java SecurityManager and AccessController classes that were deprecated in Java 17/18.

  For pre-17 this class provides access to the expected SecurityManager and AccessController. For 17+ the getSecurityManager() will always return 'null' and the doPrivileged() methods will simply execute the lambda argument without any security checks.

  Solution for AccessControl: This class uses reflection to detect whether AccessControl is deprecated. If it is deprecated we provide dummy implementation of 'doPrivileged'. If it is not deprecated we use the original implementation. Implementations are used by finding the desired methods and store them in a static field in LegacyJava. Whenever we need to call a method we can use reflection again to call the stored method in LegacyJava.

  Please note that the call to the stored method needs to happen from the original calling class. We cannot provide such a generic doPrivileged() in LegacyJava because it would be accessible from other classes and thus allow *any* caller to execute *any* code with doPrivileged() with the security context of LegacyJava. For the same reason the doPrivileged() implementations in the calling classes must be *private*.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `LegacyJava.SecurityManager` The SecurityManager is only instantiated if it is not deprecated/removed in the Java API.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Method` | `doPrivilegedAction`
    `static Method` | `doPrivilegedExceptionAction`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LegacyJava()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <T> T` | `doPrivileged(PrivilegedAction<T> privilegedAction)` This is a replacement for the old Java AccessControl.doPrivileged().
    `static <T> T` | `doPrivileged(PrivilegedExceptionAction<T> privilegedAction)` This is a replacement for the old Java AccessControl.doPrivileged().
    `static LegacyJava.SecurityManager` | `getSecurityManager()`
    `static boolean` | `isSecurityManagerDeprecated()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### doPrivilegedAction

          public static final Method doPrivilegedAction

    - #### doPrivilegedExceptionAction

          public static final Method doPrivilegedExceptionAction

  - ### Constructor Detail

    - #### LegacyJava

          public LegacyJava()

  - ### Method Detail

    - #### getSecurityManager

          public static LegacyJava.SecurityManager getSecurityManager()

      Returns:
        A wrapper around the java SecurityManager or 'null' if no SecurityManager is available or if it is deprecated (Java 17 and later).

    - #### isSecurityManagerDeprecated

          public static boolean isSecurityManagerDeprecated()

      Returns:
        'true' if the security manager is deprecated or does not exist.

    - #### doPrivileged

          public static <T> T doPrivileged(PrivilegedAction<T> privilegedAction)

      This is a replacement for the old Java AccessControl.doPrivileged(). This replacement is used when the old doPrivileged() is deprecated or not available. This replacement simply execute the action without any further checks.
      Type Parameters:
        `T` - Return type.
      Parameters:
        `privilegedAction` - The action to execute.
      Returns:
        Return value of the action.

    - #### doPrivileged

          public static <T> T doPrivileged(PrivilegedExceptionAction<T> privilegedAction)
                                    throws PrivilegedActionException

      This is a replacement for the old Java AccessControl.doPrivileged(). This replacement is used when the old doPrivileged() is deprecated or not available. This replacement simply execute the action without any further checks.
      Type Parameters:
        `T` - Return type.
      Parameters:
        `privilegedAction` - The action to execute.
      Returns:
        Return value of the action.
      Throws:
        `PrivilegedActionException` - Never thrown.

Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.