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 PermissionALL_PERMISSIONA sharedAllPermissioninstance.static PermissionCollectionALL_PERMISSIONSA read-only permission collection which impliesAllPermission.static PermissionCollectionEMPTY_PERMISSION_COLLECTIONA permission collection which is empty.static Permission[]NO_PERMISSIONSAn array with no permissions in it.
-
Constructor Summary
Constructors Modifier Constructor Description privatePermissionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PermissionCollectionadd(PermissionCollection target, Permission source)Add a permission to a collection, returning the target collection.static PermissionCollectionaddAll(PermissionCollection target, PermissionCollection source)Add all of the permissions from the source collection to the target collection.static PermissionCollectionaddAll(PermissionCollection target, Collection<Permission> source)Add all of the permissions from the source collection to the target collection.static PermissioncreatePermission(Class<? extends Permission> permissionClass, String name, String actions)Instantiate a permission with the given class, permission name, and actions.static PermissioncreatePermission(ClassLoader classLoader, String className, String name, String actions)Instantiate a permission with the given class name, permission name, and actions.static booleanequals(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> PforEachIn(PermissionCollection collection, BiConsumer<P,Permission> consumer, P parameter)Perform an action for each permission in the given collection.static <P> booleanforEachIn(PermissionCollection collection, BiPredicate<P,Permission> predicate, P parameter)Run a test for each permission in the given collection.static voidforEachIn(PermissionCollection collection, Consumer<Permission> consumer)Perform an action for each permission in the given collection.static booleanforEachIn(PermissionCollection collection, Predicate<Permission> predicate)Run a test for each permission in the given collection.static booleanimpliesAll(PermissionCollection collection, PermissionCollection testCollection)Determine if one collection implies all the permissions in the other collection.static PermissionCollectionintersection(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 intparseActions(String actionsString, ToIntFunction<String> function)Parse an actions string, using the given function to map action strings to bits.static longparseActions(String actionsString, ToLongFunction<String> function)Parse an actions string, using the given function to map action strings to bits.static PermissionCollectionreadOnlyCollectionOf(Permission... permissions)Get a read-only collection of the given permissions.static StringtoActionsString(int actionBits, IntFunction<String> mappingFunction)Deparse an action bit set, using the given function to map action bits to strings.static StringtoActionsString(long actionBits, LongFunction<String> mappingFunction)Deparse an action bit set, using the given function to map action bits to strings.static PermissionCollectionunion(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 sharedAllPermissioninstance.
-
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- iffunctionthrows 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- iffunctionthrows 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
parameterthat 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 returnsfalsefor any element,falseis returned; otherwise,trueis returned.- Parameters:
collection- the collection (must not benull)predicate- the predicate to apply to each element (must not benull)- Returns:
trueif the predicate matched all the permissions in the collection,falseotherwise
-
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 returnsfalsefor any element,falseis returned; otherwise,trueis 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:
trueif the predicate matched all the permissions in the collection,falseotherwise
-
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:
trueifcollectionimplies all of the permissions intestCollection,falseotherwise
-
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:
trueif the collections imply one another,falseotherwise
-
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 (nullindicates the system class loader)className- the name of the permission class to instantiate (must not benull)name- the permission name (may benullif allowed by the permission class)actions- the permission actions (may benullif 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 benullif allowed by the permission class)actions- the permission actions (may benullif 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
-
-