Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrSubFnNil = errors.New("subFn is nil")
)
Functions ¶
This section is empty.
Types ¶
type CasbinMiddleware ¶
type CasbinMiddleware struct {
// contains filtered or unexported fields
}
func NewCasbinMiddleware ¶
func NewCasbinMiddleware(modelFile string, policyAdapter interface{}, subFn SubjectFn) (*CasbinMiddleware, error)
NewCasbinMiddleware returns a new CasbinMiddleware using Casbin's Enforcer internally. modelFile is the file path to Casbin model file e.g. path/to/rbac_model.conf. policyAdapter can be a file or a DB adapter. File: path/to/basic_policy.csv MySQL DB: mysqladapter.NewDBAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/") subFn is a function that looks up the current subject in runtime and returns an empty string if nothing found.
func NewCasbinMiddlewareFromEnforcer ¶
func NewCasbinMiddlewareFromEnforcer(e *casbin.Enforcer, subFn SubjectFn) (*CasbinMiddleware, error)
Create from given Enforcer.
func (*CasbinMiddleware) RequiresPermissions ¶
func (am *CasbinMiddleware) RequiresPermissions(permissions []string, opts ...Option) gin.HandlerFunc
RequiresPermissions tries to find the current subject by calling SubjectFn and determine if the subject has the required permissions according to predefined Casbin policies. permissions are formatted strings. For example, "file:read" represents the permission to read a file. opts is some optional configurations such as the logical operator (default is AND) in case multiple permissions are specified.
func (*CasbinMiddleware) RequiresRoles ¶
func (am *CasbinMiddleware) RequiresRoles(requiredRoles []string, opts ...Option) gin.HandlerFunc
RequiresPermissions tries to find the current subject by calling SubjectFn and determine if the subject has the required roles according to predefined Casbin policies. opts is some optional configurations such as the logical operator (default is AND) in case multiple roles are specified.
type Logic ¶
type Logic int
Logic is the logical operation (AND/OR) used in permission checks in case multiple permissions or roles are specified.