public final class PermissionUtil extends Object
Modifier and Type | Field and Description |
---|---|
static Permission |
ALL_PERMISSION
A shared
AllPermission instance. |
static PermissionCollection |
ALL_PERMISSIONS
A read-only permission collection which implies
AllPermission . |
static PermissionCollection |
EMPTY_PERMISSION_COLLECTION
A permission collection which is empty.
|
static Permission[] |
NO_PERMISSIONS
An array with no permissions in it.
|
Modifier and Type | Method and Description |
---|---|
static PermissionCollection |
add(PermissionCollection target,
Permission source)
Add a permission to a collection, returning 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 PermissionCollection |
addAll(PermissionCollection target,
PermissionCollection 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.
|
public static final Permission ALL_PERMISSION
AllPermission
instance.public static final PermissionCollection ALL_PERMISSIONS
AllPermission
.public static final PermissionCollection EMPTY_PERMISSION_COLLECTION
public static final Permission[] NO_PERMISSIONS
public static int parseActions(String actionsString, ToIntFunction<String> function) throws IllegalArgumentException
actionsString
- the actions string (must not be null
)function
- the mapping function (must not be null
)IllegalArgumentException
- if function
throws this exception (indicating an invalid action string)public static long parseActions(String actionsString, ToLongFunction<String> function) throws IllegalArgumentException
actionsString
- the actions string (must not be null
)function
- the mapping function (must not be null
)IllegalArgumentException
- if function
throws this exception (indicating an invalid action string)public static String toActionsString(int actionBits, IntFunction<String> mappingFunction)
""
is returned.actionBits
- the action bit setmappingFunction
- the mapping function (must not be null
)null
)public static String toActionsString(long actionBits, LongFunction<String> mappingFunction)
""
is returned.actionBits
- the action bit setmappingFunction
- the mapping function (must not be null
)null
)public static Iterable<Permission> iterable(PermissionCollection pc)
pc
- the permission collection (must not be null
)null
)public static void forEachIn(PermissionCollection collection, Consumer<Permission> consumer)
collection
- the collection (must not be null
)consumer
- the consumer to which each permission should be passed (must not be null
)public static <P> P forEachIn(PermissionCollection collection, BiConsumer<P,Permission> consumer, P parameter)
P
- the type of the parametercollection
- the collection (must not be null
)parameter
- the parameter to pass to the consumerconsumer
- the consumer to which each permission should be passed (must not be null
)parameter
that was passed inpublic static boolean forEachIn(PermissionCollection collection, Predicate<Permission> predicate)
false
for any element,
false
is returned; otherwise, true
is returned.collection
- the collection (must not be null
)predicate
- the predicate to apply to each element (must not be null
)true
if the predicate matched all the permissions in the collection, false
otherwisepublic static <P> boolean forEachIn(PermissionCollection collection, BiPredicate<P,Permission> predicate, P parameter)
false
for any element,
false
is returned; otherwise, true
is returned.P
- the type of the parametercollection
- the collection (must not be null
)parameter
- the parameter to pass to the consumerpredicate
- the predicate to apply to each element (must not be null
)true
if the predicate matched all the permissions in the collection, false
otherwisepublic static PermissionCollection union(PermissionCollection pc1, PermissionCollection pc2)
pc1
- the first permission collection (must not be null
)pc2
- the second permission collection (must not be null
)null
)public static PermissionCollection intersection(PermissionCollection pc1, PermissionCollection pc2)
pc1
- the first permission collection (must not be null
)pc2
- the second permission collection (must not be null
)null
)public static boolean impliesAll(PermissionCollection collection, PermissionCollection testCollection)
collection
- the collection to check against (must not be null
)testCollection
- the collection whose permissions are to be tested (must not be null
)true
if collection
implies all of the permissions in testCollection
, false
otherwisepublic static boolean equals(PermissionCollection pc1, PermissionCollection pc2)
pc1
- the first collection (must not be null
)pc2
- the second collection (must not be null
)true
if the collections imply one another, false
otherwisepublic static PermissionCollection addAll(PermissionCollection target, PermissionCollection source)
target
- the target collection (must not be null
)source
- the source collection (must not be null
)null
)public static PermissionCollection addAll(PermissionCollection target, Collection<Permission> source)
target
- the target collection (must not be null
)source
- the source collection (must not be null
)null
)public static PermissionCollection add(PermissionCollection target, Permission source)
null
, it is
not added.target
- the target collection (must not be null
)source
- the permission to addnull
)public static Permission createPermission(ClassLoader classLoader, String className, String name, String actions)
classLoader
- the class loader to search in (null
indicates the system class loader)className
- the name of the permission class to instantiate (must not be null
)name
- the permission name (may be null
if allowed by the permission class)actions
- the permission actions (may be null
if allowed by the permission class)null
)InvalidPermissionClassException
- if the permission class does not exist or is not validClassCastException
- if the class name does not refer to a subclass of Permission
public static Permission createPermission(Class<? extends Permission> permissionClass, String name, String actions)
permissionClass
- the permission class to instantiate (must not be null
)name
- the permission name (may be null
if allowed by the permission class)actions
- the permission actions (may be null
if allowed by the permission class)null
)InvalidPermissionClassException
- if the permission class does not exist or is not validpublic static PermissionCollection readOnlyCollectionOf(Permission... permissions)
permissions
- the permissions to assignCopyright © 2020 JBoss by Red Hat. All rights reserved.