org.apache.catalina.security

## Class SecurityUtil

- java.lang.Object
- - org.apache.catalina.security.SecurityUtil

-     public final class SecurityUtil
      extends Object

  This utility class associates a `Subject` to the current `AccessControlContext`. When a `SecurityManager` is used, the container will always associate the called thread with an AccessControlContext containing only the principal of the requested Servlet/Filter. This class uses reflection to invoke the methods.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SecurityUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `doAsPrivilege(String methodName, Filter targetObject)` Perform work as a particular `Subject`.
    `static void` | `doAsPrivilege(String methodName, Filter targetObject, Class<?>[] targetType, Object[] targetArguments)` Perform work as a particular `Subject`.
    `static void` | `doAsPrivilege(String methodName, Filter targetObject, Class<?>[] targetParameterTypes, Object[] targetParameterValues, Principal principal)` Perform work as a particular `Subject`.
    `static void` | `doAsPrivilege(String methodName, Servlet targetObject)` Perform work as a particular `Subject`.
    `static void` | `doAsPrivilege(String methodName, Servlet targetObject, Class<?>[] targetType, Object[] targetArguments)` Perform work as a particular `Subject`.
    `static void` | `doAsPrivilege(String methodName, Servlet targetObject, Class<?>[] targetParameterTypes, Object[] targetArguments, Principal principal)` Perform work as a particular `Subject`.
    `static boolean` | `isPackageProtectionEnabled()` Return the `SecurityManager` only if Security is enabled AND package protection mechanism is enabled.
    `static void` | `remove(Object cachedObject)` Remove the object from the cache.

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

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

- - ### Constructor Detail

    - #### SecurityUtil

          public SecurityUtil()

  - ### Method Detail

    - #### doAsPrivilege

          public static void doAsPrivilege(String methodName,
                           Servlet targetObject)
                                    throws Exception

      Perform work as a particular `Subject`. Here the work will be granted to a `null` subject.
      Parameters:
        `methodName` - the method to apply the security restriction
        `targetObject` - the `Servlet` on which the method will be called.
      Throws:
        `Exception` - an execution error occurred

    - #### doAsPrivilege

          public static void doAsPrivilege(String methodName,
                           Servlet targetObject,
                           Class<?>[] targetType,
                           Object[] targetArguments)
                                    throws Exception

      Perform work as a particular `Subject`. Here the work will be granted to a `null` subject.
      Parameters:
        `methodName` - the method to apply the security restriction
        `targetObject` - the `Servlet` on which the method will be called.
        `targetType` - `Class` array used to instantiate a `Method` object.
        `targetArguments` - `Object` array contains the runtime parameters instance.
      Throws:
        `Exception` - an execution error occurred

    - #### doAsPrivilege

          public static void doAsPrivilege(String methodName,
                           Servlet targetObject,
                           Class<?>[] targetParameterTypes,
                           Object[] targetArguments,
                           Principal principal)
                                    throws Exception

      Perform work as a particular `Subject`. Here the work will be granted to a `null` subject.
      Parameters:
        `methodName` - the method to apply the security restriction
        `targetObject` - the `Servlet` on which the method will be called.
        `targetParameterTypes` - `Class` array used to instantiate a `Method` object.
        `targetArguments` - `Object` array contains the runtime parameters instance.
        `principal` - the `Principal` to which the security privilege applies
      Throws:
        `Exception` - an execution error occurred

    - #### doAsPrivilege

          public static void doAsPrivilege(String methodName,
                           Filter targetObject)
                                    throws Exception

      Perform work as a particular `Subject`. Here the work will be granted to a `null` subject.
      Parameters:
        `methodName` - the method to apply the security restriction
        `targetObject` - the `Filter` on which the method will be called.
      Throws:
        `Exception` - an execution error occurred

    - #### doAsPrivilege

          public static void doAsPrivilege(String methodName,
                           Filter targetObject,
                           Class<?>[] targetType,
                           Object[] targetArguments)
                                    throws Exception

      Perform work as a particular `Subject`. Here the work will be granted to a `null` subject.
      Parameters:
        `methodName` - the method to apply the security restriction
        `targetObject` - the `Filter` on which the method will be called.
        `targetType` - `Class` array used to instantiate a `Method` object.
        `targetArguments` - `Object` array contains the runtime parameters instance.
      Throws:
        `Exception` - an execution error occurred

    - #### doAsPrivilege

          public static void doAsPrivilege(String methodName,
                           Filter targetObject,
                           Class<?>[] targetParameterTypes,
                           Object[] targetParameterValues,
                           Principal principal)
                                    throws Exception

      Perform work as a particular `Subject`. Here the work will be granted to a `null` subject.
      Parameters:
        `methodName` - the method to apply the security restriction
        `targetObject` - the `Filter` on which the method will be called.
        `targetParameterTypes` - `Class` array used to instantiate a `Method` object.
        `targetParameterValues` - `Object` array contains the runtime parameters instance.
        `principal` - the `Principal` to which the security privilege applies
      Throws:
        `Exception` - an execution error occurred

    - #### remove

          public static void remove(Object cachedObject)

      Remove the object from the cache.
      Parameters:
        `cachedObject` - The object to remove

    - #### isPackageProtectionEnabled

          public static boolean isPackageProtectionEnabled()

      Return the `SecurityManager` only if Security is enabled AND package protection mechanism is enabled.
      Returns:
        `true` if package level protection is enabled

Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.