Class PermissionUtils

java.lang.Object
com.broadleafcommerce.auth.security.domain.PermissionUtils

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

    • 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
    • getPermissionRoot

      public static Optional<String> getPermissionRoot(@NonNull String permission)
      Obtains the 'root' of the permission which is defined as anything that comes after one of the PermissionType.prefixes(). Example: given ALL_PRODUCT this will return PRODUCT and given SOME_PERMISSION this will return an empty optional
      Parameters:
      permission - a permission
      Returns:
      the root of permission or an empty Optional if permission does not start with PermissionType.prefixes()
      See Also:
    • 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: