Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultConfig = Config{ Skipper: middleware.DefaultSkipper, ContextKey: "roles", DefaultRole: "any", RolesHeader: "X-Roles", ForbiddenMessage: "Access to this resource has been restricted", }
Functions ¶
func CasbinWithConfig ¶
func CasbinWithConfig(config Config) echo.MiddlewareFunc
Types ¶
type Config ¶
type Config struct {
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper
// Enforce defines the enforcer used for
// authorization enforcement and policy management.
// Required.
Enforcer *casbin.Enforcer
// ContextKey defines the key that will be used to
// read the roles on the echo.Context for enforcing.
// Optional. Defaults to "roles".
ContextKey string
// DefaultRoles defines
// Optional. Defaults to "any".
DefaultRole string
// EnableRolesHeader enables the RolesHeader.
// Optional. Defaults to false.
EnableRolesHeader bool
// RolesHeader defines the header that will be used to
// read in the roles if EnableRolesHeader is set to true.
// Roles should be separated by commas. E.g. "role1,role2".
// Optional. Defaults to false.
RolesHeader string
// RolesHeaderFunc defines the function that will validate that
// a client is allowed to the use roles they passed via the RolesHeader.
// The RolesHeader value will be passed unmodified, so you will need
// to parse it in this function yourself. The DefaultRole will be passed
// if the RolesHeader is empty. The roles that you want to have
// enforced will need to be returned in a slice: []string{"role1, "role2"}.
// Optional.
RolesHeaderFunc func(string) ([]string, error)
// RolesFunc defines the function that will retrieve the roles
// to be passed to the Enforcer.
// Takes precedence over ContextKey and RolesHeader if they're defined.
// Optional.
RolesFunc func(echo.Context) ([]string, error)
// ForbiddenMessage defines the message that will be
// returned when authorization fails.
// Optional. Defaults to "Access to this resource has been restricted".
ForbiddenMessage string
// SuccessFunc defines the function that will run
// when authorization succeeds.
// Optional.
SuccessFunc func(string, string, string)
// FailureFunc defines the function that will run
// when authorization fails.
// Optional.
FailureFunc func([]string, string, string)
}
Click to show internal directories.
Click to hide internal directories.