casbin

package
v0.0.0-...-9fdf600 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetAdapter

func SetAdapter(adapter persist.Adapter)

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

func (au *Authorizer) Eval(ctx context.Context, args *security.EvalArgs) (bool, error)

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) Prepare

func (au *Authorizer) Prepare(ctx context.Context, kind security.ArnKind, arnParts ...string) (*security.EvalArgs, error)

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL