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 SummaryFields 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.
 - 
Method SummaryAll 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_PERMISSIONpublic static final Permission ALL_PERMISSION A sharedAllPermissioninstance.
 - 
ALL_PERMISSIONSpublic static final PermissionCollection ALL_PERMISSIONS A read-only permission collection which impliesAllPermission.
 - 
EMPTY_PERMISSION_COLLECTIONpublic static final PermissionCollection EMPTY_PERMISSION_COLLECTION A permission collection which is empty.
 - 
NO_PERMISSIONSpublic static final Permission[] NO_PERMISSIONS An array with no permissions in it.
 
- 
 - 
Method Detail- 
parseActionspublic 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 be- null)
- function- the mapping function (must not be- null)
- Returns:
- the union of all the action bits
- Throws:
- IllegalArgumentException- if- functionthrows this exception (indicating an invalid action string)
 
 - 
parseActionspublic 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 be- null)
- function- the mapping function (must not be- null)
- Returns:
- the union of all the action bits
- Throws:
- IllegalArgumentException- if- functionthrows this exception (indicating an invalid action string)
 
 - 
toActionsStringpublic 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 set
- mappingFunction- the mapping function (must not be- null)
- Returns:
- the actions string (not null)
 
 - 
toActionsStringpublic 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 set
- mappingFunction- the mapping function (must not be- null)
- Returns:
- the actions string (not null)
 
 - 
iterablepublic static Iterable<Permission> iterable(PermissionCollection pc) Create an iterable view over a permission collection.- Parameters:
- pc- the permission collection (must not be- null)
- Returns:
- the iterable view (not null)
 
 - 
forEachInpublic static void forEachIn(PermissionCollection collection, Consumer<Permission> consumer) Perform an action for each permission in the given collection.- Parameters:
- collection- the collection (must not be- null)
- consumer- the consumer to which each permission should be passed (must not be- null)
 
 - 
forEachInpublic 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 be- null)
- parameter- the parameter to pass to the consumer
- consumer- the consumer to which each permission should be passed (must not be- null)
- Returns:
- the parameterthat was passed in
 
 - 
forEachInpublic 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 be- null)
- predicate- the predicate to apply to each element (must not be- null)
- Returns:
- trueif the predicate matched all the permissions in the collection,- falseotherwise
 
 - 
forEachInpublic 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 be- null)
- parameter- the parameter to pass to the consumer
- predicate- the predicate to apply to each element (must not be- null)
- Returns:
- trueif the predicate matched all the permissions in the collection,- falseotherwise
 
 - 
unionpublic 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 be- null)
- pc2- the second permission collection (must not be- null)
- Returns:
- a new permission collection that is the union of the two collections (not null)
 
 - 
intersectionpublic 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 be- null)
- pc2- the second permission collection (must not be- null)
- Returns:
- a new permission collection that is the intersection of the two collections (not null)
 
 - 
impliesAllpublic 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 be- null)
- testCollection- the collection whose permissions are to be tested (must not be- null)
- Returns:
- trueif- collectionimplies all of the permissions in- testCollection,- falseotherwise
 
 - 
equalspublic 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 be- null)
- pc2- the second collection (must not be- null)
- Returns:
- trueif the collections imply one another,- falseotherwise
 
 - 
addAllpublic 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 be- null)
- source- the source collection (must not be- null)
- Returns:
- the target collection (not null)
 
 - 
addAllpublic 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 be- null)
- source- the source collection (must not be- null)
- Returns:
- the target collection (not null)
 
 - 
addpublic 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 be- null)
- source- the permission to add
- Returns:
- the target collection (not null)
 
 - 
createPermissionpublic 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 be- null)
- name- the permission name (may be- nullif allowed by the permission class)
- actions- the permission actions (may be- nullif allowed by the permission class)
- Returns:
- the permission object (not null)
- Throws:
- InvalidPermissionClassException- if the permission class does not exist or is not valid
- ClassCastException- if the class name does not refer to a subclass of- Permission
 
 - 
createPermissionpublic 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 be- null)
- name- the permission name (may be- nullif allowed by the permission class)
- actions- the permission actions (may be- nullif allowed by the permission class)
- Returns:
- the permission object (not null)
- Throws:
- InvalidPermissionClassException- if the permission class does not exist or is not valid
 
 - 
readOnlyCollectionOfpublic 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
 
 
- 
 
-