rbac

package
v0.0.0-...-891d2fd Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SameAssignedRoles

func SameAssignedRoles(r, t Role) bool

SameAssignedRoles is an equality test for roles that have been assigned.

func SameRoleDefinitions

func SameRoleDefinitions(r, t Role) bool

SameRoleDefinitions is an equality test for Roles.

Types

type Enforcer

type Enforcer struct {
	Roles                RoleList
	AuthorizationChecker func(http.ResponseWriter, *http.Request, Role) error
	// contains filtered or unexported fields
}

Enforcer is a xhttp handler that is used to make sure that access to a server endpoint is made with the proper roles and/or permissions.

func Enforce

func Enforce(r RoleList, AuthorizationChecker func(http.ResponseWriter, *http.Request, Role) error) Enforcer

Enforce returns a role-based access checking xhttp.Handler. As in the Rolelist AccessGranted method, it takes as argument a function that checks if a user has the proper roles.

func (Enforcer) ServeHTTP

func (e Enforcer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Role

type Role struct {
	UID         string
	Name        string
	Permissions map[string]interface{}
	Duration    time.Duration
	CreatedAt   time.Time
	AssignedOn  time.Time
	ContextKey  *contextKey `json:"-"`
}

Role defines a user role. User roles can be used to grant access to parts of an application to a selection of credited clients. If permissions are added, permissions will have to be checked.

func NewRole

func NewRole(uid string, name string, duration time.Duration, perms ...string) Role

NewRole creates a Role and persists it was not already persisted.

type RoleList

type RoleList struct {
	Roles      map[*contextKey]Role
	AssignRole func(http.ResponseWriter, *http.Request, Role) error
	// contains filtered or unexported fields
}

RoleList defines a list of roles that may be enforced simultaneously.

func NewRoleList

func NewRoleList(AssignFunc func(http.ResponseWriter, *http.Request, Role) error, roles ...Role) RoleList

NewRoleList creates a RoleList. The first argument is the function used to assign roles in response to a http request to be granted said roles.

func (RoleList) ServeHTTP

func (rl RoleList) ServeHTTP(w http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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