Documentation
¶
Overview ¶
Package client implements a Go client for casbin-server, and contains an implementation of an API similar to the casbin API.
Index ¶
- type Client
- type Config
- type Enforcer
- func (e *Enforcer) AddGroupingPolicy(ctx context.Context, params ...interface{}) (bool, error)
- func (e *Enforcer) AddNamedGroupingPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
- func (e *Enforcer) AddNamedPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
- func (e *Enforcer) AddPermissionForUser(ctx context.Context, user string, permission ...string) (bool, error)
- func (e *Enforcer) AddPolicy(ctx context.Context, params ...interface{}) (bool, error)
- func (e *Enforcer) AddRoleForUser(ctx context.Context, user, role string) (bool, error)
- func (e *Enforcer) DeletePermission(ctx context.Context, permission ...string) (bool, error)
- func (e *Enforcer) DeletePermissionForUser(ctx context.Context, user string, permission ...string) (bool, error)
- func (e *Enforcer) DeletePermissionsForUser(ctx context.Context, user string) (bool, error)
- func (e *Enforcer) DeleteRole(ctx context.Context, role string) error
- func (e *Enforcer) DeleteRoleForUser(ctx context.Context, user, role string) (bool, error)
- func (e *Enforcer) DeleteRolesForUser(ctx context.Context, user string) (bool, error)
- func (e *Enforcer) DeleteUser(ctx context.Context, user string) (bool, error)
- func (e *Enforcer) Enforce(ctx context.Context, params ...interface{}) (bool, error)
- func (e *Enforcer) GetAllActions(ctx context.Context) ([]string, error)
- func (e *Enforcer) GetAllNamedActions(ctx context.Context, ptype string) ([]string, error)
- func (e *Enforcer) GetAllNamedObjects(ctx context.Context, ptype string) ([]string, error)
- func (e *Enforcer) GetAllNamedRoles(ctx context.Context, ptype string) ([]string, error)
- func (e *Enforcer) GetAllNamedSubjects(ctx context.Context, ptype string) ([]string, error)
- func (e *Enforcer) GetAllObjects(ctx context.Context) ([]string, error)
- func (e *Enforcer) GetAllRoles(ctx context.Context) ([]string, error)
- func (e *Enforcer) GetAllSubjects(ctx context.Context) ([]string, error)
- func (e *Enforcer) GetFilteredGroupingPolicy(ctx context.Context, fieldIndex int32, fieldValues ...string) ([][]string, error)
- func (e *Enforcer) GetFilteredNamedGroupingPolicy(ctx context.Context, ptype string, fieldIndex int32, fieldValues ...string) ([][]string, error)
- func (e *Enforcer) GetFilteredNamedPolicy(ctx context.Context, ptype string, fieldIndex int32, fieldValues ...string) ([][]string, error)
- func (e *Enforcer) GetFilteredPolicy(ctx context.Context, fieldIndex int32, fieldValues ...string) ([][]string, error)
- func (e *Enforcer) GetGroupingPolicy(ctx context.Context) ([][]string, error)
- func (e *Enforcer) GetImplicitPermissionsForUser(ctx context.Context, user string, domain ...string) ([][]string, error)
- func (e *Enforcer) GetImplicitRolesForUser(ctx context.Context, name string, domain ...string) ([]string, error)
- func (e *Enforcer) GetNamedGroupingPolicy(ctx context.Context, ptype string) ([][]string, error)
- func (e *Enforcer) GetNamedPolicy(ctx context.Context, ptype string) ([][]string, error)
- func (e *Enforcer) GetPermissionsForUser(ctx context.Context, user string) ([][]string, error)
- func (e *Enforcer) GetPolicy(ctx context.Context) ([][]string, error)
- func (e *Enforcer) GetRolesForUser(ctx context.Context, name string) ([]string, error)
- func (e *Enforcer) GetUsersForRole(ctx context.Context, name string) ([]string, error)
- func (e *Enforcer) HasGroupingPolicy(ctx context.Context, params ...interface{}) (bool, error)
- func (e *Enforcer) HasNamedGroupingPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
- func (e *Enforcer) HasNamedPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
- func (e *Enforcer) HasPermissionForUser(ctx context.Context, user string, permission ...string) (bool, error)
- func (e *Enforcer) HasPolicy(ctx context.Context, params ...interface{}) (bool, error)
- func (e *Enforcer) HasRoleForUser(ctx context.Context, user, role string) (bool, error)
- func (e *Enforcer) LoadPolicy(ctx context.Context) error
- func (e *Enforcer) RemoveFilteredGroupingPolicy(ctx context.Context, fieldIndex int32, fieldValues ...string) (bool, error)
- func (e *Enforcer) RemoveFilteredNamedGroupingPolicy(ctx context.Context, ptype string, fieldIndex int32, fieldValues ...string) (bool, error)
- func (e *Enforcer) RemoveFilteredNamedPolicy(ctx context.Context, ptype string, fieldIndex int32, fieldValues ...string) (bool, error)
- func (e *Enforcer) RemoveFilteredPolicy(ctx context.Context, fieldIndex int32, fieldValues ...string) (bool, error)
- func (e *Enforcer) RemoveGroupingPolicy(ctx context.Context, params ...interface{}) (bool, error)
- func (e *Enforcer) RemoveNamedGroupingPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
- func (e *Enforcer) RemoveNamedPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
- func (e *Enforcer) RemovePolicy(ctx context.Context, params ...interface{}) (bool, error)
- func (e *Enforcer) SavePolicy(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapper around proto.CasbinClient, and can be used to create an Enforcer.
func (*Client) NewEnforcer ¶
NewEnforcer creates an enforcer via file or DB. File: e := casbin.NewEnforcer("path/to/basic_model.conf", "path/to/basic_policy.csv") MySQL DB: a := mysqladapter.NewDBAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/") e := casbin.NewEnforcer("path/to/basic_model.conf", a)
type Config ¶
type Config struct { DriverName string ConnectString string ModelText string DbSpecified bool EnableAcceptJsonRequest bool }
Config contains data needed to create an enforcer.
type Enforcer ¶
type Enforcer struct {
// contains filtered or unexported fields
}
Enforcer is the main interface for authorization enforcement and policy management.
func (*Enforcer) 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.
func (*Enforcer) AddNamedGroupingPolicy ¶
func (e *Enforcer) AddNamedGroupingPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
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.
func (*Enforcer) AddNamedPolicy ¶
func (e *Enforcer) AddNamedPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
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.
func (*Enforcer) AddPermissionForUser ¶
func (e *Enforcer) AddPermissionForUser(ctx context.Context, user string, permission ...string) (bool, error)
AddPermissionForUser adds a permission for a user or role. Returns false if the user or role already has the permission (aka not affected).
func (*Enforcer) 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.
func (*Enforcer) AddRoleForUser ¶
AddRoleForUser adds a role for a user. Returns false if the user already has the role (aka not affected).
func (*Enforcer) DeletePermission ¶
DeletePermission deletes a permission. Returns false if the permission does not exist (aka not affected).
func (*Enforcer) DeletePermissionForUser ¶
func (e *Enforcer) DeletePermissionForUser(ctx context.Context, user string, permission ...string) (bool, error)
DeletePermissionForUser deletes a permission for a user or role. Returns false if the user or role does not have the permission (aka not affected).
func (*Enforcer) DeletePermissionsForUser ¶
DeletePermissionsForUser deletes permissions for a user or role. Returns false if the user or role does not have any permissions (aka not affected).
func (*Enforcer) DeleteRole ¶
DeleteRole deletes a role.
func (*Enforcer) DeleteRoleForUser ¶
DeleteRoleForUser deletes a role for a user. Returns false if the user does not have the role (aka not affected).
func (*Enforcer) DeleteRolesForUser ¶
DeleteRolesForUser deletes all roles for a user. Returns false if the user does not have any roles (aka not affected).
func (*Enforcer) DeleteUser ¶
DeleteUser deletes a user. Returns false if the user does not exist (aka not affected).
func (*Enforcer) Enforce ¶
Enforce decides whether a "subject" can access a "object" with the operation "action", input parameters are usually: (sub, obj, act).
func (*Enforcer) GetAllActions ¶
GetAllActions gets the list of actions that show up in the current policy.
func (*Enforcer) GetAllNamedActions ¶
GetAllNamedActions gets the list of actions that show up in the current named policy.
func (*Enforcer) GetAllNamedObjects ¶
GetAllNamedObjects gets the list of objects that show up in the current named policy.
func (*Enforcer) GetAllNamedRoles ¶
GetAllNamedRoles gets the list of roles that show up in the current named policy.
func (*Enforcer) GetAllNamedSubjects ¶
GetAllNamedSubjects gets the list of subjects that show up in the current named policy.
func (*Enforcer) GetAllObjects ¶
GetAllObjects gets the list of objects that show up in the current policy.
func (*Enforcer) GetAllRoles ¶
GetAllRoles gets the list of roles that show up in the current policy.
func (*Enforcer) GetAllSubjects ¶
GetAllSubjects gets the list of subjects that show up in the current policy.
func (*Enforcer) GetFilteredGroupingPolicy ¶
func (e *Enforcer) GetFilteredGroupingPolicy(ctx context.Context, fieldIndex int32, fieldValues ...string) ([][]string, error)
GetFilteredGroupingPolicy gets all the role inheritance rules in the policy, field filters can be specified.
func (*Enforcer) GetFilteredNamedGroupingPolicy ¶
func (e *Enforcer) GetFilteredNamedGroupingPolicy(ctx context.Context, ptype string, fieldIndex int32, fieldValues ...string) ([][]string, error)
GetFilteredNamedGroupingPolicy gets all the role inheritance rules in the policy, field filters can be specified.
func (*Enforcer) GetFilteredNamedPolicy ¶
func (e *Enforcer) GetFilteredNamedPolicy(ctx context.Context, ptype string, fieldIndex int32, fieldValues ...string) ([][]string, error)
GetFilteredNamedPolicy gets all the authorization rules in the named policy, field filters can be specified.
func (*Enforcer) GetFilteredPolicy ¶
func (e *Enforcer) GetFilteredPolicy(ctx context.Context, fieldIndex int32, fieldValues ...string) ([][]string, error)
GetFilteredPolicy gets all the authorization rules in the policy, field filters can be specified.
func (*Enforcer) GetGroupingPolicy ¶
GetGroupingPolicy gets all the role inheritance rules in the policy.
func (*Enforcer) GetImplicitPermissionsForUser ¶
func (e *Enforcer) GetImplicitPermissionsForUser(ctx context.Context, user string, domain ...string) ([][]string, error)
GetImplicitPermissionsForUser gets implicit permissions for a user or role. Compared to GetPermissionsForUser(), this function retrieves permissions for inherited roles. For example: p, admin, data1, read p, alice, data2, read g, alice, admin
GetPermissionsForUser("alice") can only get: [["alice", "data2", "read"]]. But GetImplicitPermissionsForUser("alice") will get: [["admin", "data1", "read"], ["alice", "data2", "read"]].
func (*Enforcer) GetImplicitRolesForUser ¶
func (e *Enforcer) GetImplicitRolesForUser(ctx context.Context, name string, domain ...string) ([]string, error)
GetImplicitRolesForUser gets implicit roles that a user has. Compared to GetRolesForUser(), this function retrieves indirect roles besides direct roles. For example: g, alice, role:admin g, role:admin, role:user
GetRolesForUser("alice") can only get: ["role:admin"]. But GetImplicitRolesForUser("alice") will get: ["role:admin", "role:user"].
func (*Enforcer) GetNamedGroupingPolicy ¶
GetNamedGroupingPolicy gets all the role inheritance rules in the policy.
func (*Enforcer) GetNamedPolicy ¶
GetNamedPolicy gets all the authorization rules in the named policy.
func (*Enforcer) GetPermissionsForUser ¶
GetPermissionsForUser gets permissions for a user or role.
func (*Enforcer) GetRolesForUser ¶
GetRolesForUser gets the roles that a user has.
func (*Enforcer) GetUsersForRole ¶
GetUsersForRole gets the users that has a role.
func (*Enforcer) HasGroupingPolicy ¶
HasGroupingPolicy determines whether a role inheritance rule exists.
func (*Enforcer) HasNamedGroupingPolicy ¶
func (e *Enforcer) HasNamedGroupingPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
HasNamedGroupingPolicy determines whether a named role inheritance rule exists.
func (*Enforcer) HasNamedPolicy ¶
func (e *Enforcer) HasNamedPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
HasNamedPolicy determines whether a named authorization rule exists.
func (*Enforcer) HasPermissionForUser ¶
func (e *Enforcer) HasPermissionForUser(ctx context.Context, user string, permission ...string) (bool, error)
HasPermissionForUser determines whether a user has a permission.
func (*Enforcer) HasRoleForUser ¶
HasRoleForUser determines whether a user has a role.
func (*Enforcer) LoadPolicy ¶
LoadPolicy reloads the policy from file/database.
func (*Enforcer) RemoveFilteredGroupingPolicy ¶
func (e *Enforcer) RemoveFilteredGroupingPolicy(ctx context.Context, fieldIndex int32, fieldValues ...string) (bool, error)
RemoveFilteredGroupingPolicy removes a role inheritance rule from the current policy, field filters can be specified.
func (*Enforcer) RemoveFilteredNamedGroupingPolicy ¶
func (e *Enforcer) RemoveFilteredNamedGroupingPolicy(ctx context.Context, ptype string, fieldIndex int32, fieldValues ...string) (bool, error)
RemoveFilteredNamedGroupingPolicy removes a role inheritance rule from the current named policy, field filters can be specified.
func (*Enforcer) RemoveFilteredNamedPolicy ¶
func (e *Enforcer) RemoveFilteredNamedPolicy(ctx context.Context, ptype string, fieldIndex int32, fieldValues ...string) (bool, error)
RemoveFilteredNamedPolicy removes an authorization rule from the current named policy, field filters can be specified.
func (*Enforcer) RemoveFilteredPolicy ¶
func (e *Enforcer) RemoveFilteredPolicy(ctx context.Context, fieldIndex int32, fieldValues ...string) (bool, error)
RemoveFilteredPolicy removes an authorization rule from the current policy, field filters can be specified.
func (*Enforcer) RemoveGroupingPolicy ¶
RemoveGroupingPolicy removes a role inheritance rule from the current policy.
func (*Enforcer) RemoveNamedGroupingPolicy ¶
func (e *Enforcer) RemoveNamedGroupingPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
RemoveNamedGroupingPolicy removes a role inheritance rule from the current named policy.
func (*Enforcer) RemoveNamedPolicy ¶
func (e *Enforcer) RemoveNamedPolicy(ctx context.Context, ptype string, params ...interface{}) (bool, error)
RemoveNamedPolicy removes an authorization rule from the current named policy.
func (*Enforcer) RemovePolicy ¶
RemovePolicy removes an authorization rule from the current policy.