The primitive API that provides full support for Casbin policy management.
global variable e is Enforcer instance.
e := NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
const e = await newEnforcer('examples/rbac_model.conf', 'examples/rbac_policy.csv')
GetAllSubjects()GetAllSubjects gets the list of subjects that show up in the current policy.
For example:
allSubjects := e.GetAllSubjects()
const allSubjects = e.getAllSubjects()
GetAllNamedSubjects()GetAllNamedSubjects gets the list of subjects that show up in the current named policy.
For example:
allNamedSubjects := e.GetAllNamedSubjects("p")
const allNamedSubjects = e.getAllNamedSubjects('p')
GetAllObjects()GetAllObjects gets the list of objects that show up in the current policy.
For example:
allObjects := e.GetAllObjects()
const allObjects = e.getAllObjects()
GetAllNamedObjects()GetAllNamedObjects gets the list of objects that show up in the current named policy.
For example:
allNamedObjects := e.GetAllNamedObjects("p")
const allNamedObjects = e.getAllNamedObjects('p')
GetAllActions()GetAllActions gets the list of actions that show up in the current policy.
For example:
allActions := e.GetAllActions()
const allActions = e.getAllActions()
GetAllNamedActions()GetAllNamedActions gets the list of actions that show up in the current named policy.
For example:
allNamedActions := e.GetAllNamedActions("p")
const allNamedActions = e.getAllNamedActions('p')
GetAllRoles()GetAllRoles gets the list of roles that show up in the current policy.
For example:
allRoles = e.GetAllRoles()
const allRoles = e.getAllRoles()
GetAllNamedRoles()GetAllNamedRoles gets the list of roles that show up in the current named policy.
For example:
allNamedRoles := e.GetAllNamedRoles("g")
const allNamedRoles = e.getAllNamedRoles('g')
GetPolicy()GetPolicy gets all the authorization rules in the policy.
For example:
policy = e.GetPolicy()
const policy = e.getPolicy()
GetFilteredPolicy()GetFilteredPolicy gets all the authorization rules in the policy, field filters can be specified.
For example:
filteredPolicy := e.GetFilteredPolicy(0, "alice")
const filteredPolicy = e.getFilteredPolicy(0, 'alice')
GetNamedPolicy()GetNamedPolicy gets all the authorization rules in the named policy.
For example:
namedPolicy := e.GetNamedPolicy("p")
const namedPolicy = e.getNamedPolicy('p')
GetFilteredNamedPolicy()GetFilteredNamedPolicy gets all the authorization rules in the named policy, field filters can be specified.
For example:
filteredNamedPolicy = e.GetFilteredNamedPolicy("p", 0, "bob")
const filteredNamedPolicy = e.getFilteredNamedPolicy('p', 0, 'bob')
GetGroupingPolicy()GetGroupingPolicy gets all the role inheritance rules in the policy.
For example:
groupingPolicy := e.GetGroupingPolicy()
const groupingPolicy = e.getGroupingPolicy()
GetFilteredGroupingPolicy()GetFilteredGroupingPolicy gets all the role inheritance rules in the policy, field filters can be specified.
For example:
filteredGroupingPolicy := e.GetFilteredGroupingPolicy(0, "alice")
const filteredGroupingPolicy = e.getFilteredGroupingPolicy(0, 'alice')
GetNamedGroupingPolicy()GetNamedGroupingPolicy gets all the role inheritance rules in the policy.
For example:
namedGroupingPolicy := e.GetNamedGroupingPolicy("g")
const namedGroupingPolicy = e.getNamedGroupingPolicy('g')
GetFilteredNamedGroupingPolicy()GetFilteredNamedGroupingPolicy gets all the role inheritance rules in the policy.
For example:
namedGroupingPolicy := e.GetFilteredNamedGroupingPolicy("g", 0, "alice")
const namedGroupingPolicy = e.getFilteredNamedGroupingPolicy('g', 0, 'alice')
HasPolicy()HasPolicy determines whether an authorization rule exists.
For example:
hasPolicy := e.HasPolicy("data2_admin", "data2", "read")
const hasPolicy = e.hasPolicy('data2_admin', 'data2', 'read')
HasNamedPolicy()HasNamedPolicy determines whether a named authorization rule exists.
For example:
hasNamedPolicy := e.HasNamedPolicy("p", "data2_admin", "data2", "read")
const hasNamedPolicy = e.hasNamedPolicy('p', 'data2_admin', 'data2', 'read')
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.
For example:
added := e.AddPolicy("eve", "data3", "read")
const p = ['eve', 'data3', 'read'] const added = await e.addPolicy(...p)
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.
For example:
added := e.AddNamedPolicy("p", "eve", "data3", "read")
const p = ['eve', 'data3', 'read'] const added = await e.addNamedPolicy('p', ...p)
RemovePolicy()RemovePolicy removes an authorization rule from the current policy.
For example:
removed := e.RemovePolicy("alice", "data1", "read")
const p = ['alice', 'data1', 'read'] const removed = await e.removePolicy(...p)
RemoveFilteredPolicy()RemoveFilteredPolicy removes an authorization rule from the current policy, field filters can be specified. RemovePolicy removes an authorization rule from the current policy.
For example:
removed := e.RemoveFilteredPolicy(0, "alice", "data1", "read")
const p = ['alice', 'data1', 'read'] const removed = await e.removeFilteredPolicy(0, ...p)
RemoveNamedPolicy()RemoveNamedPolicy removes an authorization rule from the current named policy.
For example:
removed := e.RemoveNamedPolicy("p", "alice", "data1", "read")
const p = ['alice', 'data1', 'read'] const removed = await e.removeNamedPolicy('p', ...p)
RemoveFilteredNamedPolicy()RemoveFilteredNamedPolicy removes an authorization rule from the current named policy, field filters can be specified.
For example:
removed := e.RemoveFilteredNamedPolicy("p", 0, "alice", "data1", "read")
const p = ['alice', 'data1', 'read'] const removed = await e.removeFilteredNamedPolicy('p', 0, ...p)
HasGroupingPolicy()HasGroupingPolicy determines whether a role inheritance rule exists.
For example:
has := e.HasGroupingPolicy("alice", "data2_admin")
const has = e.hasGroupingPolicy('alice', 'data2_admin')
HasNamedGroupingPolicy()HasNamedGroupingPolicy determines whether a named role inheritance rule exists.
For example:
has := e.HasNamedGroupingPolicy("g", "alice", "data2_admin")
const has = e.hasNamedGroupingPolicy('g', 'alice', 'data2_admin')
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.
For example:
added := e.AddGroupingPolicy("group1", "data2_admin")
const added = await e.addGroupingPolicy('group1', 'data2_admin')
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.
For example:
added := e.AddNamedGroupingPolicy("g", "group1", "data2_admin")
const added = await e.addNamedGroupingPolicy('g', 'group1', 'data2_admin')
RemoveGroupingPolicy()RemoveGroupingPolicy removes a role inheritance rule from the current policy.
For example:
removed := e.AddNamedGroupingPolicy("alice", "data2_admin")
const removed = await e.removeGroupingPolicy('alice', 'data2_admin')
RemoveFilteredGroupingPolicy()RemoveFilteredGroupingPolicy removes a role inheritance rule from the current policy, field filters can be specified.
For example:
removed := e.RemoveFilteredGroupingPolicy(0, "alice")
const removed = await e.removeFilteredGroupingPolicy(0, 'alice')
RemoveNamedGroupingPolicy()RemoveNamedGroupingPolicy removes a role inheritance rule from the current named policy.
For example:
removed := e.RemoveNamedGroupingPolicy("g", "alice")
const removed = await e.removeNamedGroupingPolicy('g', 'alice')
RemoveFilteredNamedGroupingPolicy()RemoveFilteredNamedGroupingPolicy removes a role inheritance rule from the current named policy, field filters can be specified.
For example:
removed := e.RemoveFilteredNamedGroupingPolicy("g", 0, "alice")
const removed = await e.removeFilteredNamedGroupingPolicy('g', 0, 'alice')
AddFunction()AddFunction adds a customized function.
For example:
func CustomFunction(key1 string, key2 string) bool {
if key1 == "/alice_data2/myid/using/res_id" && key2 == "/alice_data/:resource" {
return true
} else if key1 == "/alice_data2/myid/using/res_id" && key2 == "/alice_data2/:id/using/:resId" {
return true
} else {
return false
}
}
func CustomFunctionWrapper(args ...interface{}) (interface{}, error) {
key1 := args[0].(string)
key2 := args[1].(string)
return bool(CustomFunction(key1, key2)), nil
}
e.AddFunction("keyMatchCustom", CustomFunctionWrapper)
Method is not implemented