qra

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2017 License: MIT Imports: 2 Imported by: 0

README

####Quick and Robust Admin interfaces written in Go

License MIT Build Status Go Report Card GoDoc Coverage Status

QRA is a collection of interfaces for common tasks building authentication and authorization-designation policies.

diagram

#####Installation:

go get gopkg.in/jimmy-go/qra.v0

#####Description: In order to understand QRA you must know:

Identity is a responsible party person or non-person entity.

Authentication is the means used to prove identity or take on a role.

Authorization means access policy by explicitly granting a right.

QRA is not limited to administrator sites, you can gain permission granularity for microservices too.

// Identity interface for management of identities (users).
type Identity interface {
	// Me method returns identity name (username, userID, etc.)
	Me() string

	// Session method returns current session or error.
	// If session is found then is written to dst.
	Session(dst interface{}) error
}

// Authentication interface for session management of users.
type Authentication interface {
	// Authenticate method makes login to user. It will call
	// Me method to retrieve Identity username, validate
	// if not session is present with Session method.
	// Developer implementations of Authentication interface
	// MUST have session storage methods.
	Authenticate(ctx Identity, password string, dst interface{}) error

	// Close method will delete session of current identity.
	Close(ctx Identity) error
}

// Designation interface stands for Authorization-Designation
// operations.
type Designation interface {
	// Search permission-designations and binds table designation content to v.
	// Return error if not permission for identity was found.
	// Filter parameter will allow search permissions by
	// name, resource and has pagination (e.g.: `permission:resource/1-36` or
	// `permission:resource/since/123abc`).
	Search(ctx Identity, v interface{}, filter string) error

	// Allow method shares identity permission over resource with dst.
	Allow(ctx Identity, password, permission, resource, dst string, expiresAt time.Time) error

	// Revoke method will revoke a permission that ctx previously
	// give to dst.
	Revoke(ctx Identity, password, permission, resource, dst string) error
}

#####Usage:

QRA needs a default manager that you must register at init time.

qra.MustRegisterAuthentication(yourAuthentication)
qra.MustRegisterDesignation(yourDesignationAuthorization)

Inside your project call some qra function.

func MyLoginHandler(w http.Response, r *http.Request) {

    username := r.Form.Get("username")
    ctx := &SomeContext{User: username} // must satisfy qra.Identity interface

    password := r.Form.Get("password")

    var token string
    err := qra.Authenticate(ctx, password, &token) error {
    // check errors...
}

#####One more thing... QRA has a collection of managers with several database integrations:

qra/litemanager.Connect("sqlite", "url://somedatabasefile.sql") registers a manager with sqlite integration.

qra/pgmanager.Connect("postgres", "url://somedatabasefile.sql") registers a manager with PostgreSQL integration.

qra/rawmanager.Connect() is a manager with only cache data (never use it on production, demonstration purposes only).

#####Examples:

See the QRA examples for real world usage.

#####License:

MIT License

Copyright (c) 2016 Angel Del Castillo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package qra contains QuickRobutsAdmin interfaces for RBAC, MAC, DAC, ABAC and ZBAC systems.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultManager is the default QRA Manager.
	DefaultManager = defaultQRA()

	// ErrAuthenticationNil returned when QRA authentication
	// interface is nil.
	ErrAuthenticationNil = errors.New("qra: authentication interface is nil")

	// ErrDesignationNil returned when QRA authorization-designation
	// interface is nil.
	ErrDesignationNil = errors.New("qra: authorization-designation interface is nil")

	ErrSystemNotFound       = errors.New("system identity not found")
	ErrInvalidCredentials   = errors.New("invalid username or password")
	ErrResourceNotSpecified = errors.New("resource not specified")
	ErrPasswordSize         = errors.New("invalid password size")
	// ErrOwnSign error returned when an identity try to auto sign a permission.
	ErrOwnSign = errors.New("can't allow own permission")
	// ErrIdentityNotFound error returned when identity not exists in database.
	ErrIdentityNotFound = errors.New("identity not found")
)

Functions

func Allow added in v0.0.2

func Allow(ctx Identity, password, permission, resource, dst string, expiresAt time.Time) error

Allow wrapper for DefaultManager.Designation.Allow.

func Authenticate added in v0.0.2

func Authenticate(ctx Identity, password string, dst interface{}) error

Authenticate wrapper for DefaultManager.Authentication.Authenticate.

func Close added in v0.0.2

func Close(ctx Identity) error

Close wrapper for DefaultManager.Authentication.Close.

func MustRegisterAuthentication added in v0.0.2

func MustRegisterAuthentication(a Authentication)

MustRegisterAuthentication calls RegisterAuthentication function or panics.

func MustRegisterDesignation added in v0.0.2

func MustRegisterDesignation(d Designation)

MustRegisterDesignation calls RegisterDesignation function or panics.

func RegisterAuthentication added in v0.0.2

func RegisterAuthentication(a Authentication) error

RegisterAuthentication replaces Authentication of DefaultManager.

func RegisterDesignation added in v0.0.2

func RegisterDesignation(d Designation) error

RegisterDesignation replaces Authentication of DefaultManager.

func Revoke added in v0.0.2

func Revoke(ctx Identity, password, permission, resource, dst string) error

Revoke wrapper for DefaultManager.Designation.Revoke.

func Search(ctx Identity, v interface{}, filter string) error

Search wrapper for DefaultManager.Designation.Search.

Types

type Authentication added in v0.0.2

type Authentication interface {
	// Authenticate method makes login to user. It will call
	// Me method to retrieve Identity username, validate
	// if not session is present with Session method.
	Authenticate(ctx Identity, password string, dst interface{}) error

	// Close method will delete session of current identity.
	Close(ctx Identity) error
}

Authentication interface for session management of users.

type Designation added in v0.0.2

type Designation interface {
	// Search permission-designations and binds table designation content to v.
	// Return error if not permission for identity was found.
	// Filter parameter will allow search permissions by
	// name, resource and has pagination (e.g.: `permission:resource/1-36` or
	// `permission:resource/since/123abc`).
	Search(ctx Identity, v interface{}, filter string) error

	// Allow method shares identity permission over resource with dst.
	Allow(ctx Identity, password, permission, resource, dst string, expiresAt time.Time) error

	// Revoke method will revoke a permission that ctx previously
	// give to dst.
	Revoke(ctx Identity, password, permission, resource, dst string) error
}

Designation interface stands for Authorization-Designation operations.

type Identity added in v0.0.2

type Identity interface {
	// Me method returns identity name (username, userID, etc.)
	Me() string

	// Session method binds the current session. If identity has no session error
	// is returned
	Session(dst interface{}) error
}

Identity interface for management of identities (users).

type QRA

type QRA struct {
	Authentication           Authentication
	DesignationAuthorization Designation
}

QRA struct is the container for common administrator operations split between interfaces.

func New

func New(a Authentication, d Designation) (*QRA, error)

New returns a new QRA manager.

Directories

Path Synopsis
cmd
pgterm
Package main contains terminal session for pgmanager.
Package main contains terminal session for pgmanager.
Package pgmanager contains a QRA manager for PostgreSQL.
Package pgmanager contains a QRA manager for PostgreSQL.
Package qmenu contains QuickRobutsAdmin interfaces for RBAC, MAC, DAC, ABAC and ZBAC systems.
Package qmenu contains QuickRobutsAdmin interfaces for RBAC, MAC, DAC, ABAC and ZBAC systems.
Package qsess contains QRA integration with gorilla sessions cookie store.
Package qsess contains QRA integration with gorilla sessions cookie store.

Jump to

Keyboard shortcuts

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