Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConfigDefault = Config{ ModelFilePath: "./model.conf", PolicyAdapter: fileadapter.NewAdapter("./policy.csv"), Lookup: func(c *fiber.Ctx) string { return "" }, Unauthorized: func(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusUnauthorized) }, Forbidden: func(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusForbidden) }, }
var OptionsDefault = Options{ ValidationRule: MatchAllRule, PermissionParser: PermissionParserWithSeperator(":"), }
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // ModelFilePath is path to model file for Casbin. // Optional. Default: "./model.conf". ModelFilePath string // PolicyAdapter is an interface for different persistent providers. // Optional. Default: fileadapter.NewAdapter("./policy.csv"). PolicyAdapter persist.Adapter // Enforcer is an enforcer. If you want to use your own enforcer. // Optional. Default: nil Enforcer *casbin.Enforcer // Lookup is a function that is used to look up current subject. // An empty string is considered as unauthenticated user. // Optional. Default: func(c *fiber.Ctx) string { return "" } Lookup func(*fiber.Ctx) string // Optional. Default: func(c *fiber.Ctx) error { return c.SendStatus(401) } Unauthorized fiber.Handler // Forbidden defines the response body for forbidden responses. // Optional. Default: func(c *fiber.Ctx) error { return c.SendStatus(403) } Forbidden fiber.Handler }
Config holds the configuration for the middleware
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware ...
func New ¶
func New(config ...Config) *Middleware
New creates an authorization middleware for use in Fiber
func (*Middleware) RequiresPermissions ¶
func (m *Middleware) RequiresPermissions(permissions []string, opts ...Option) fiber.Handler
RequiresPermissions tries to find the current subject and determine if the subject has the required permissions according to predefined Casbin policies.
func (*Middleware) RequiresRoles ¶
func (m *Middleware) RequiresRoles(roles []string, opts ...Option) fiber.Handler
RequiresRoles tries to find the current subject and determine if the subject has the required roles according to predefined Casbin policies.
func (*Middleware) RoutePermission ¶
func (m *Middleware) RoutePermission() fiber.Handler
RoutePermission tries to find the current subject and determine if the subject has the required permissions according to predefined Casbin policies. This method uses http Path and Method as object and action.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option specifies casbin configuration options.
func WithPermissionParser ¶
func WithPermissionParser(pp PermissionParserFunc) Option
func WithValidationRule ¶
func WithValidationRule(vr ValidationRule) Option
type OptionFunc ¶
type OptionFunc func(*Options)
type Options ¶
type Options struct { ValidationRule ValidationRule PermissionParser PermissionParserFunc }
Options holds Options of middleware
type PermissionParserFunc ¶
PermissionParserFunc is used for parsing the permission to extract object and action usually
func PermissionParserWithSeperator ¶
func PermissionParserWithSeperator(sep string) PermissionParserFunc
type ValidationRule ¶
type ValidationRule int
const ( MatchAllRule ValidationRule = iota AtLeastOneRule )