auth

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AdminUser = NewUser("ADMIN_USER", nil, true, nil)

This user has all privileges for all resources.

View Source
var PrivilegeList []Privilege

Functions

func APIResource

func APIResource(p string) string

func DatabaseResource

func DatabaseResource(database string) string

Types

type Action

type Action struct {
	Resource  string
	Privilege Privilege
}

type Interface

type Interface interface {
	Authenticate(username, password string) (User, error)
	User(username string) (User, error)
	SubscriptionUser(token string) (User, error)
	GrantSubscriptionAccess(token, db, rp string) error
	ListSubscriptionTokens() ([]string, error)
	RevokeSubscriptionAccess(token string) error
}

Interface for authenticating and retrieving users.

type Privilege

type Privilege uint
const (
	NoPrivileges Privilege = 1 << iota

	ReadPrivilege
	WritePrivilege
	DeletePrivilege

	AllPrivileges
)

func (Privilege) String

func (p Privilege) String() string

type User

type User struct {
	// contains filtered or unexported fields
}

This structure is designed to be immutable, to avoid bugs/exploits where the user could be modified by external code. For this reason all fields are private and methods are value receivers.

func NewUser

func NewUser(name string, hash []byte, admin bool, privileges map[string][]Privilege) User

Create a user with the given privileges.

func (User) AuthorizeAction

func (u User) AuthorizeAction(action Action) error

Determine wether the user is authorized to take the action. Returns nil if the action is authorized, otherwise returns an error describing the needed permissions.

func (User) Hash

func (u User) Hash() []byte

Return a copy of the user's password hash

func (User) IsAdmin

func (u User) IsAdmin() bool

Report whether the user is an Admin user

func (User) Name

func (u User) Name() string

Determine wether the user is authorized to take the action.

func (User) Privileges

func (u User) Privileges() map[string][]Privilege

Return a copy of the privileges the user has.

Jump to

Keyboard shortcuts

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