Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetAdapter ¶
SetAdapter sets the default adapter for the enforcer.
func SetDefaultAuthorization ¶
func SetDefaultAuthorization(au *Authorization)
SetDefaultAuthorization sets the default authorization.
func SetDefaultRequestParserFunc ¶ added in v0.2.6
func SetDefaultRequestParserFunc(f RequestParserFunc)
SetDefaultRequestParserFunc sets the default request parser function.
notice: in web middleware that will implicit initial authorization component, web permission check use appcode,c.Request.URL.Path, request.Method as default enforce check, you should set this first if not default.
Types ¶
type Authorization ¶
type Authorization struct { Enforcer casbin.IEnforcer Watcher persist.Watcher // RequestParser is the function to parse cashbin request according cashbin Model RequestParser RequestParserFunc // contains filtered or unexported fields }
Authorization is an Authorization feature base on casbin.
var (
DefaultAuthorization *Authorization
)
func NewAuthorization ¶
func NewAuthorization(cnf *conf.Configuration, opts ...Option) (au *Authorization, err error)
NewAuthorization 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
func (*Authorization) BaseEnforcer ¶ added in v0.2.5
func (au *Authorization) BaseEnforcer() *casbin.Enforcer
BaseEnforcer returns the base enforcer. casbin api is not broadcasting to enforcer interface. so need to use base enforcer.
func (*Authorization) CheckPermission ¶ added in v0.2.3
func (au *Authorization) CheckPermission(ctx context.Context, identity security.Identity, item *security.PermissionItem) (bool, error)
type Option ¶ added in v0.2.3
type Option func(*Authorization)
func WithRequestParseFunc ¶ added in v0.2.3
func WithRequestParseFunc(f RequestParserFunc) Option
WithRequestParseFunc set the request parser function.