Package org.wildfly.security.permission
Class PermissionUtil
- java.lang.Object
-
- org.wildfly.security.permission.PermissionUtil
-
public final class PermissionUtil extends Object
General permission utility methods and constants.- Author:
- David M. Lloyd
-
-
Field Summary
Fields Modifier and Type Field Description static Permission
ALL_PERMISSION
A sharedAllPermission
instance.static PermissionCollection
ALL_PERMISSIONS
A read-only permission collection which impliesAllPermission
.static PermissionCollection
EMPTY_PERMISSION_COLLECTION
A permission collection which is empty.static Permission[]
NO_PERMISSIONS
An array with no permissions in it.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PermissionCollection
add(PermissionCollection target, Permission source)
Add a permission to a collection, returning the target collection.static PermissionCollection
addAll(PermissionCollection target, PermissionCollection source)
Add all of the permissions from the source collection to the target collection.static PermissionCollection
addAll(PermissionCollection target, Collection<Permission> source)
Add all of the permissions from the source collection to the target collection.static Permission
createPermission(Class<? extends Permission> permissionClass, String name, String actions)
Instantiate a permission with the given class, permission name, and actions.static Permission
createPermission(ClassLoader classLoader, String className, String name, String actions)
Instantiate a permission with the given class name, permission name, and actions.static boolean
equals(PermissionCollection pc1, PermissionCollection pc2)
Determine if two permission collections are equal, that is, each collection implies all of the permissions in the other collection.static <P> P
forEachIn(PermissionCollection collection, BiConsumer<P,Permission> consumer, P parameter)
Perform an action for each permission in the given collection.static <P> boolean
forEachIn(PermissionCollection collection, BiPredicate<P,Permission> predicate, P parameter)
Run a test for each permission in the given collection.static void
forEachIn(PermissionCollection collection, Consumer<Permission> consumer)
Perform an action for each permission in the given collection.static boolean
forEachIn(PermissionCollection collection, Predicate<Permission> predicate)
Run a test for each permission in the given collection.static boolean
impliesAll(PermissionCollection collection, PermissionCollection testCollection)
Determine if one collection implies all the permissions in the other collection.static PermissionCollection
intersection(PermissionCollection pc1, PermissionCollection pc2)
Create a permission collection that is the intersection of two permission collections.static Iterable<Permission>
iterable(PermissionCollection pc)
Create an iterable view over a permission collection.static int
parseActions(String actionsString, ToIntFunction<String> function)
Parse an actions string, using the given function to map action strings to bits.static long
parseActions(String actionsString, ToLongFunction<String> function)
Parse an actions string, using the given function to map action strings to bits.static PermissionCollection
readOnlyCollectionOf(Permission... permissions)
Get a read-only collection of the given permissions.static String
toActionsString(int actionBits, IntFunction<String> mappingFunction)
Deparse an action bit set, using the given function to map action bits to strings.static String
toActionsString(long actionBits, LongFunction<String> mappingFunction)
Deparse an action bit set, using the given function to map action bits to strings.static PermissionCollection
union(PermissionCollection pc1, PermissionCollection pc2)
Create a permission collection that is the union of two permission collections.
-
-
-
Field Detail
-
ALL_PERMISSION
public static final Permission ALL_PERMISSION
A sharedAllPermission
instance.
-
ALL_PERMISSIONS
public static final PermissionCollection ALL_PERMISSIONS
A read-only permission collection which impliesAllPermission
.
-
EMPTY_PERMISSION_COLLECTION
public static final PermissionCollection EMPTY_PERMISSION_COLLECTION
A permission collection which is empty.
-
NO_PERMISSIONS
public static final Permission[] NO_PERMISSIONS
An array with no permissions in it.
-
-
Method Detail
-
parseActions
public static int parseActions(String actionsString, ToIntFunction<String> function) throws IllegalArgumentException
Parse an actions string, using the given function to map action strings to bits.- Parameters:
actionsString
- the actions string (must not benull
)function
- the mapping function (must not benull
)- Returns:
- the union of all the action bits
- Throws:
IllegalArgumentException
- iffunction
throws this exception (indicating an invalid action string)
-
parseActions
public static long parseActions(String actionsString, ToLongFunction<String> function) throws IllegalArgumentException
Parse an actions string, using the given function to map action strings to bits.- Parameters:
actionsString
- the actions string (must not benull
)function
- the mapping function (must not benull
)- Returns:
- the union of all the action bits
- Throws:
IllegalArgumentException
- iffunction
throws this exception (indicating an invalid action string)
-
toActionsString
public static String toActionsString(int actionBits, IntFunction<String> mappingFunction)
Deparse an action bit set, using the given function to map action bits to strings. If the bits are all clear, the empty string""
is returned.- Parameters:
actionBits
- the action bit setmappingFunction
- the mapping function (must not benull
)- Returns:
- the actions string (not
null
)
-
toActionsString
public static String toActionsString(long actionBits, LongFunction<String> mappingFunction)
Deparse an action bit set, using the given function to map action bits to strings. If the bits are all clear, the empty string""
is returned.- Parameters:
actionBits
- the action bit setmappingFunction
- the mapping function (must not benull
)- Returns:
- the actions string (not
null
)
-
iterable
public static Iterable<Permission> iterable(PermissionCollection pc)
Create an iterable view over a permission collection.- Parameters:
pc
- the permission collection (must not benull
)- Returns:
- the iterable view (not
null
)
-
forEachIn
public static void forEachIn(PermissionCollection collection, Consumer<Permission> consumer)
Perform an action for each permission in the given collection.- Parameters:
collection
- the collection (must not benull
)consumer
- the consumer to which each permission should be passed (must not benull
)
-
forEachIn
public static <P> P forEachIn(PermissionCollection collection, BiConsumer<P,Permission> consumer, P parameter)
Perform an action for each permission in the given collection.- Type Parameters:
P
- the type of the parameter- Parameters:
collection
- the collection (must not benull
)parameter
- the parameter to pass to the consumerconsumer
- the consumer to which each permission should be passed (must not benull
)- Returns:
- the
parameter
that was passed in
-
forEachIn
public static boolean forEachIn(PermissionCollection collection, Predicate<Permission> predicate)
Run a test for each permission in the given collection. If the predicate returnsfalse
for any element,false
is returned; otherwise,true
is returned.- Parameters:
collection
- the collection (must not benull
)predicate
- the predicate to apply to each element (must not benull
)- Returns:
true
if the predicate matched all the permissions in the collection,false
otherwise
-
forEachIn
public static <P> boolean forEachIn(PermissionCollection collection, BiPredicate<P,Permission> predicate, P parameter)
Run a test for each permission in the given collection. If the predicate returnsfalse
for any element,false
is returned; otherwise,true
is returned.- Type Parameters:
P
- the type of the parameter- Parameters:
collection
- the collection (must not benull
)parameter
- the parameter to pass to the consumerpredicate
- the predicate to apply to each element (must not benull
)- Returns:
true
if the predicate matched all the permissions in the collection,false
otherwise
-
union
public static PermissionCollection union(PermissionCollection pc1, PermissionCollection pc2)
Create a permission collection that is the union of two permission collections. The permission collections must be read-only.- Parameters:
pc1
- the first permission collection (must not benull
)pc2
- the second permission collection (must not benull
)- Returns:
- a new permission collection that is the union of the two collections (not
null
)
-
intersection
public static PermissionCollection intersection(PermissionCollection pc1, PermissionCollection pc2)
Create a permission collection that is the intersection of two permission collections. The permission collections must be read-only.- Parameters:
pc1
- the first permission collection (must not benull
)pc2
- the second permission collection (must not benull
)- Returns:
- a new permission collection that is the intersection of the two collections (not
null
)
-
impliesAll
public static boolean impliesAll(PermissionCollection collection, PermissionCollection testCollection)
Determine if one collection implies all the permissions in the other collection.- Parameters:
collection
- the collection to check against (must not benull
)testCollection
- the collection whose permissions are to be tested (must not benull
)- Returns:
true
ifcollection
implies all of the permissions intestCollection
,false
otherwise
-
equals
public static boolean equals(PermissionCollection pc1, PermissionCollection pc2)
Determine if two permission collections are equal, that is, each collection implies all of the permissions in the other collection.- Parameters:
pc1
- the first collection (must not benull
)pc2
- the second collection (must not benull
)- Returns:
true
if the collections imply one another,false
otherwise
-
addAll
public static PermissionCollection addAll(PermissionCollection target, PermissionCollection source)
Add all of the permissions from the source collection to the target collection.- Parameters:
target
- the target collection (must not benull
)source
- the source collection (must not benull
)- Returns:
- the target collection (not
null
)
-
addAll
public static PermissionCollection addAll(PermissionCollection target, Collection<Permission> source)
Add all of the permissions from the source collection to the target collection.- Parameters:
target
- the target collection (must not benull
)source
- the source collection (must not benull
)- Returns:
- the target collection (not
null
)
-
add
public static PermissionCollection add(PermissionCollection target, Permission source)
Add a permission to a collection, returning the target collection. If the permission isnull
, it is not added.- Parameters:
target
- the target collection (must not benull
)source
- the permission to add- Returns:
- the target collection (not
null
)
-
createPermission
public static Permission createPermission(ClassLoader classLoader, String className, String name, String actions)
Instantiate a permission with the given class name, permission name, and actions.- Parameters:
classLoader
- the class loader to search in (null
indicates the system class loader)className
- the name of the permission class to instantiate (must not benull
)name
- the permission name (may benull
if allowed by the permission class)actions
- the permission actions (may benull
if allowed by the permission class)- Returns:
- the permission object (not
null
) - Throws:
InvalidPermissionClassException
- if the permission class does not exist or is not validClassCastException
- if the class name does not refer to a subclass ofPermission
-
createPermission
public static Permission createPermission(Class<? extends Permission> permissionClass, String name, String actions)
Instantiate a permission with the given class, permission name, and actions.- Parameters:
permissionClass
- the permission class to instantiate (must not benull
)name
- the permission name (may benull
if allowed by the permission class)actions
- the permission actions (may benull
if allowed by the permission class)- Returns:
- the permission object (not
null
) - Throws:
InvalidPermissionClassException
- if the permission class does not exist or is not valid
-
readOnlyCollectionOf
public static PermissionCollection readOnlyCollectionOf(Permission... permissions)
Get a read-only collection of the given permissions.- Parameters:
permissions
- the permissions to assign- Returns:
- the read-only collection
-
-