Management API
The Management API provides comprehensive support for Casbin policy management operations.
Filtered API
Filtered API methods share a common parameter signature: (fieldIndex int, fieldValues ...string). The fieldIndex parameter specifies the starting index for matching, while fieldValues contains the expected values. Empty strings in fieldValues act as wildcards, matching any value.
Приклад:
p, alice, book, read
p, bob, book, read
p, bob, book, write
p, alice, pen, get
p, bob, pen ,get
e.GetFilteredPolicy(1, "book") // returns: [["alice", "book", "read"], ["bob", "book", "read"], ["bob", "book", "write"]]
e.GetFilteredPolicy(1, "book", "read") // returns: [["alice", "book", "read"], ["bob", "book", "read"]]
e.GetFilteredPolicy(0, "alice", "", "read") // returns: [[alice book read]]
e.GetFilteredPolicy(0, "alice") // returns: [["alice", "book", "read"], ["alice", "pen", "get"]]
API Reference
Throughout this reference, the variable e represents an Enforcer instance.
e, err := NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
const e = await newEnforcer('examples/rbac_model.conf', 'examples/rbac_policy.csv')
$e = new Enforcer('examples/rbac_model.conf', 'examples/rbac_policy.csv');
e = casbin.Enforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
var e = new Enforcer("path/to/model.conf", "path/to/policy.csv");
let mut e = Enforce::new("examples/rbac_model.conf", "examples/rbac_policy.csv").await?;
Enforcer e = new Enforcer("examples/rbac_model.conf", "examples/rbac_policy.csv");
Enforce()
Enforce вирішує, чи може "суб'єкт" отримати доступ до "об'єкта" з операцією "дія", зазвичай вхідні параметри: (sub, obj, act).
Наприклад:
ok, err := e.Enforce(request)
const ok = await e.enforce(request);
$ok = $e->enforcer($request);
ok = e.enforcer(request)
var ok = e.Enforce(request);
// or async
var ok = await e.EnforceAsync(request);
boolean ok = e.enforce(request);
EnforceWithMatcher()
EnforceWithMatcher use a custom matcher to decides whether a "subject" can access a "object" with the operation "action", input parameters are usually: (matcher, sub, obj, act), use model matcher by default when matcher is "".
For example:
ok, err := e.EnforceWithMatcher(matcher, request)
$ok = $e->enforceWithMatcher($matcher, $request);
ok = e.enforce_with_matcher(matcher, request)
var ok = e.EnforceWithMatcher(matcher, request);
// or async
var ok = await e.EnforceWithMatcherAsync(matcher, request);
boolean ok = e.enforceWithMatcher(matcher, request);
EnforceEx()
EnforceEx explain enforcement by informing matched rules.
For example:
ok, reason, err := e.EnforceEx(request)
const ok = await e.enforceEx(request);
list($ok, $reason) = $e->enforceEx($request);
var (ok, explain) = e.EnforceEx(request);
// or async
var (ok, explain) = await e.EnforceExAsync(request);
ok, reason = e.enforce_ex(request)
EnforceExWithMatcher()
EnforceExWithMatcher use a custom matcher and explain enforcement by informing matched rules.
Наприклад:
ok, reason, err := e.EnforceExWithMatcher(matcher, request)
var (ok, explain) = e.EnforceExWithMatcher(matcher, request);
// or async
var (ok, explain) = await e.EnforceExWithMatcherAsync(matcher, request);
BatchEnforce()
BatchEnforce enforces each request and returns result in a bool array
For example:
boolArray, err := e.BatchEnforce(requests)
const boolArray = await e.batchEnforce(requests);
var boolArray = e.BatchEnforce(requests);
// or async
var boolArray = await e.BatchEnforceAsync(requests);
List<Boolean> boolArray = e.batchEnforce(requests);
GetAllSubjects()
GetAllSubjects gets the list of subjects that show up in the current policy.
For example:
allSubjects := e.GetAllSubjects()
const allSubjects = await e.getAllSubjects()
$allSubjects = $e->getAllSubjects();
all_subjects = e.get_all_subjects()
var allSubjects = e.GetAllSubjects();
let all_subjects = e.get_all_subjects();
List<String> 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 = await e.getAllNamedSubjects('p')
$allNamedSubjects = $e->getAllNamedSubjects("p");
all_named_subjects = e.get_all_named_subjects("p")
var allNamedSubjects = e.GetAllNamedSubjects("p");
let all_named_subjects = e.get_all_named_subjects("p");
List<String> 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 = await e.getAllObjects()
$allObjects = $e->getAllObjects();
all_objects = e.get_all_objects()
var allObjects = e.GetAllObjects();
let all_objects = e.get_all_objects();
List<String> 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 = await e.getAllNamedObjects('p')
$allNamedObjects = $e->getAllNamedObjects("p");
all_named_objects = e.get_all_named_objects("p")
var allNamedObjects = e.GetAllNamedObjects("p");
let all_named_objects = e.get_all_named_objects("p");
List<String> 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 = await e.getAllActions()
$allActions = $e->getAllActions();
all_actions = e.get_all_actions()
var allActions = e.GetAllActions();
let all_actions = e.get_all_actions();
List<String> 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 = await e.getAllNamedActions('p')
$allNamedActions = $e->getAllNamedActions("p");
all_named_actions = e.get_all_named_actions("p")
var allNamedActions = e.GetAllNamedActions("p");
let all_named_actions = e.get_all_named_actions("p");
List<String> 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 = await e.getAllRoles()
$allRoles = $e->getAllRoles();
all_roles = e.get_all_roles()
var allRoles = e.GetAllRoles();
let all_roles = e.get_all_roles();
List<String> 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 = await e.getAllNamedRoles('g')
$allNamedRoles = $e->getAllNamedRoles('g');
all_named_roles = e.get_all_named_roles("g")
var allNamedRoles = e.GetAllNamedRoles("g");
let all_named_roles = e.get_all_named_roles("g");
List<String> allNamedRoles = e.getAllNamedRoles("g");
GetPolicy()
GetPolicy gets all the authorization rules in the policy.
For example:
policy = e.GetPolicy()
const policy = await e.getPolicy()
$policy = $e->getPolicy();
policy = e.get_policy()
var policy = e.GetPolicy();
let policy = e.get_policy();
List<List<String>> 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 = await e.getFilteredPolicy(0, 'alice')
$filteredPolicy = $e->getFilteredPolicy(0, "alice");
filtered_policy = e.get_filtered_policy(0, "alice")
var filteredPolicy = e.GetFilteredPolicy(0, "alice");
let filtered_policy = e.get_filtered_policy(0, vec!["alice".to_owned()]);
List<List<String>> filteredPolicy = e.getFilteredPolicy(0, "alice");
GetNamedPolicy()
GetNamedPolicy gets all the authorization rules in the named policy.
For example:
namedPolicy := e.GetNamedPolicy("p")
const namedPolicy = await e.getNamedPolicy('p')
$namedPolicy = $e->getNamedPolicy("p");
named_policy = e.get_named_policy("p")
var namedPolicy = e.GetNamedPolicy("p");
let named_policy = e.get_named_policy("p");
List<List<String>> 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 = await e.getFilteredNamedPolicy('p', 0, 'bob')
$filteredNamedPolicy = $e->getFilteredNamedPolicy("p", 0, "bob");
filtered_named_policy = e.get_filtered_named_policy("p", 0, "alice")
var filteredNamedPolicy = e.GetFilteredNamedPolicy("p", 0, "alice");
let filtered_named_policy = e.get_filtered_named_policy("p", 0, vec!["bob".to_owned()]);
List<List<String>> filteredNamedPolicy = e.getFilteredNamedPolicy("p", 0, "bob");