Package org.wildfly.security.manager
Class WildFlySecurityManager
java.lang.Object
java.lang.SecurityManager
org.wildfly.security.manager.WildFlySecurityManager
- All Implemented Interfaces:
PermissionVerifier
@MetaInfServices(java.lang.SecurityManager.class)
public final class WildFlySecurityManager
extends SecurityManager
implements PermissionVerifier
The security manager. This security manager implementation can be switched on and off on a per-thread basis,
and additionally logs access violations in a way that should be substantially clearer than most JDK implementations.
- Author:
- David M. Lloyd
-
Field Summary
Fields inherited from interface org.wildfly.security.permission.PermissionVerifier
ALL, NONE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckAccept(String host, int port) voidvoidvoidcheckConnect(String host, int port) voidcheckConnect(String host, int port, Object context) voidvoidcheckDelete(String file) voidvoidcheckExit(int status) voidvoidcheckListen(int port) voidcheckMemberAccess(Class<?> clazz, int which) Deprecated.voidcheckMulticast(InetAddress maddr) voidcheckMulticast(InetAddress maddr, byte ttl) Deprecated.voidcheckPackageAccess(String pkg) voidvoidcheckPermission(Permission perm) Perform a permission check.voidcheckPermission(Permission perm, Object context) Perform a permission check.voidcheckPermission(Permission perm, AccessControlContext context) Perform a permission check.voidvoidvoidvoidvoidvoidvoidcheckSecurityAccess(String target) voidvoidvoidcheckWrite(String file) static StringClear a property, doing a faster permission check that skips having to execute a privileged action frame.static <T> TdoChecked(PrivilegedAction<T> action) Perform an action with permission checking enabled.static <T> TdoChecked(PrivilegedAction<T> action, AccessControlContext context) Perform an action with permission checking enabled.static <T> TdoChecked(PrivilegedExceptionAction<T> action) Perform an action with permission checking enabled.static <T> TdoChecked(PrivilegedExceptionAction<T> action, AccessControlContext context) Perform an action with permission checking enabled.static <T,P> T doChecked(P parameter, ParametricPrivilegedAction<T, P> action) Perform an action with permission checking enabled.static <T,P> T doChecked(P parameter, ParametricPrivilegedAction<T, P> action, AccessControlContext context) Perform an action with permission checking enabled.static <T,P> T doChecked(P parameter, ParametricPrivilegedExceptionAction<T, P> action) Perform an action with permission checking enabled.static <T,P> T doChecked(P parameter, ParametricPrivilegedExceptionAction<T, P> action, AccessControlContext context) Perform an action with permission checking enabled.static <T,P> T doPrivilegedWithParameter(P parameter, ParametricPrivilegedAction<T, P> action) Execute a parametric privileged action with the given parameter in a privileged context.static <T,P> T doPrivilegedWithParameter(P parameter, ParametricPrivilegedAction<T, P> action, AccessControlContext accessControlContext) Execute a parametric privileged action with the given parameter with the given context.static <T,P> T doPrivilegedWithParameter(P parameter, ParametricPrivilegedExceptionAction<T, P> action) Execute a parametric privileged action with the given parameter in a privileged context.static <T,P> T doPrivilegedWithParameter(P parameter, ParametricPrivilegedExceptionAction<T, P> action, AccessControlContext accessControlContext) Execute a parametric privileged action with the given parameter with the given context.static <T> TdoUnchecked(PrivilegedAction<T> action) Perform an action with permission checking disabled.static <T> TdoUnchecked(PrivilegedAction<T> action, AccessControlContext context) Perform an action with permission checking disabled.static <T> TdoUnchecked(PrivilegedExceptionAction<T> action) Perform an action with permission checking disabled.static <T> TdoUnchecked(PrivilegedExceptionAction<T> action, AccessControlContext context) Perform an action with permission checking disabled.static <T,P> T doUnchecked(P parameter, ParametricPrivilegedAction<T, P> action) Perform an action with permission checking disabled.static <T,P> T doUnchecked(P parameter, ParametricPrivilegedAction<T, P> action, AccessControlContext context) Perform an action with permission checking disabled.static <T,P> T doUnchecked(P parameter, ParametricPrivilegedExceptionAction<T, P> action) Perform an action with permission checking disabled.static <T,P> T doUnchecked(P parameter, ParametricPrivilegedExceptionAction<T, P> action, AccessControlContext context) Perform an action with permission checking disabled.static ProtectionDomainfindAccessDenial(Permission permission, ProtectionDomain... domains) Find the protection domain in the given list which denies a permission, ornullif the permission check would pass.static ClassLoadergetClassLoaderPrivileged(Class<?> clazz) Get the class loader for a class, doing a faster permission check that skips having to execute a privileged action frame.static ClassLoaderGet the current thread's context class loader, doing a faster permission check that skips having to execute a privileged action frame.static StringgetEnvPropertyPrivileged(String name, String def) Get an environmental property, doing a faster permission check that skips having to execute a privileged action frame.static StringgetPropertyPrivileged(String name, String def) Get a property, doing a faster permission check that skips having to execute a privileged action frame.Get the system environment map, doing a faster permission check that skips having to execute a privileged action frame.static PropertiesGet the system properties map, doing a faster permission check that skips having to execute a privileged action frame.booleanimplies(Permission permission) Determine if the permission is verified by this object.static voidinstall()Deprecated.static booleanDetermine whether the security manager is currently checking permissions.static ClassLoadersetCurrentContextClassLoaderPrivileged(Class<?> clazz) Set the current thread's context class loader, doing a faster permission check that skips having to execute a privileged action frame.static ClassLoadersetCurrentContextClassLoaderPrivileged(ClassLoader newClassLoader) Set the current thread's context class loader, doing a faster permission check that skips having to execute a privileged action frame.static StringsetPropertyPrivileged(String name, String value) Set a property, doing a faster permission check that skips having to execute a privileged action frame.static booleantryCheckPermission(Permission permission, ProtectionDomain... domains) Try a permission check.Methods inherited from class java.lang.SecurityManager
getClassContext, getSecurityContext, getThreadGroupMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.wildfly.security.permission.PermissionVerifier
and, not, or, toPermissionCollection, unless, xor
-
Constructor Details
-
WildFlySecurityManager
Construct a new instance. If the caller does not have permission to do so, this method will throw an exception.- Throws:
SecurityException- if the caller does not have permission to create a security manager instance
-
-
Method Details
-
install
Deprecated.- Throws:
SecurityException
-
isChecking
public static boolean isChecking()Determine whether the security manager is currently checking permissions.- Returns:
trueif the security manager is currently checking permissions
-
checkPermission
Perform a permission check.- Specified by:
checkPermissionin interfacePermissionVerifier- Overrides:
checkPermissionin classSecurityManager- Parameters:
perm- the permission to check- Throws:
SecurityException- if the check fails
-
checkPermission
Perform a permission check.- Overrides:
checkPermissionin classSecurityManager- Parameters:
perm- the permission to checkcontext- the security context to use for the check (must be anAccessControlContextinstance)- Throws:
SecurityException- if the check fails
-
findAccessDenial
Find the protection domain in the given list which denies a permission, ornullif the permission check would pass.- Parameters:
permission- the permission to testdomains- the protection domains to try- Returns:
- the first denying protection domain, or
nullif there is none
-
tryCheckPermission
Try a permission check. Any violations will be logged to theorg.wildfly.security.accesscategory at aDEBUGlevel.- Parameters:
permission- the permission to checkdomains- the protection domains to try- Returns:
trueif the access check succeeded,falseotherwise
-
implies
Description copied from interface:PermissionVerifierDetermine if the permission is verified by this object.- Specified by:
impliesin interfacePermissionVerifier- Parameters:
permission- the permission to verify (must not benull)- Returns:
trueif the permission is implied by this verifier,falseotherwise
-
checkPermission
Perform a permission check.- Parameters:
perm- the permission to checkcontext- the security context to use for the check- Throws:
SecurityException- if the check fails
-
checkCreateClassLoader
public void checkCreateClassLoader()- Overrides:
checkCreateClassLoaderin classSecurityManager
-
checkAccess
- Overrides:
checkAccessin classSecurityManager
-
checkAccess
- Overrides:
checkAccessin classSecurityManager
-
checkExit
public void checkExit(int status) - Overrides:
checkExitin classSecurityManager
-
checkExec
- Overrides:
checkExecin classSecurityManager
-
checkLink
- Overrides:
checkLinkin classSecurityManager
-
checkRead
- Overrides:
checkReadin classSecurityManager
-
checkRead
- Overrides:
checkReadin classSecurityManager
-
checkRead
- Overrides:
checkReadin classSecurityManager
-
checkWrite
- Overrides:
checkWritein classSecurityManager
-
checkWrite
- Overrides:
checkWritein classSecurityManager
-
checkDelete
- Overrides:
checkDeletein classSecurityManager
-
checkConnect
- Overrides:
checkConnectin classSecurityManager
-
checkConnect
- Overrides:
checkConnectin classSecurityManager
-
checkListen
public void checkListen(int port) - Overrides:
checkListenin classSecurityManager
-
checkAccept
- Overrides:
checkAcceptin classSecurityManager
-
checkMulticast
- Overrides:
checkMulticastin classSecurityManager
-
checkMulticast
Deprecated.- Overrides:
checkMulticastin classSecurityManager
-
checkPropertiesAccess
public void checkPropertiesAccess()- Overrides:
checkPropertiesAccessin classSecurityManager
-
checkPropertyAccess
- Overrides:
checkPropertyAccessin classSecurityManager
-
checkPrintJobAccess
public void checkPrintJobAccess()- Overrides:
checkPrintJobAccessin classSecurityManager
-
checkPackageAccess
- Overrides:
checkPackageAccessin classSecurityManager
-
checkPackageDefinition
- Overrides:
checkPackageDefinitionin classSecurityManager
-
checkSetFactory
public void checkSetFactory()- Overrides:
checkSetFactoryin classSecurityManager
-
checkMemberAccess
Deprecated. -
checkSecurityAccess
- Overrides:
checkSecurityAccessin classSecurityManager
-
doChecked
Perform an action with permission checking enabled. If permission checking is already enabled, the action is simply run.- Type Parameters:
T- the action return type- Parameters:
action- the action to perform- Returns:
- the return value of the action
-
doChecked
Perform an action with permission checking enabled. If permission checking is already enabled, the action is simply run.- Type Parameters:
T- the action return type- Parameters:
action- the action to perform- Returns:
- the return value of the action
- Throws:
PrivilegedActionException- if the action threw an exception
-
doChecked
Perform an action with permission checking enabled. If permission checking is already enabled, the action is simply run.- Type Parameters:
T- the action return type- Parameters:
action- the action to performcontext- the access control context to use- Returns:
- the return value of the action
-
doChecked
public static <T> T doChecked(PrivilegedExceptionAction<T> action, AccessControlContext context) throws PrivilegedActionException Perform an action with permission checking enabled. If permission checking is already enabled, the action is simply run.- Type Parameters:
T- the action return type- Parameters:
action- the action to performcontext- the access control context to use- Returns:
- the return value of the action
- Throws:
PrivilegedActionException- if the action threw an exception
-
doChecked
Perform an action with permission checking enabled. If permission checking is already enabled, the action is simply run.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- the action to perform- Returns:
- the return value of the action
-
doChecked
public static <T,P> T doChecked(P parameter, ParametricPrivilegedExceptionAction<T, P> action) throws PrivilegedActionExceptionPerform an action with permission checking enabled. If permission checking is already enabled, the action is simply run.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- the action to perform- Returns:
- the return value of the action
- Throws:
PrivilegedActionException- if the action threw an exception
-
doChecked
public static <T,P> T doChecked(P parameter, ParametricPrivilegedAction<T, P> action, AccessControlContext context) Perform an action with permission checking enabled. If permission checking is already enabled, the action is simply run.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- the action to performcontext- the access control context to use- Returns:
- the return value of the action
-
doChecked
public static <T,P> T doChecked(P parameter, ParametricPrivilegedExceptionAction<T, P> action, AccessControlContext context) throws PrivilegedActionExceptionPerform an action with permission checking enabled. If permission checking is already enabled, the action is simply run.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- the action to performcontext- the access control context to use- Returns:
- the return value of the action
- Throws:
PrivilegedActionException- if the action threw an exception
-
doUnchecked
Perform an action with permission checking disabled. If permission checking is already disabled, the action is simply run. The immediate caller must have thedoUncheckedruntime permission.- Type Parameters:
T- the action return type- Parameters:
action- the action to perform- Returns:
- the return value of the action
-
doUnchecked
public static <T> T doUnchecked(PrivilegedExceptionAction<T> action) throws PrivilegedActionException Perform an action with permission checking disabled. If permission checking is already disabled, the action is simply run. The caller must have thedoUncheckedruntime permission.- Type Parameters:
T- the action return type- Parameters:
action- the action to perform- Returns:
- the return value of the action
- Throws:
PrivilegedActionException- if the action threw an exception
-
doUnchecked
Perform an action with permission checking disabled. If permission checking is already disabled, the action is simply run. The immediate caller must have thedoUncheckedruntime permission.- Type Parameters:
T- the action return type- Parameters:
action- the action to performcontext- the access control context to use- Returns:
- the return value of the action
-
doUnchecked
public static <T> T doUnchecked(PrivilegedExceptionAction<T> action, AccessControlContext context) throws PrivilegedActionException Perform an action with permission checking disabled. If permission checking is already disabled, the action is simply run. The caller must have thedoUncheckedruntime permission.- Type Parameters:
T- the action return type- Parameters:
action- the action to performcontext- the access control context to use- Returns:
- the return value of the action
- Throws:
PrivilegedActionException- if the action threw an exception
-
doUnchecked
Perform an action with permission checking disabled. If permission checking is already disabled, the action is simply run. The immediate caller must have thedoUncheckedruntime permission.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- the action to perform- Returns:
- the return value of the action
-
doUnchecked
public static <T,P> T doUnchecked(P parameter, ParametricPrivilegedExceptionAction<T, P> action) throws PrivilegedActionExceptionPerform an action with permission checking disabled. If permission checking is already disabled, the action is simply run. The caller must have thedoUncheckedruntime permission.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- the action to perform- Returns:
- the return value of the action
- Throws:
PrivilegedActionException- if the action threw an exception
-
doUnchecked
public static <T,P> T doUnchecked(P parameter, ParametricPrivilegedAction<T, P> action, AccessControlContext context) Perform an action with permission checking disabled. If permission checking is already disabled, the action is simply run. The immediate caller must have thedoUncheckedruntime permission.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- the action to performcontext- the access control context to use- Returns:
- the return value of the action
-
doUnchecked
public static <T,P> T doUnchecked(P parameter, ParametricPrivilegedExceptionAction<T, P> action, AccessControlContext context) throws PrivilegedActionExceptionPerform an action with permission checking disabled. If permission checking is already disabled, the action is simply run. The caller must have thedoUncheckedruntime permission.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- the action to performcontext- the access control context to use- Returns:
- the return value of the action
- Throws:
PrivilegedActionException- if the action threw an exception
-
getPropertyPrivileged
Get a property, doing a faster permission check that skips having to execute a privileged action frame.- Parameters:
name- the property namedef- the default value if the property is not found- Returns:
- the property value, or the default value
-
getEnvPropertyPrivileged
Get an environmental property, doing a faster permission check that skips having to execute a privileged action frame.- Parameters:
name- the property namedef- the default value if the property is not found- Returns:
- the property value, or the default value
-
setPropertyPrivileged
Set a property, doing a faster permission check that skips having to execute a privileged action frame.- Parameters:
name- the property namevalue- the value ot set- Returns:
- the previous property value, or
nullif there was none
-
clearPropertyPrivileged
Clear a property, doing a faster permission check that skips having to execute a privileged action frame.- Parameters:
name- the property name- Returns:
- the previous property value, or
nullif there was none
-
getCurrentContextClassLoaderPrivileged
Get the current thread's context class loader, doing a faster permission check that skips having to execute a privileged action frame.- Returns:
- the context class loader
-
setCurrentContextClassLoaderPrivileged
Set the current thread's context class loader, doing a faster permission check that skips having to execute a privileged action frame.- Parameters:
newClassLoader- the new class loader to set- Returns:
- the previously set context class loader
-
setCurrentContextClassLoaderPrivileged
Set the current thread's context class loader, doing a faster permission check that skips having to execute a privileged action frame.- Parameters:
clazz- the class whose class loader is the new class loader to set- Returns:
- the previously set context class loader
-
getSystemPropertiesPrivileged
Get the system properties map, doing a faster permission check that skips having to execute a privileged action frame.- Returns:
- the system property map
-
getSystemEnvironmentPrivileged
Get the system environment map, doing a faster permission check that skips having to execute a privileged action frame.- Returns:
- the system environment map
-
getClassLoaderPrivileged
Get the class loader for a class, doing a faster permission check that skips having to execute a privileged action frame.- Parameters:
clazz- the class to check- Returns:
- the class loader
-
doPrivilegedWithParameter
public static <T,P> T doPrivilegedWithParameter(P parameter, ParametricPrivilegedAction<T, P> action) Execute a parametric privileged action with the given parameter in a privileged context.- Type Parameters:
T- the action result typeP- the parameter type- Parameters:
parameter- the parameter to send in to the actionaction- the action to execute- Returns:
- the action result
-
doPrivilegedWithParameter
public static <T,P> T doPrivilegedWithParameter(P parameter, ParametricPrivilegedExceptionAction<T, P> action) throws PrivilegedActionExceptionExecute a parametric privileged action with the given parameter in a privileged context.- Type Parameters:
T- the action result typeP- the parameter type- Parameters:
parameter- the parameter to send in to the actionaction- the action to execute- Returns:
- the action result
- Throws:
PrivilegedActionException
-
doPrivilegedWithParameter
public static <T,P> T doPrivilegedWithParameter(P parameter, ParametricPrivilegedAction<T, P> action, AccessControlContext accessControlContext) Execute a parametric privileged action with the given parameter with the given context.- Type Parameters:
T- the action result typeP- the parameter type- Parameters:
parameter- the parameter to send in to the actionaction- the action to executeaccessControlContext- the context to use- Returns:
- the action result
-
doPrivilegedWithParameter
public static <T,P> T doPrivilegedWithParameter(P parameter, ParametricPrivilegedExceptionAction<T, P> action, AccessControlContext accessControlContext) throws PrivilegedActionExceptionExecute a parametric privileged action with the given parameter with the given context.- Type Parameters:
T- the action result typeP- the parameter type- Parameters:
parameter- the parameter to send in to the actionaction- the action to executeaccessControlContext- the context to use- Returns:
- the action result
- Throws:
PrivilegedActionException
-