Package org.casbin.jcasbin.model
Class Policy
java.lang.Object
org.casbin.jcasbin.model.Policy
- Direct Known Subclasses:
Model
Policy represents the whole access control policy user defined.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addPolicies adds policy rules to the model.boolean
addPolicy adds a policy rule to the model.void
buildConditionalRoleLinks
(Map<String, ConditionalRoleManager> condRmMap) buildConditionalRoleLinks initializes the roles in RBAC.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.void
buildIncrementalRoleLinks
(Map<String, RoleManager> rmMap, Model.PolicyOperations op, String sec, String ptype, List<List<String>> rules) void
buildRoleLinks
(Map<String, RoleManager> rmMap) buildRoleLinks initializes the roles in RBAC.void
clearPolicy clears all current policy.getFilteredPolicy
(String sec, String ptype, int fieldIndex, String... fieldValues) getFilteredPolicy gets rules based on field filters from a policy.getPolicy gets all rules in a policy.getValuesForFieldInPolicy
(String sec, String ptype, int fieldIndex) getValuesForFieldInPolicy gets all values for a field for all rules in a policy, duplicated values are removed.boolean
boolean
hasPolicy determines whether a model has the specified policy rule.void
printPolicy prints the policy to log.boolean
removeFilteredPolicy
(String sec, String ptype, int fieldIndex, String... fieldValues) removeFilteredPolicy removes policy rules based on field filters from the model.removeFilteredPolicyReturnsEffects
(String sec, String ptype, int fieldIndex, String... fieldValues) removeFilteredPolicyReturnsEffects removes policy rules based on field filters from the model.boolean
removePolicies removes rules from the current policy.boolean
removePolicy
(String sec, String ptype, List<String> rule) removePolicy removes a policy rule from the model.savePolicyToText saves the policy to the text.boolean
UpdatePolicy updates a policy rule from the model.
-
Field Details
-
model
-
-
Constructor Details
-
Policy
public Policy()
-
-
Method Details
-
buildRoleLinks
buildRoleLinks initializes the roles in RBAC.- Parameters:
rmMap
- the role manager map.
-
printPolicy
public void printPolicy()printPolicy prints the policy to log. -
savePolicyToText
savePolicyToText saves the policy to the text.- Returns:
- the policy text.
-
clearPolicy
public void clearPolicy()clearPolicy clears all current policy. -
getPolicy
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
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
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
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
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
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
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
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
-
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
buildConditionalRoleLinks initializes the roles in RBAC.- Parameters:
condRmMap
- a map of conditional role managers that manage the role links and their conditions.
-