Package org.cyclos.impl.utils
Class PermissionHelper
- java.lang.Object
-
- org.cyclos.impl.utils.PermissionHelper
-
public class PermissionHelper extends Object
Contains helper methods for permission checks
-
-
Constructor Summary
Constructors Constructor Description PermissionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Set<Role>allRoles(RoleContainer container)Returns all roles the given role container hasstatic <E,A extends E>
Set<E>applyAllowed(Collection<E> selection, Collection<A> allowed)Used for query filter semantics with collections.static <T> voidcheckContains(Collection<? super T> allowed, T element)Throws aPermissionDeniedExceptionif allowed is empty or not contains the given elementstatic voidcheckContainsId(Collection<? extends IEntity> entities, Long id)Checks whether the given entity collection contains the given idstatic voidcheckEmpty(Collection<?> collection)Throws aPermissionDeniedExceptionif the given collection is not emptystatic voidcheckEquals(Object expected, Object actual)Throws aPermissionDeniedExceptionif expected is not the same as actualstatic voidcheckNotEmpty(Collection<?> collection)Throws aPermissionDeniedExceptionif the given collection is emptystatic voidcheckNotNull(Object object)Throws aPermissionDeniedExceptionif the given object is nullstatic <T> Collection<T>checkSelection(Collection<T> allowed, Collection<T> selection)Same ascheckSelection(Collection, Collection, boolean)but not supporting an empty collection for the allowed elements.static <T> Collection<T>checkSelection(Collection<T> allowed, Collection<T> selection, boolean isEmptyAllowedSupported)Used for query filter semantics with collections.
Given a collection with the selected elements and another one with the allowed elements:
If the allowed elements are empty (and empty for the allowed is not supported) it throws a PermissionDeniedException.static booleanhasRole(RoleContainer container, Role role)Returns whether the givenRoleContainerhas the givenRole
-
-
-
Method Detail
-
allRoles
public static Set<Role> allRoles(RoleContainer container)
Returns all roles the given role container has
-
applyAllowed
public static <E,A extends E> Set<E> applyAllowed(Collection<E> selection, Collection<A> allowed) throws PermissionDeniedException
Used for query filter semantics with collections. Returns the selected elements that are allowed (i.e contained in the allowed collection). If the allowed collection is empty or if the result of remove the not allowed elements from the selection is empty then it throwPermissionDeniedException.- Throws:
PermissionDeniedException
-
checkContains
public static <T> void checkContains(Collection<? super T> allowed, T element)
Throws aPermissionDeniedExceptionif allowed is empty or not contains the given element
-
checkContainsId
public static void checkContainsId(Collection<? extends IEntity> entities, Long id)
Checks whether the given entity collection contains the given id
-
checkEmpty
public static void checkEmpty(Collection<?> collection)
Throws aPermissionDeniedExceptionif the given collection is not empty
-
checkEquals
public static void checkEquals(Object expected, Object actual)
Throws aPermissionDeniedExceptionif expected is not the same as actual
-
checkNotEmpty
public static void checkNotEmpty(Collection<?> collection)
Throws aPermissionDeniedExceptionif the given collection is empty
-
checkNotNull
public static void checkNotNull(Object object)
Throws aPermissionDeniedExceptionif the given object is null
-
checkSelection
public static <T> Collection<T> checkSelection(Collection<T> allowed, Collection<T> selection)
Same ascheckSelection(Collection, Collection, boolean)but not supporting an empty collection for the allowed elements.
-
checkSelection
public static <T> Collection<T> checkSelection(Collection<T> allowed, Collection<T> selection, boolean isEmptyAllowedSupported)
Used for query filter semantics with collections.
Given a collection with the selected elements and another one with the allowed elements:
If the allowed elements are empty (and empty for the allowed is not supported) it throws a PermissionDeniedException. Else, if elements is empty, then allowed is returned. Otherwise, the selected elements must be contained in the allowed collection.
-
hasRole
public static boolean hasRole(RoleContainer container, Role role)
Returns whether the givenRoleContainerhas the givenRole
-
-