Class SecurityManagerWrapperImpl
- All Implemented Interfaces:
SecurityManagerWrapper
This class allows code that still uses a SecurityManager or
AccessController to work on Java 21 through 23. The Java 24 and
later implementation is in the coherence-core-24 multi-release
layer.
- Author:
- Jonathan Knight 25/01/2025
-
Method Summary
Modifier and TypeMethodDescriptionvoidcheckPermission(Permission permission) Throws aSecurityExceptionif the requested access, specified by the given permission, is not permitted based on the security policy currently in effect.voidcheckPermission(Supplier<Permission> supplier) Throws aSecurityExceptionif the requested access, specified by the given permission, is not permitted based on the security policy currently in effect.voiddoIfSecure(PrivilegedAction<?> action, Runnable fallback) Performs the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run thefallbackrunnable.<T> TdoIfSecure(PrivilegedAction<T> action) Performs the specified PrivilegedAction with privileges enabled or if the JVM is running without a security manager this method just callsPrivilegedAction.run().<T> TdoIfSecure(PrivilegedAction<T> action, Supplier<T> fallback) Performs the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run thefallbackrunnable.<T> TdoIfSecure(PrivilegedExceptionAction<T> action) Performs the specified PrivilegedExceptionAction with privileges enabled or if the JVM is running without a security manager this method just callsPrivilegedAction.run().voiddoIfSecure(Supplier<PrivilegedAction<?>> supplier, Runnable fallback) Performs the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run thefallbackrunnable.<T> TdoIfSecure(Supplier<PrivilegedAction<T>> supplier, Supplier<T> fallback) Performs the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run thefallbackrunnable.<T> TdoIfSecureInDoAsAction(PrivilegedAction<T> action, Supplier<T> fallback) <T> TdoIfSecureInDoAsAction(Supplier<PrivilegedAction<T>> supplier, Supplier<T> fallback) <T> TdoPrivileged(PrivilegedAction<T> action) Performs the specified PrivilegedAction with privileges enabled.<T> TdoPrivileged(PrivilegedExceptionAction<T> action) Performs the specified PrivilegedExceptionAction with privileges enabled.Returns the current subject.booleanReturntrueif the JVM is running with a security manager enabled.
-
Method Details
-
getCurrentSubject
Description copied from interface:SecurityManagerWrapperReturns 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 ofcallAs().- Specified by:
getCurrentSubjectin interfaceSecurityManagerWrapper- 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:SecurityManagerWrapperReturntrueif the JVM is running with a security manager enabled.- Specified by:
hasSecurityManagerin interfaceSecurityManagerWrapper- Returns:
trueif the JVM is running with a security manager enabled
-
doIfSecure
Description copied from interface:SecurityManagerWrapperPerforms the specified PrivilegedAction with privileges enabled or if the JVM is running without a security manager this method just callsPrivilegedAction.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:
doIfSecurein interfaceSecurityManagerWrapper- 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
Description copied from interface:SecurityManagerWrapperPerforms the specified PrivilegedExceptionAction with privileges enabled or if the JVM is running without a security manager this method just callsPrivilegedAction.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:
doIfSecurein interfaceSecurityManagerWrapper- 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
Description copied from interface:SecurityManagerWrapperPerforms the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run thefallbackrunnable.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:
doIfSecurein interfaceSecurityManagerWrapper- Parameters:
action- the action to be performed.fallback- theRunnableto execute if the JVM is not running with a security manager
-
doIfSecure
Description copied from interface:SecurityManagerWrapperPerforms the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run thefallbackrunnable.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:
doIfSecurein interfaceSecurityManagerWrapper- Parameters:
supplier- aSupplierto provide the action to be performed.fallback- theRunnableto execute if the JVM is not running with a security manager
-
doIfSecure
Description copied from interface:SecurityManagerWrapperPerforms the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run thefallbackrunnable.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:
doIfSecurein interfaceSecurityManagerWrapper- Parameters:
action- the action to be performed.fallback- theSupplierto execute if the JVM is not running with a security manager
-
doIfSecureInDoAsAction
- Specified by:
doIfSecureInDoAsActionin interfaceSecurityManagerWrapper
-
doIfSecureInDoAsAction
- Specified by:
doIfSecureInDoAsActionin interfaceSecurityManagerWrapper
-
doIfSecure
Description copied from interface:SecurityManagerWrapperPerforms the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run thefallbackrunnable.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:
doIfSecurein interfaceSecurityManagerWrapper- Parameters:
supplier- aSupplierto provide the action to be performed.fallback- theSupplierto execute if the JVM is not running with a security manager
-
doPrivileged
Description copied from interface:SecurityManagerWrapperPerforms 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:
doPrivilegedin interfaceSecurityManagerWrapper- 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
Description copied from interface:SecurityManagerWrapperPerforms 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:
doPrivilegedin interfaceSecurityManagerWrapper- 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
Description copied from interface:SecurityManagerWrapperThrows aSecurityExceptionif 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:
checkPermissionin interfaceSecurityManagerWrapper- Parameters:
supplier- aSupplierto provide the permission to check
-
checkPermission
Description copied from interface:SecurityManagerWrapperThrows aSecurityExceptionif 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:
checkPermissionin interfaceSecurityManagerWrapper- Parameters:
permission- the requested permission.
-