Class ManagementEnforcer
java.lang.Object
org.casbin.jcasbin.main.CoreEnforcer
org.casbin.jcasbin.main.InternalEnforcer
org.casbin.jcasbin.main.ManagementEnforcer
- Direct Known Subclasses:
Enforcer
ManagementEnforcer = InternalEnforcer + Management API.
-
Field Summary
Fields inherited from class CoreEnforcer
acceptJsonRequest, adapter, autoBuildRoleLinks, autoNotifyDispatcher, autoNotifyWatcher, autoSave, condRmMap, dispatcher, fm, model, modelPath, rmMap, watcher -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFunction(String name, CustomFunction function) addFunction adds a customized function.booleanaddGroupingPolicies(String[][] rules) addGroupingPolicies adds role inheritance rules to the current policy.booleanaddGroupingPolicies(List<List<String>> rules) addGroupingPolicies adds role inheritance rules to the current policy.booleanaddGroupingPolicy(String... params) addGroupingPolicy adds a role inheritance rule to the current policy.booleanaddGroupingPolicy(List<String> params) addGroupingPolicy adds a role inheritance rule to the current policy.booleanaddNamedGroupingPolicies(String ptype, String[][] rules) addNamedGroupingPolicies adds named role inheritance rules to the current policy.booleanaddNamedGroupingPolicies(String ptype, List<List<String>> rules) addNamedGroupingPolicies adds named role inheritance rules to the current policy.booleanaddNamedGroupingPolicy(String ptype, String... params) addNamedGroupingPolicy adds a named role inheritance rule to the current policy.booleanaddNamedGroupingPolicy(String ptype, List<String> params) addNamedGroupingPolicy adds a named role inheritance rule to the current policy.booleanaddNamedPolicies(String ptype, List<List<String>> rules) addNamedPolicies adds authorization rules to the current named policy.booleanaddNamedPoliciesEx(String ptype, List<List<String>> rules) addNamedPoliciesEx adds authorization rules to the current named policy.booleanaddNamedPolicy(String ptype, String... params) AddNamedPolicy adds an authorization rule to the current named policy.booleanaddNamedPolicy(String ptype, List<String> params) AddNamedPolicy adds an authorization rule to the current named policy.booleanaddPolicies(String[][] rules) addPolicies adds authorization rules to the current policy.booleanaddPolicies(List<List<String>> rules) addPolicies adds authorization rules to the current policy.booleanaddPolicy adds an authorization rule to the current policy.booleanaddPolicy adds an authorization rule to the current policy.getAllActions gets the list of actions that show up in the current policy.getAllNamedActions(String ptype) GetAllNamedActions gets the list of actions that show up in the current named policy.getAllNamedObjects(String ptype) getAllNamedObjects gets the list of objects that show up in the current named policy.getAllNamedRoles(String ptype) getAllNamedRoles gets the list of roles that show up in the current named policy.getAllNamedSubjects(String ptype) GetAllNamedSubjects gets the list of subjects that show up in the currentnamed policy.getAllObjects gets the list of objects that show up in the current policy.getAllRoles gets the list of roles that show up in the current policy.getAllSubjects gets the list of subjects that show up in the current policy.private intgetElementIndex(Assertion policy, String elementName) getElementIndex returns the index of a specific element.getFilteredGroupingPolicy(int fieldIndex, String... fieldValues) getFilteredGroupingPolicy gets all the role inheritance rules in the policy, field filters can be specified.getFilteredNamedGroupingPolicy(String ptype, int fieldIndex, String... fieldValues) getFilteredNamedGroupingPolicy gets all the role inheritance rules in the policy, field filters can be specified.getFilteredNamedPolicy(String ptype, int fieldIndex, String... fieldValues) getFilteredNamedPolicy gets all the authorization rules in the named policy, field filters can be specified.getFilteredPolicy(int fieldIndex, String... fieldValues) getFilteredPolicy gets all the authorization rules in the policy, field filters can be specified.getGroupingPolicy gets all the role inheritance rules in the policy.getNamedGroupingPolicy(String ptype) getNamedGroupingPolicy gets all the role inheritance rules in the policy.getNamedPolicy(String ptype) getNamedPolicy gets all the authorization rules in the named policy.getPermittedActions(Object sub, Object obj) getPermittedActions returns all valid actions to specific object for current subject.getPolicy gets all the authorization rules in the policy.booleanhasGroupingPolicy(String... params) hasGroupingPolicy determines whether a role inheritance rule exists.booleanhasGroupingPolicy(List<String> params) hasGroupingPolicy determines whether a role inheritance rule exists.booleanhasNamedGroupingPolicy(String ptype, String... params) hasNamedGroupingPolicy determines whether a named role inheritance rule exists.booleanhasNamedGroupingPolicy(String ptype, List<String> params) hasNamedGroupingPolicy determines whether a named role inheritance rule exists.booleanhasNamedPolicy(String ptype, String... params) hasNamedPolicy determines whether a named authorization rule exists.booleanhasNamedPolicy(String ptype, List<String> params) hasNamedPolicy determines whether a named authorization rule exists.booleanhasPolicy determines whether an authorization rule exists.booleanhasPolicy determines whether an authorization rule exists.booleanremoveFilteredGroupingPolicy(int fieldIndex, String... fieldValues) removeFilteredGroupingPolicy removes a role inheritance rule from the current policy, field filters can be specified.booleanremoveFilteredNamedGroupingPolicy(String ptype, int fieldIndex, String... fieldValues) removeFilteredNamedGroupingPolicy removes a role inheritance rule from the current named policy, field filters can be specified.booleanremoveFilteredNamedPolicy(String ptype, int fieldIndex, String... fieldValues) removeFilteredNamedPolicy removes an authorization rule from the current named policy, field filters can be specified.booleanremoveFilteredPolicy(int fieldIndex, String... fieldValues) removeFilteredPolicy removes an authorization rule from the current policy, field filters can be specified.booleanremoveGroupingPolicies(String[][] rules) removeGroupingPolicies removes role inheritance rules from the current policy.booleanremoveGroupingPolicies(List<List<String>> rules) removeGroupingPolicies removes role inheritance rules from the current policy.booleanremoveGroupingPolicy(String... params) removeGroupingPolicy removes a role inheritance rule from the current policy.booleanremoveGroupingPolicy(List<String> params) removeGroupingPolicy removes a role inheritance rule from the current policy.booleanremoveNamedGroupingPolicies(String ptype, String[][] rules) removeNamedGroupingPolicies removes role inheritance rules from the current named policy.booleanremoveNamedGroupingPolicies(String ptype, List<List<String>> rules) removeNamedGroupingPolicies removes role inheritance rules from the current named policy.booleanremoveNamedGroupingPolicy(String ptype, String... params) removeNamedGroupingPolicy removes a role inheritance rule from the current named policy.booleanremoveNamedGroupingPolicy(String ptype, List<String> params) removeNamedGroupingPolicy removes a role inheritance rule from the current named policy.booleanremoveNamedPolicies(String ptype, List<List<String>> rules) removeNamedPolicies removes authorization rules from the current named policy.booleanremoveNamedPolicy(String ptype, String... params) removeNamedPolicy removes an authorization rule from the current named policy.booleanremoveNamedPolicy(String ptype, List<String> params) removeNamedPolicy removes an authorization rule from the current named policy.booleanremovePolicies(String[][] rules) removePolicies removes authorization rules from the current policy.booleanremovePolicies(List<List<String>> rules) removePolicies removes authorization rules from the current policy.booleanremovePolicy(String... params) removePolicy removes an authorization rule from the current policy.booleanremovePolicy(List<String> params) removePolicy removes an authorization rule from the current policy.booleanupdateGroupingPolicy(List<String> params1, List<String> params2) UpdateGroupingPolicy updates an authorization rule to the current named policy.booleanupdateNamedGroupingPolicy updates an authorization rule to the current named policy.booleanupdateNamedPolicy updates an authorization rule to the current named policy.booleanupdatePolicy(List<String> params1, List<String> params2) updatePolicy update an authorization rule to the current policy.Methods inherited from class InternalEnforcer
addPolicies, addPolicy, buildIncrementalRoleLinks, getDomainIndex, removeFilteredPolicy, removePolicies, removePolicy, updatePolicyMethods inherited from class CoreEnforcer
addNamedDomainLinkConditionFunc, addNamedDomainMatchingFunc, addNamedLinkConditionFunc, addNamedMatchingFunc, buildConditionalRoleLinks, buildRoleLinks, clearPolicy, enableAcceptJsonRequest, enableAutoBuildRoleLinks, enableAutoSave, enableEnforce, enableLog, enforce, enforceEx, enforceExWithMatcher, enforceWithMatcher, getAdapter, getAviatorEval, getModel, getNamedRoleManager, getRmMap, getRoleManager, initialize, isAutoNotifyDispatcher, isAutoNotifyWatcher, isFiltered, loadFilteredPolicy, loadModel, loadPolicy, mustUseDispatcher, newModel, newModel, newModel, resetExpressionEvaluator, savePolicy, setAdapter, setAutoNotifyDispatcher, setAutoNotifyWatcher, setAviatorEvaluator, setDispatcher, setEffector, setModel, setNamedDomainLinkConditionFuncParams, setNamedLinkConditionFuncParams, setNamedRoleManager, setRoleManager, setRoleManager, setWatcher, validateEnforce
-
Constructor Details
-
ManagementEnforcer
public ManagementEnforcer()
-
-
Method Details
-
getAllSubjects
getAllSubjects gets the list of subjects that show up in the current policy.- Returns:
- all the subjects in "p" policy rules. It actually collects the 0-index elements of "p" policy rules. So make sure your subject is the 0-index element, like (sub, obj, act). Duplicates are removed.
-
getAllNamedSubjects
GetAllNamedSubjects gets the list of subjects that show up in the currentnamed policy.- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..- Returns:
- all the subjects in policy rules of the ptype type. It actually collects the 0-index elements of the policy rules. So make sure your subject is the 0-index element, like (sub, obj, act). Duplicates are removed.
-
getAllObjects
getAllObjects gets the list of objects that show up in the current policy.- Returns:
- all the objects in "p" policy rules. It actually collects the 1-index elements of "p" policy rules. So make sure your object is the 1-index element, like (sub, obj, act). Duplicates are removed.
-
getAllNamedObjects
getAllNamedObjects gets the list of objects that show up in the current named policy.- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..- Returns:
- all the objects in policy rules of the ptype type. It actually collects the 1-index elements of the policy rules. So make sure your object is the 1-index element, like (sub, obj, act). Duplicates are removed.
-
getAllActions
getAllActions gets the list of actions that show up in the current policy.- Returns:
- all the actions in "p" policy rules. It actually collects the 2-index elements of "p" policy rules. So make sure your action is the 2-index element, like (sub, obj, act). Duplicates are removed.
-
getAllNamedActions
GetAllNamedActions gets the list of actions that show up in the current named policy.- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..- Returns:
- all the actions in policy rules of the ptype type. It actually collects the 2-index elements of the policy rules. So make sure your action is the 2-index element, like (sub, obj, act). Duplicates are removed.
-
getAllRoles
getAllRoles gets the list of roles that show up in the current policy.- Returns:
- all the roles in "g" policy rules. It actually collects the 1-index elements of "g" policy rules. So make sure your role is the 1-index element, like (sub, role). Duplicates are removed.
-
getAllNamedRoles
getAllNamedRoles gets the list of roles that show up in the current named policy.- Parameters:
ptype- the policy type, can be "g", "g2", "g3", ..- Returns:
- all the subjects in policy rules of the ptype type. It actually collects the 0-index elements of the policy rules. So make sure your subject is the 0-index element, like (sub, obj, act). Duplicates are removed.
-
getPolicy
-
getFilteredPolicy
getFilteredPolicy gets all the authorization rules in the policy, field filters can be specified.- Parameters:
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 "p" policy rules.
-
getNamedPolicy
-
getFilteredNamedPolicy
public List<List<String>> getFilteredNamedPolicy(String ptype, int fieldIndex, String... fieldValues) getFilteredNamedPolicy gets all the authorization rules in the named policy, field filters can be specified.- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..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 "p" policy rules of the specified ptype.
-
getGroupingPolicy
-
getFilteredGroupingPolicy
getFilteredGroupingPolicy gets all the role inheritance rules in the policy, field filters can be specified.- Parameters:
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 "g" policy rules.
-
getNamedGroupingPolicy
-
getFilteredNamedGroupingPolicy
public List<List<String>> getFilteredNamedGroupingPolicy(String ptype, int fieldIndex, String... fieldValues) getFilteredNamedGroupingPolicy gets all the role inheritance rules in the policy, field filters can be specified.- Parameters:
ptype- the policy type, can be "g", "g2", "g3", ..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 "g" policy rules of the specified ptype.
-
hasPolicy
-
hasPolicy
hasPolicy determines whether an authorization rule exists.- Parameters:
params- the "p" policy rule, ptype "p" is implicitly used.- Returns:
- whether the rule exists.
-
hasNamedPolicy
-
hasNamedPolicy
-
addPolicy
addPolicy adds an authorization rule to the current policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.- Parameters:
params- the "p" policy rule, ptype "p" is implicitly used.- Returns:
- succeeds or not.
-
addPolicies
addPolicies adds authorization rules to the current policy. If the rule already exists, the function returns false for the corresponding rule and the rule will not be added. Otherwise the function returns true for the corresponding rule by adding the new rule.- Parameters:
rules- the "p" policy rules, ptype "p" is implicitly used.- Returns:
- succeeds or not.
-
updatePolicy
-
addPolicy
addPolicy adds an authorization rule to the current policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.- Parameters:
params- the "p" policy rule, ptype "p" is implicitly used.- Returns:
- succeeds or not.
-
addPolicies
addPolicies adds authorization rules to the current policy. If the rule already exists, the function returns false for the corresponding rule and the rule will not be added. Otherwise the function returns true for the corresponding rule by adding the new rule.- Parameters:
rules- the "p" policy rules, ptype "p" is implicitly used.- Returns:
- succeeds or not.
-
addNamedPolicy
AddNamedPolicy adds an authorization rule to the current named policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..params- the "p" policy rule.- Returns:
- succeeds or not.
-
addNamedPolicies
addNamedPolicies adds authorization rules to the current named policy. If the rule already exists, the function returns false for the corresponding rule and the rule will not be added. Otherwise the function returns true for the corresponding by adding the new rule.- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..rules- the "p" policy rules.- Returns:
- succeeds or not.
-
addNamedPoliciesEx
addNamedPoliciesEx adds authorization rules to the current named policy. If the rule already exists, the rule will not be added. But unlike AddNamedPolicies, other non-existent rules are added instead of returning false directly- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..rules- the "p" policy rules.- Returns:
- succeeds or not.
-
updateNamedPolicy
updateNamedPolicy updates an authorization rule to the current named policy.- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..params1- the old rule.params2- the new rule.- Returns:
- succeeds or not.
-
updateGroupingPolicy
-
updateNamedGroupingPolicy
updateNamedGroupingPolicy updates an authorization rule to the current named policy.- Parameters:
ptype- the policy type, can be "g", "g2", "g3", ..params1- the old rule.params2- the new rule.- Returns:
- succeeds or not.
-
addNamedPolicy
AddNamedPolicy adds an authorization rule to the current named policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..params- the "p" policy rule.- Returns:
- succeeds or not.
-
removePolicy
-
removePolicy
removePolicy removes an authorization rule from the current policy.- Parameters:
params- the "p" policy rule, ptype "p" is implicitly used.- Returns:
- succeeds or not.
-
removePolicies
-
removePolicies
removePolicies removes authorization rules from the current policy.- Parameters:
rules- the "p" policy rules, ptype "p" is implicitly used.- Returns:
- succeeds or not.
-
removeFilteredPolicy
removeFilteredPolicy removes an authorization rule from the current policy, field filters can be specified.- Parameters:
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.
-
removeNamedPolicy
-
removeNamedPolicy
-
removeNamedPolicies
-
removeFilteredNamedPolicy
removeFilteredNamedPolicy removes an authorization rule from the current named policy, field filters can be specified.- Parameters:
ptype- the policy type, can be "p", "p2", "p3", ..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.
-
hasGroupingPolicy
-
hasGroupingPolicy
hasGroupingPolicy determines whether a role inheritance rule exists.- Parameters:
params- the "g" policy rule, ptype "g" is implicitly used.- Returns:
- whether the rule exists.
-
hasNamedGroupingPolicy
-
hasNamedGroupingPolicy
-
addGroupingPolicy
addGroupingPolicy adds a role inheritance rule to the current policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.- Parameters:
params- the "g" policy rule, ptype "g" is implicitly used.- Returns:
- succeeds or not.
-
addGroupingPolicy
addGroupingPolicy adds a role inheritance rule to the current policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.- Parameters:
params- the "g" policy rule, ptype "g" is implicitly used.- Returns:
- succeeds or not.
-
addGroupingPolicies
addGroupingPolicies adds role inheritance rules to the current policy. If the rule already exists, the function returns false for the corresponding policy rule and the rule will not be added. Otherwise the function returns true for the corresponding policy rule by adding the new rule.- Parameters:
rules- the "g" policy rules, ptype "g" is implicitly used.- Returns:
- succeeds or not.
-
addGroupingPolicies
addGroupingPolicies adds role inheritance rules to the current policy. If the rule already exists, the function returns false for the corresponding policy rule and the rule will not be added. Otherwise the function returns true for the corresponding policy rule by adding the new rule.- Parameters:
rules- the "g" policy rules, ptype "g" is implicitly used.- Returns:
- succeeds or not.
-
addNamedGroupingPolicy
addNamedGroupingPolicy adds a named role inheritance rule to the current policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.- Parameters:
ptype- the policy type, can be "g", "g2", "g3", ..params- the "g" policy rule.- Returns:
- succeeds or not.
-
addNamedGroupingPolicy
addNamedGroupingPolicy adds a named role inheritance rule to the current policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.- Parameters:
ptype- the policy type, can be "g", "g2", "g3", ..params- the "g" policy rule.- Returns:
- succeeds or not.
-
addNamedGroupingPolicies
addNamedGroupingPolicies adds named role inheritance rules to the current policy. If the rule already exists, the function returns false for the corresponding policy rule and the rule will not be added. Otherwise the function returns true for the corresponding policy rule by adding the new rule.- Parameters:
ptype- the policy type, can be "g", "g2", "g3", ..rules- the "g" policy rules.- Returns:
- succeeds or not.
-
addNamedGroupingPolicies
addNamedGroupingPolicies adds named role inheritance rules to the current policy. If the rule already exists, the function returns false for the corresponding policy rule and the rule will not be added. Otherwise the function returns true for the corresponding policy rule by adding the new rule.- Parameters:
ptype- the policy type, can be "g", "g2", "g3", ..rules- the "g" policy rules.- Returns:
- succeeds or not.
-
removeGroupingPolicy
-
removeGroupingPolicy
removeGroupingPolicy removes a role inheritance rule from the current policy.- Parameters:
params- the "g" policy rule, ptype "g" is implicitly used.- Returns:
- succeeds or not.
-
removeGroupingPolicies
-
removeGroupingPolicies
removeGroupingPolicies removes role inheritance rules from the current policy.- Parameters:
rules- the "g" policy rules, ptype "g" is implicitly used.- Returns:
- succeeds or not.
-
removeFilteredGroupingPolicy
removeFilteredGroupingPolicy removes a role inheritance rule from the current policy, field filters can be specified.- Parameters:
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.
-
removeNamedGroupingPolicy
-
removeNamedGroupingPolicy
-
removeNamedGroupingPolicies
-
removeNamedGroupingPolicies
-
removeFilteredNamedGroupingPolicy
public boolean removeFilteredNamedGroupingPolicy(String ptype, int fieldIndex, String... fieldValues) removeFilteredNamedGroupingPolicy removes a role inheritance rule from the current named policy, field filters can be specified.- Parameters:
ptype- the policy type, can be "g", "g2", "g3", ..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.
-
addFunction
addFunction adds a customized function.- Parameters:
name- the name of the function.function- the custom function.
-
getPermittedActions
getPermittedActions returns all valid actions to specific object for current subject. At present, the execution efficiency of this method is not high. Please avoid calling this method frequently.- Parameters:
sub- the subject(usually means user).obj- the object(usually means resources).- Returns:
- all valid actions to specific object for current subject.
-
getElementIndex
getElementIndex returns the index of a specific element.- Parameters:
policy- the policy. For example: policy.value = "sub, obj, act"elementName- the element's name. For example: elementName = "act"- Returns:
- the index of a specific element. If the above two example parameters are passed in, it will return 2. -1 if the element does not exist.
-