Class PermissionRule

Object
PermissionRule
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
PermissionRule.ApplyStructure, PermissionRule.SetLevel

public abstract class PermissionRule extends Object implements Cloneable

A list of PermissionRules is used to define a PermissionLevel for a given user. All possible sub-classes of PermissionRule are listed here as the inner classes.

Author:
Igor Sereda
See Also:
  • Constructor Details

    • PermissionRule

      public PermissionRule()
  • Method Details

    • toEncodedString

      public abstract String toEncodedString()
      Returns:
      a string representation of this permission rule
      See Also:
    • apply

      @NotNull public abstract PermissionLevel apply(@Nullable ApplicationUser user, @NotNull PermissionLevel pass, @Nullable List<Object> callStack, @Nullable La<Long,List<PermissionRule>> resolver)

      Apply permission rule and return the result.

      Normally you should not call this method directly - call Structure.getEffectivePermission() instead.

      Parameters:
      user - the user, null means anonymous
      pass - the default value, which is returned in case this rule does not apply
      callStack - auxiliary container for objects used to check for recursive rules
      resolver - auxiliary function that converts structure ID into associated list of permission rules - used by PermissionRule.ApplyStructure. If null, PermissionRule.ApplyStructure will not be able to apply and return pass value.
      Returns:
      permission level for the passed user
    • fromEncodedString

      @Nullable public static PermissionRule fromEncodedString(@Nullable String s) throws ParseException
      Restores permission rule from its encoded String form. In case the string is null or empty, returns null. Use this method only if user keys were used to encode user permissions.
      Parameters:
      s - encoded string
      Returns:
      the encoded rule, or null if the string is null or empty
      Throws:
      ParseException - if the string is not empty, but cannot be translated back to a rule
      See Also:
    • fromEncodedString

      @Nullable public static PermissionRule fromEncodedString(@Nullable String s, boolean usersAsUserNames) throws ParseException
      Restores permission rule from its encoded String form. In case the string is null or empty, returns null.
      Parameters:
      s - encoded string
      usersAsUserNames - true if user names were used to encode user permissions (Structure version was less than 2.3), false if user keys were used instead.
      Returns:
      the encoded rule, or null if the string is null or empty
      Throws:
      ParseException - if the string is not empty, but cannot be translated back to a rule
    • encodePermissions

      @NotNull @Deprecated public static String encodePermissions(@Nullable List<PermissionRule> permissions)
      Deprecated.
      Please avoid using this method. The resulting String can't be decoded if any provided PermissionRule contains "," in its encoded form. Consider using other formats for encoding: JSON or XML.
      Utility method to encode a list of PermissionRules.
      Parameters:
      permissions - a list of permissions
      Returns:
      a string with encoded permissions, separated by comma
      See Also:
    • decodePermissions

      @NotNull @Deprecated public static List<PermissionRule> decodePermissions(@Nullable String s) throws ParseException
      Deprecated.
      Please avoid using this method. It can't decode permission rules if any rule contains "," it its encoded form. Consider using other formats for encoding: JSON or XML.
      Utility method to decode a list of PermissionRules.
      Parameters:
      s - encoded list of permissions, delimited by comma
      Returns:
      a restored list of rules
      Throws:
      ParseException - in case any of the parts used to encode a permission rule failed to decode
      See Also:
    • clone

      public PermissionRule clone()
      Overrides:
      clone in class Object
      Returns:
      a cloned version of this rule
    • toString

      public String toString()
      Overrides:
      toString in class Object