Class PermissionUtils


  • public class PermissionUtils
    extends Object
    Convenience methods used for processing permissions and authorities
    Author:
    Phillip Verheyden (phillipuniverse)
    • Method Detail

      • expandAllPermission

        public static List<String> expandAllPermission​(@NonNull
                                                       String permission)
        Transforms a given permission into the expanded version with all of the permission types. For example, given a permission ALL_PRODUCT this will return [CREATE_PRODUCT, READ_PRODUCT, UPDATE_PRODUCT, DELETE_PRODUCT]. Note that the result set will not include the given permission which means that if the given permission does not start with ALL_ then an empty list is returned
        Parameters:
        permission - a permission that starts with ALL_
        Returns:
        the CRUD-expanded ALL_ permission or an empty list if this is not an ALL_ permission
      • getPermissionType

        @Nullable
        public static String getPermissionType​(@NonNull
                                               String permission)
        Obtains the permission type of the given permission based on PermissionType.prefixes(). This assumes that the type is coded as a prefix in the given permission. If no permission type can be found, this returns the entire given permission unchanged.
        Parameters:
        permission - a permission to get the prefix for
        Returns:
        the prefix of the given permission from PermissionType.prefixes() or the permission unchanged if it does not have a prefix
        See Also:
        PermissionType.prefixes(), getPermissionRoot(String)