Class Policy

java.lang.Object
org.casbin.jcasbin.model.Policy
Direct Known Subclasses:
Model

public class Policy extends Object
Policy represents the whole access control policy user defined.
  • Field Details

  • Constructor Details

    • Policy

      public Policy()
  • Method Details

    • buildRoleLinks

      public void buildRoleLinks(Map<String,RoleManager> rmMap)
      buildRoleLinks initializes the roles in RBAC.
      Parameters:
      rmMap - the role manager map.
    • printPolicy

      public void printPolicy()
      printPolicy prints the policy to log.
    • savePolicyToText

      public String savePolicyToText()
      savePolicyToText saves the policy to the text.
      Returns:
      the policy text.
    • clearPolicy

      public void clearPolicy()
      clearPolicy clears all current policy.
    • getPolicy

      public List<List<String>> getPolicy(String sec, String ptype)
      getPolicy gets all rules in a policy.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      Returns:
      the policy rules of section sec and policy type ptype.
    • getFilteredPolicy

      public List<List<String>> getFilteredPolicy(String sec, String ptype, int fieldIndex, String... fieldValues)
      getFilteredPolicy gets rules based on field filters from a policy.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      fieldIndex - the policy rule's start index to be matched.
      fieldValues - the field values to be matched, value "" means not to match this field.
      Returns:
      the filtered policy rules of section sec and policy type ptype.
    • hasPolicy

      public boolean hasPolicy(String sec, String ptype, List<String> rule)
      hasPolicy determines whether a model has the specified policy rule.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      rule - the policy rule.
      Returns:
      whether the rule exists.
    • addPolicy

      public boolean addPolicy(String sec, String ptype, List<String> rule)
      addPolicy adds a policy rule to the model.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      rule - the policy rule.
      Returns:
      succeeds or not.
    • addPolicies

      public boolean addPolicies(String sec, String ptype, List<List<String>> rules)
      addPolicies adds policy rules to the model.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      rules - the policy rules.
      Returns:
      succeeds or not.
    • updatePolicy

      public boolean updatePolicy(String sec, String ptype, List<String> oldRule, List<String> newRule)
      UpdatePolicy updates a policy rule from the model.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      oldRule - the old rule.
      newRule - the new rule.
      Returns:
      succeeds or not.
    • removePolicy

      public boolean removePolicy(String sec, String ptype, List<String> rule)
      removePolicy removes a policy rule from the model.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      rule - the policy rule.
      Returns:
      succeeds or not.
    • removePolicies

      public boolean removePolicies(String sec, String ptype, List<List<String>> rules)
      removePolicies removes rules from the current policy.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      rules - the policy rules.
      Returns:
      succeeds or not.
    • removeFilteredPolicyReturnsEffects

      public List<List<String>> removeFilteredPolicyReturnsEffects(String sec, String ptype, int fieldIndex, String... fieldValues)
      removeFilteredPolicyReturnsEffects removes policy rules based on field filters from the model.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      fieldIndex - the policy rule's start index to be matched.
      fieldValues - the field values to be matched, value "" means not to match this field.
      Returns:
      succeeds(effects.size () > 0) or not.
    • removeFilteredPolicy

      public boolean removeFilteredPolicy(String sec, String ptype, int fieldIndex, String... fieldValues)
      removeFilteredPolicy removes policy rules based on field filters from the model.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      fieldIndex - the policy rule's start index to be matched.
      fieldValues - the field values to be matched, value "" means not to match this field.
      Returns:
      succeeds or not.
    • getValuesForFieldInPolicy

      public List<String> getValuesForFieldInPolicy(String sec, String ptype, int fieldIndex)
      getValuesForFieldInPolicy gets all values for a field for all rules in a policy, duplicated values are removed.
      Parameters:
      sec - the section, "p" or "g".
      ptype - the policy type, "p", "p2", .. or "g", "g2", ..
      fieldIndex - the policy rule's index.
      Returns:
      the field values specified by fieldIndex.
    • buildIncrementalRoleLinks

      public void buildIncrementalRoleLinks(Map<String,RoleManager> rmMap, Model.PolicyOperations op, String sec, String ptype, List<List<String>> rules)
    • hasPolicies

      public boolean hasPolicies(String sec, String ptype, List<List<String>> rules)
    • buildIncrementalConditionalRoleLinks

      public void buildIncrementalConditionalRoleLinks(Map<String,ConditionalRoleManager> condRmMap, Model.PolicyOperations op, String sec, String ptype, List<List<String>> rules)
      buildIncrementalConditionalRoleLinks provides incremental build the role inheritance relations.
      Parameters:
      condRmMap - a map of conditional role managers used for role link management.
      op - the operation to perform, such as adding or removing role links.
      sec - the section of the policy, typically "g" for role inheritance.
      ptype - the policy type, which specifies the kind of roles being managed.
      rules - the rules that define the role links to be built.
    • buildConditionalRoleLinks

      public void buildConditionalRoleLinks(Map<String,ConditionalRoleManager> condRmMap)
      buildConditionalRoleLinks initializes the roles in RBAC.
      Parameters:
      condRmMap - a map of conditional role managers that manage the role links and their conditions.