Documentation
¶
Index ¶
- func SetAuthorizer(cnf *conf.Configuration, opts ...Option) error
- type Authorizer
- func (au *Authorizer) BaseEnforcer() casbin.IEnforcer
- func (au *Authorizer) Eval(ctx context.Context, args *security.EvalArgs) (pass bool, err error)
- func (au *Authorizer) Prepare(ctx context.Context, kind security.ArnKind, arnParts ...string) (*security.EvalArgs, error)
- func (au *Authorizer) QueryAllowedResourceConditions(ctx context.Context, args *security.EvalArgs) (conditions []string, err error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetAuthorizer ¶
func SetAuthorizer(cnf *conf.Configuration, opts ...Option) error
SetAuthorizer set the default authorizer for security package.
Types ¶
type Authorizer ¶
type Authorizer struct {
Enforcer casbin.IEnforcer
Watcher persist.Watcher
Adapter persist.Adapter
// contains filtered or unexported fields
}
Authorizer is an Authorizer feature base on casbin.
func NewAuthorizer ¶
func NewAuthorizer(cnf *conf.Configuration, opts ...Option) (au *Authorizer, err error)
NewAuthorizer 根据配置创建验证器. Configuration example:
authz:
autoSave: false
expireTime: 1h
watcherOptions:
options:
addr: "localhost:6379"
channel: "/casbin"
model: /path/to/model.conf
policy: /path/to/policy.csv
cache:
size: 1000
ttl: 1m
. autoSave in watcher callback should be false. but set false will cause casbin main nodes lost save data. we will improve in the future.current use database unique index to avoid duplicate data.
expireTime if set for casbin.CachedEnforcer, if not set will use normal casbin.Enforcer.
cache node is for independent cache usding for cached the Authorizer itself. cache.ttl default 1 minute.
func (*Authorizer) BaseEnforcer ¶
func (au *Authorizer) BaseEnforcer() casbin.IEnforcer
BaseEnforcer returns the base enforcer. casbin api is not broadcasting to enforcer interface. so need to use base enforcer.
func (*Authorizer) Eval ¶
Eval checks if the user has permission to do an operation on a resource. tenant will be used as domain.
func (*Authorizer) QueryAllowedResourceConditions ¶
func (au *Authorizer) QueryAllowedResourceConditions(ctx context.Context, args *security.EvalArgs) (conditions []string, err error)
QueryAllowedResourceConditions returns the allowed resource conditions for the user in domain. if the user don't have any permission, return nil. A ResourceCondition's operation should be use `data`.
type Option ¶
type Option func(*Authorizer)