casbin

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWildcardItem = "*"
)

Variables

This section is empty.

Functions

func DefaultModel

func DefaultModel() string

DefaultModel returns the default Casbin model string.

func NewAuthorizer

func NewAuthorizer(cfg *authzv1.Authorizer, opts ...Option) (authz.Authorizer, error)

NewAuthorizer creates a new Authorizer instance.

Types

type Authorizer

type Authorizer struct {
	*Options // Embed a pointer to Options
	// contains filtered or unexported fields
}

Authorizer is a struct that implements the Authorizer interface.

func New added in v1.2.0

func New(opts *Options, logger log.Logger) (*Authorizer, error)

New creates a new Authorizer instance from a pre-built Options object and a logger. This is the recommended way to create an Authenticator when you need to customize its dependencies or when you are creating it as part of a dependency injection system.

func (*Authorizer) Authorized

func (auth *Authorizer) Authorized(ctx context.Context, principal security.Principal, spec authz.RuleSpec) (bool, error)

Authorized checks if a principal is authorized. It uses a fast path for standard models and a dynamic path for custom models, ensuring both performance and flexibility.

type Option

type Option = options.Option

func WithFileModel

func WithFileModel(path string) Option

WithFileModel sets the Casbin model from a file path. It panics if the model cannot be created from the file.

func WithModel

func WithModel(m casbinmodel.Model) Option

WithModel sets the Casbin model for the Authorizer.

func WithNameModel

func WithNameModel(name string) Option

WithNameModel sets the Casbin model by its predefined name. It panics if the named model cannot be found or created.

func WithPolicyAdapter

func WithPolicyAdapter(p persist.Adapter) Option

WithPolicyAdapter sets the Casbin policy adapter.

func WithStringModel

func WithStringModel(str string) Option

WithStringModel sets the Casbin model from a string. It panics if the model cannot be created from the string.

func WithWatcher

func WithWatcher(w persist.Watcher) Option

WithWatcher sets the Casbin watcher for dynamic policy updates.

func WithWildcardItem

func WithWildcardItem(item string) Option

WithWildcardItem sets the wildcard item for domain matching.

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options holds configuration for the Casbin Authorizer, used with optionutil. All fields are unexported to enforce configuration via functional options, ensuring a controlled and validated setup process.

func FromOptions

func FromOptions(opts ...Option) *Options

FromOptions creates a new Options struct by applying the given functional options.

func NewOptions added in v1.2.0

func NewOptions(cfg *authzv1.Authorizer, opts ...Option) (*Options, error)

NewOptions creates a new Options object from the given configuration and functional options. It is responsible for parsing the protobuf configuration and merging it with any provided functional options. This function is intended to be used when you need to create the configuration options separately before creating the Authorizer instance.

Directories

Path Synopsis
Package adapter implements the functions, types, and interfaces for the module.
Package adapter implements the functions, types, and interfaces for the module.
internal
model
Package model embedding the model files for Casbin.
Package model embedding the model files for Casbin.
policy
Package policy embedding the policy files for Casbin.
Package policy embedding the policy files for Casbin.

Jump to

Keyboard shortcuts

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