Class SecurityManagerWrapperImpl
- All Implemented Interfaces:
SecurityManagerWrapper
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 Summary
Modifier and TypeMethodDescriptionvoid
checkPermission
(Permission permission) Throws aSecurityException
if the requested access, specified by the given permission, is not permitted based on the security policy currently in effect.void
checkPermission
(Supplier<Permission> supplier) Throws aSecurityException
if the requested access, specified by the given permission, is not permitted based on the security policy currently in effect.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 thefallback
runnable.<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 callsPrivilegedAction.run()
.<T> T
doIfSecure
(PrivilegedAction<T> action, Supplier<T> fallback) <T> T
doIfSecure
(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()
.<T> T
doPrivileged
(PrivilegedAction<T> action) Performs the specified PrivilegedAction with privileges enabled.<T> T
doPrivileged
(PrivilegedExceptionAction<T> action) Performs the specified PrivilegedExceptionAction with privileges enabled.Returns the current subject.boolean
Returntrue
if the JVM is running with a security manager enabled.
-
Method Details
-
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 ofcallAs()
.- Specified by:
getCurrentSubject
in 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:SecurityManagerWrapper
Returntrue
if the JVM is running with a security manager enabled.- Specified by:
hasSecurityManager
in interfaceSecurityManagerWrapper
- Returns:
true
if the JVM is running with a security manager enabled
-
doIfSecure
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 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:
doIfSecure
in 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:SecurityManagerWrapper
Performs 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:
doIfSecure
in 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:SecurityManagerWrapper
Performs the specified PrivilegedAction with privileges enabled if the JVM is running with a security manager enabled otherwise run thefallback
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 interfaceSecurityManagerWrapper
- Parameters:
action
- the action to be performed.fallback
- theRunnable
to execute if the JVM is not running with a security manager
-
doIfSecure
- Specified by:
doIfSecure
in interfaceSecurityManagerWrapper
-
doPrivileged
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 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: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 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:SecurityManagerWrapper
Throws aSecurityException
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 interfaceSecurityManagerWrapper
- Parameters:
supplier
- aSupplier
to provide the permission to check
-
checkPermission
Description copied from interface:SecurityManagerWrapper
Throws aSecurityException
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 interfaceSecurityManagerWrapper
- Parameters:
permission
- the requested permission.
-