Interface SecurityManagerWrapper
This class is here to allow for pre-Java24 code that still uses a SecurityManager 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
Subject getCurrentSubject()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()
.- Returns:
- the current subject, or null if a current subject is not installed or the current subject is set to null
-
hasSecurityManager
boolean hasSecurityManager()Returntrue
if the JVM is running with a security manager enabled.- Returns:
true
if the JVM is running with a security manager enabled
-
doIfSecure
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.
- 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.
- Throws:
NullPointerException
- – if the action is null
-
doIfSecure
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.
- 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 exceptionNullPointerException
- – if the action is nullException
-
doIfSecure
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.
- Parameters:
action
- the action to be performed.fallback
- theRunnable
to execute if the JVM is not running with a security manager
-
doIfSecure
-
doPrivileged
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.- 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.
- Throws:
NullPointerException
- – if the action is null
-
doPrivileged
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.- 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 exceptionNullPointerException
- – if the action is null
-
checkPermission
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.
- Parameters:
supplier
- aSupplier
to provide the permission to check- Throws:
SecurityException
- if access is not permitted based on the current security policy.NullPointerException
- if the permission argument is null.
-
checkPermission
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
- Parameters:
permission
- the requested permission.- Throws:
SecurityException
- if access is not permitted based on the current security policy.NullPointerException
- if the permission argument is null.
-