user

package
v0.0.0-...-daa0946 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package user contains structures and functions to manage users, their roles and permissions.

Index

Constants

This section is empty.

Variables

View Source
var FilePermissionTable = make(map[string]map[string][]FilePermission)

FilePermissionTable is a map of UserID to a map of File to FilePermission

View Source
var RoleTable = make(map[string]Role)

RoleTable is a map of RoleID to Role

View Source
var UserTable = make(map[string]User)

UserTable is a map of user email to User

Functions

func Authenticate

func Authenticate(email, password, file string) error

Authenticate authenticates a user's credentials for access to the system.

func AuthenticateForRole

func AuthenticateForRole(email, password, file string, roleType RoleType) error

AuthenticateForRole authenticates a user's credentials and then validates if the user is of a required role for that operation.

func Authorize

func Authorize(email, password, file, resource string) error

Authorize authorizes acccess to a resource.

func ChangePassword

func ChangePassword(email, password, newPassword, confirmPassword, file string) error

ChangePassword changes the password for a user.

func CreateUser

func CreateUser(email, password, description, roleID, file, adminUsr, adminPwd string) error

CreateUser creates a new user.

func ExpireUser

func ExpireUser(email string)

ExpireUser sets the expiration date of the user to now.

func GetRoleIDFor

func GetRoleIDFor(name string) (string, error)

GetRoleIDFor returns the RoleID for a RoleName

func ListRoles

func ListRoles() map[string]interface{}

ListRoles lists all available roles.

Types

type AccessPermissions

type AccessPermissions int

AccessPermissions is a enumeration constant for resource access permissions.

const (
	// Read indicates read right
	Read AccessPermissions = iota
	// Write indicates write right
	Write
	// ReadWrite indicates both read and write right
	ReadWrite
)

type Configuration

type Configuration struct {
	Location           string
	FileAccessProtocol Protocol
}

Configuration represents userd configuration.

func NewConfig

func NewConfig(file string) (*Configuration, error)

NewConfig builds a new Configuration by taking a file directory as an input. For e.g.

file:/etc/userd https://openspock.org/userd

func (*Configuration) InitRead

func (c *Configuration) InitRead() error

InitRead initializes userd configuration.

1. init user conf 2. int fperm conf

func (*Configuration) WriteFP

func (c *Configuration) WriteFP(fp *FilePermission) error

WriteFP writes a FilePermission to file permission conf file.

func (*Configuration) WriteRole

func (c *Configuration) WriteRole(r *Role) error

WriteRole writes a role to the role conf file.

func (*Configuration) WriteUser

func (c *Configuration) WriteUser(u *User) error

WriteUser writes a user to the user conf file.

type FilePermission

type FilePermission struct {
	File       string
	UserID     string
	Role       Role
	Assignment time.Time
	Expiration time.Time
}

FilePermission represents permissions per file/ resource, per user.

Either UserID or Role is mandatory

A file or resource can be identified with a URL. Examples - file:/etc/userd/user.conf https://openspock.org/userd/user.conf

FilePermissions are persisted in fperm.conf

func CreateFP

func CreateFP(file string, user *User, role *Role, expiration time.Time, location string) (*FilePermission, error)

CreateFP creates a new file permission for either a user or a role.

func NewFP

func NewFP(file string, user User, role Role, expiration time.Time) (*FilePermission, error)

NewFP creates new FilePermission

type Protocol

type Protocol int

Protocol has configuration file access protocol.

const (
	// File is local file access protocol.
	File Protocol = iota << 1
)

type Role

type Role struct {
	RoleID string
	Name   string
}

Role represents a role assignable to a User

func CreateRole

func CreateRole(name, file string) (*Role, error)

CreateRole creates a new role.

func NewRole

func NewRole(name string) (*Role, error)

NewRole creates a new Role and returns it.

type RoleType

type RoleType int

RoleType helps define the type of a role that can be used by operations to ascertain that only users with certain roles can perform these operations.

const (
	// Disregard role type for this operation
	Disregard RoleType = iota
	// Admin role type for this operation
	Admin
)

func (RoleType) String

func (t RoleType) String() string

type User

type User struct {
	UserID string

	Salt string

	Email       string
	Description string
	Since       time.Time
	RoleID      string
	// contains filtered or unexported fields
}

User represents a user which requires authorization. Authentication is managed separately using FilePermission

Users are stored in user.conf

func NewUser

func NewUser(email, description, secret, salt, hash, roleID string) (*User, error)

NewUser creates a new user and stores it in user conf.

func (User) String

func (u User) String() string

Jump to

Keyboard shortcuts

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