rbac

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: LGPL-2.1 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrForbiddenAccess = server.NewHTTPError(http.StatusForbidden, "FORBIDDEN", "You don't have permission to access the requested resource")
	ErrForbiddenAction = server.NewHTTPError(http.StatusForbidden, "FORBIDDEN", "You don't have permission to perform this action")
)

Custom errors

View Source
var DefaultConfig = Config{
	Model:     NewRBACModel(),
	Adapter:   nil,
	GormDB:    nil,
	EnableLog: true,
}

DefaultConfig represents the default configuration

Functions

func NewRBACModel

func NewRBACModel() model.Model

NewRBACModel initializes the RBAC casbin model

func NewRBACWithDomainModel

func NewRBACWithDomainModel() model.Model

NewRBACWithDomainModel initializes the RBAC with domain model

func NewRBACWithLevelInheritanceModel

func NewRBACWithLevelInheritanceModel() model.Model

NewRBACWithLevelInheritanceModel initializes the RBAC with level inheritance model

func NormalizeRole

func NormalizeRole(r int) string

NormalizeRole corrects role ID for RBAC service

func NormalizeUser

func NormalizeUser(uid int) string

NormalizeUser corrects user ID for RBAC service

func UnnormalizeRole

func UnnormalizeRole(r string) int

UnnormalizeRole converts RBAC role back to normal

Types

type Config

type Config struct {
	Model     model.Model
	Adapter   persist.Adapter
	GormDB    *gorm.DB
	EnableLog bool
}

Config represents the config for RBAC service

type Intf

type Intf interface {
	Enforce(rvals ...interface{}) bool
}

Intf represents common interface for the RBAC service

type RBAC

type RBAC struct {
	*casbin.Enforcer
}

RBAC is RBAC application service

func New

func New() *RBAC

New creates new RBAC service with default configuration

func NewWithConfig

func NewWithConfig(cfg Config) *RBAC

NewWithConfig creates new RBAC service with custom configuration

func (*RBAC) AddGroupingPolicy2

func (s *RBAC) AddGroupingPolicy2(params ...interface{}) bool

AddGroupingPolicy2 adds a role inheritance rule to the current policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.

func (*RBAC) AddRoleForUserID

func (s *RBAC) AddRoleForUserID(uid int, role string) bool

AddRoleForUserID adds a role for a user by ID. Returns false if the user already has the role (aka not affected).

func (*RBAC) DeleteRoleForUserID

func (s *RBAC) DeleteRoleForUserID(uid int, role string) bool

DeleteRoleForUserID deletes a role for a user ID. Returns false if the user does not have the role (aka not affected).

func (*RBAC) DeleteRolesForUserID

func (s *RBAC) DeleteRolesForUserID(uid int) bool

DeleteRolesForUserID delete all roles for a user ID. Returns false if the user does not have any roles (aka not affected).

func (*RBAC) DeleteUserID

func (s *RBAC) DeleteUserID(uid int) bool

DeleteUserID deletes a user ID. Returns false if the user does not exist (aka not affected).

func (*RBAC) EnforceUserID

func (s *RBAC) EnforceUserID(uid int, rvals ...interface{}) bool

EnforceUserID determines whether a user ID has permission to do stuff

func (*RBAC) GetRolesForUserID

func (s *RBAC) GetRolesForUserID(uid int) []string

GetRolesForUserID gets the roles that a user has.

func (*RBAC) HasRoleForUserID

func (s *RBAC) HasRoleForUserID(uid int, role string) bool

HasRoleForUserID determines whether a user has a role.

func (*RBAC) RemoveGroupingPolicy2

func (s *RBAC) RemoveGroupingPolicy2(params ...interface{}) bool

RemoveGroupingPolicy2 removes a role inheritance rule from the current policy.

func (*RBAC) ReplaceRoleForUserID

func (s *RBAC) ReplaceRoleForUserID(uid int, role string) bool

ReplaceRoleForUserID removes all current roles then adds the new role for a user ID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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