gorbac

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2017 License: MIT Imports: 6 Imported by: 0

README

go-rbac

Build Status License

A simplified role-based access control (RBAC) implementation, inspired by gorbac

v1.0.0 status

Purpose

  • Only three objects: identity, role and permission
  • One to many relationship between identity and roles.
  • One to many relationship between role and permissions.
  • One to many relationship between role and parent roles(inheritance relationship).

Features

  • An identity has one or more roles.
  • A role has one or more permissions.
  • A role can inherit one or more other roles(inheriting their permissions).
  • Both identity, role, permission are defined by ID string.
  • Pure no third party library dependent.

Installation

go get -u github.com/WindomZ/go-rbac

License

The MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRoleNotExist   error = errors.New("gorbac: Role does not exist")
	ErrPermissionNoID       = errors.New("gorbac: Permission does not has ID")
)

Functions

This section is empty.

Types

type AssertionAssignFunc

type AssertionAssignFunc func(string) bool

type AssertionFunc

type AssertionFunc func(RBAC, string, Permission) bool

type AssertionIDFunc

type AssertionIDFunc func(RBAC, string, string) bool

type Permission added in v0.5.1

type Permission interface {
	ID() string
	Match(Permission) bool
	MatchID(string) bool
}

func NewPermission added in v0.5.1

func NewPermission(id string) Permission

NewPermission returns a Permission instance with `id`

type Permissions added in v0.5.1

type Permissions map[string]Permission

type RBAC added in v0.5.1

type RBAC interface {
	SetParents(string, []string) error
	GetParents(string) ([]string, error)
	SetParent(string, string) error
	RemoveParent(string, string) error

	AddRole(Role) error
	RemoveRole(string) error
	GetRole(string) (Role, []string, error)
	GetRoleOnly(string) (Role, error)

	IsGranted(string, Permission) bool
	IsGrantedID(string, string) bool
	IsAssertGranted(string, Permission, AssertionFunc) bool
	IsAssertGrantedID(string, string, AssertionIDFunc) bool
}

func NewRBAC added in v0.5.1

func NewRBAC() RBAC

NewRBAC returns a RBAC structure. The default role structure will be used.

type Role added in v0.5.1

type Role interface {
	ID() string
	Tag() string

	Assign(Permission) error
	AssignID(string) error
	AssertAssignIDs([]string, AssertionAssignFunc)

	Revoke(Permission) error
	RevokeID(string) error

	Permit(Permission) bool
	PermitID(string) bool

	Permissions() []Permission
	PermissionIDs() []string

	Sign(string) string
}

func NewRole added in v0.5.1

func NewRole(id string, tag ...string) Role

NewRole returns a Role structure.

type Roles added in v0.5.1

type Roles map[string]Role

Jump to

Keyboard shortcuts

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