Documentation ¶
Index ¶
- Variables
- func NewRBACModel() model.Model
- func NewRBACWithDomainModel() model.Model
- func NewRBACWithLevelInheritanceModel() model.Model
- func NormalizeRole(r int) string
- func NormalizeUser(uid int) string
- func UnnormalizeRole(r string) int
- type Config
- type Intf
- type RBAC
- func (s *RBAC) AddGroupingPolicy2(params ...interface{}) bool
- func (s *RBAC) AddRoleForUserID(uid int, role string) bool
- func (s *RBAC) DeleteRoleForUserID(uid int, role string) bool
- func (s *RBAC) DeleteRolesForUserID(uid int) bool
- func (s *RBAC) DeleteUserID(uid int) bool
- func (s *RBAC) EnforceUserID(uid int, rvals ...interface{}) bool
- func (s *RBAC) GetRolesForUserID(uid int) []string
- func (s *RBAC) HasRoleForUserID(uid int, role string) bool
- func (s *RBAC) RemoveGroupingPolicy2(params ...interface{}) bool
- func (s *RBAC) ReplaceRoleForUserID(uid int, role string) bool
Constants ¶
This section is empty.
Variables ¶
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
var DefaultConfig = Config{ Model: NewRBACModel(), Adapter: nil, GormDB: nil, EnableLog: true, }
DefaultConfig represents the default configuration
Functions ¶
func NewRBACWithDomainModel ¶
NewRBACWithDomainModel initializes the RBAC with domain model
func NewRBACWithLevelInheritanceModel ¶
NewRBACWithLevelInheritanceModel initializes the RBAC with level inheritance model
func NormalizeRole ¶
NormalizeRole corrects role ID for RBAC service
func NormalizeUser ¶
NormalizeUser corrects user ID for RBAC service
func UnnormalizeRole ¶
UnnormalizeRole converts RBAC role back to normal
Types ¶
type Intf ¶
type Intf interface {
Enforce(rvals ...interface{}) bool
}
Intf represents common interface for the RBAC service
type RBAC ¶
RBAC is RBAC application service
func NewWithConfig ¶
NewWithConfig creates new RBAC service with custom configuration
func (*RBAC) AddGroupingPolicy2 ¶
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 ¶
AddRoleForUserID adds a role for a user by ID. Returns false if the user already has the role (aka not affected).
func (*RBAC) DeleteRoleForUserID ¶
DeleteRoleForUserID deletes a role for a user ID. Returns false if the user does not have the role (aka not affected).
func (*RBAC) DeleteRolesForUserID ¶
DeleteRolesForUserID delete all roles for a user ID. Returns false if the user does not have any roles (aka not affected).
func (*RBAC) DeleteUserID ¶
DeleteUserID deletes a user ID. Returns false if the user does not exist (aka not affected).
func (*RBAC) EnforceUserID ¶
EnforceUserID determines whether a user ID has permission to do stuff
func (*RBAC) GetRolesForUserID ¶
GetRolesForUserID gets the roles that a user has.
func (*RBAC) HasRoleForUserID ¶
HasRoleForUserID determines whether a user has a role.
func (*RBAC) RemoveGroupingPolicy2 ¶
RemoveGroupingPolicy2 removes a role inheritance rule from the current policy.