Documentation ¶
Index ¶
- func SetAdapter(adapter persist.Adapter)
- func SetAuthorizer(cnf *conf.Configuration, client *ent.Client, opts ...entadapter.Option) error
- type Authorizer
- func (au *Authorizer) BaseEnforcer() *casbin.Enforcer
- func (au *Authorizer) Eval(ctx context.Context, args *security.EvalArgs) (bool, 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) ([]string, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetAdapter ¶
SetAdapter sets the default adapter for the enforcer.
func SetAuthorizer ¶
func SetAuthorizer(cnf *conf.Configuration, client *ent.Client, opts ...entadapter.Option) error
SetAuthorizer set the default authorizer for security package.
Types ¶
type Authorizer ¶
type Authorizer struct { Enforcer casbin.IEnforcer Watcher persist.Watcher // 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 returns a new authenticator with CachedEnforcer and redis watcher by application configuration. Configuration example:
authz:
autoSave: false expireTime: 1h watcherOptions: options: addr: "localhost:6379" channel: "/casbin" model: /path/to/model.conf policy: /path/to/policy.csv
. 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.
func (*Authorizer) BaseEnforcer ¶
func (au *Authorizer) BaseEnforcer() *casbin.Enforcer
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. tenant allows not set.
func (*Authorizer) QueryAllowedResourceConditions ¶
func (au *Authorizer) QueryAllowedResourceConditions(ctx context.Context, args *security.EvalArgs) ([]string, error)
QueryAllowedResourceConditions returns the allowed resource conditions for the user in domain. if the user don't have any permission, return nil.
type Option ¶
type Option func(*Authorizer)