sec

package
v0.0.0-...-182d01c Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sec is the security implementation used by the CPM application. Key function is to issue tokens and validate them against an RBAC based schema defined and maintained within CPM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBAddRole

func DBAddRole(dbConn *sql.DB, role Role) error

DBAddRole add a role

func DBAddRolePerm

func DBAddRolePerm(dbConn *sql.DB, role string, perm string) error

DBAddRolePerm create a role to perm mapping

func DBAddSession

func DBAddSession(dbConn *sql.DB, uuid string, id string) error

DBAddSession create a user session

func DBAddUser

func DBAddUser(dbConn *sql.DB, user User) error

DBAddUser create a new user

func DBAddUserRole

func DBAddUserRole(dbConn *sql.DB, user string, role string) error

DBAddUserRole create a user to role mapping

func DBDeleteRole

func DBDeleteRole(dbConn *sql.DB, name string) error

DBDeleteRole delete a role by name

func DBDeleteSession

func DBDeleteSession(dbConn *sql.DB, uuid string) error

DBDeleteSession remove a user session

func DBDeleteUser

func DBDeleteUser(dbConn *sql.DB, name string) error

DBDeleteUser delete a user by userid

func DBUpdatePassword

func DBUpdatePassword(dbConn *sql.DB, username string, password string) error

DBUpdatePassword update a user password

func DBUpdateRole

func DBUpdateRole(dbConn *sql.DB, role Role) error

DBUpdateRole update a role

func DBUpdateUser

func DBUpdateUser(dbConn *sql.DB, user User) error

DBUpdateUser update a user

func DecryptPassword

func DecryptPassword(encodedHexPassword string) (string, error)

DecryptPassword decrypt the encrypted password returning the cleartext password

func EncryptPassword

func EncryptPassword(inputPassword string) (string, error)

EncryptPassword encrypt a cleartext password returning the encrypted password

func LogPermissions

func LogPermissions(perms map[string]Permission)

LogPermissions print to stdout a map of permissions

func LogUser

func LogUser(user User)

LogUser print to stdout a user object

Types

type CustomSec

type CustomSec struct {
}

func (CustomSec) AddRole

func (d CustomSec) AddRole(dbConn *sql.DB, role Role) error

func (CustomSec) AddUser

func (d CustomSec) AddUser(dbConn *sql.DB, user User) error

func (CustomSec) Authorize

func (d CustomSec) Authorize(dbConn *sql.DB, token string, action string) error

func (CustomSec) ChangePassword

func (d CustomSec) ChangePassword(dbConn *sql.DB, username string, newpass string) error

func (CustomSec) CompareUserToToken

func (d CustomSec) CompareUserToToken(string, string) (bool, error)

func (CustomSec) DeleteRole

func (d CustomSec) DeleteRole(dbConn *sql.DB, name string) error

func (CustomSec) DeleteUser

func (d CustomSec) DeleteUser(dbConn *sql.DB, id string) error

func (CustomSec) GetAllRoles

func (d CustomSec) GetAllRoles(dbConn *sql.DB) ([]Role, error)

func (CustomSec) GetAllUsers

func (d CustomSec) GetAllUsers(dbConn *sql.DB) ([]User, error)

func (CustomSec) GetRole

func (d CustomSec) GetRole(dbConn *sql.DB, name string) (Role, error)

func (CustomSec) GetUser

func (d CustomSec) GetUser(dbConn *sql.DB, id string) (User, error)

func (CustomSec) LogRole

func (d CustomSec) LogRole(role Role)

func (CustomSec) LogUser

func (d CustomSec) LogUser(user User)

func (CustomSec) Login

func (d CustomSec) Login(dbConn *sql.DB, id string, psw string) (string, error)

func (CustomSec) Logout

func (d CustomSec) Logout(dbConn *sql.DB, id string) error

func (CustomSec) UpdateRole

func (d CustomSec) UpdateRole(dbConn *sql.DB, role Role) error

func (CustomSec) UpdateUser

func (d CustomSec) UpdateUser(dbConn *sql.DB, user User) error

type DefaultSec

type DefaultSec struct {
}

func (DefaultSec) AddRole

func (d DefaultSec) AddRole(dbConn *sql.DB, role Role) error

AddRole add a role

func (DefaultSec) AddUser

func (d DefaultSec) AddUser(dbConn *sql.DB, user User) error

AddUser create a new user object

func (DefaultSec) Authorize

func (d DefaultSec) Authorize(dbConn *sql.DB, token string, action string) error

Authorize perform an authorization based on a security token and requested action

func (DefaultSec) ChangePassword

func (d DefaultSec) ChangePassword(dbConn *sql.DB, username string, newpass string) error

ChangePassword change a users password

func (DefaultSec) CompareUserToToken

func (d DefaultSec) CompareUserToToken(dbConn *sql.DB, username string, token string) (bool, error)

CompareUserToToken test to see if a token matches a user id

func (DefaultSec) DeleteRole

func (d DefaultSec) DeleteRole(dbConn *sql.DB, name string) error

DeleteRole delete a role by name

func (DefaultSec) DeleteUser

func (d DefaultSec) DeleteUser(dbConn *sql.DB, id string) error

DeleteUser delete a user

func (DefaultSec) GetAllRoles

func (d DefaultSec) GetAllRoles(dbConn *sql.DB) ([]Role, error)

GetAllRoles return a list of all roles

func (DefaultSec) GetAllUsers

func (d DefaultSec) GetAllUsers(dbConn *sql.DB) ([]User, error)

GetAllUsers return a list of all users

func (DefaultSec) GetRole

func (d DefaultSec) GetRole(dbConn *sql.DB, name string) (Role, error)

GetRole return a role by name

func (DefaultSec) GetUser

func (d DefaultSec) GetUser(dbConn *sql.DB, id string) (User, error)

GetUser return a given user by ID

func (DefaultSec) LogRole

func (d DefaultSec) LogRole(role Role)

LogRole print to stdout a role

func (DefaultSec) LogUser

func (d DefaultSec) LogUser(user User)

LogUser print to stdout a user

func (DefaultSec) Login

func (d DefaultSec) Login(dbConn *sql.DB, id string, psw string) (string, error)

Login perform a login using a password and user id returning the security token if successful

func (DefaultSec) Logout

func (d DefaultSec) Logout(dbConn *sql.DB, uuid string) error

Logout logout the user using the security token

func (DefaultSec) UpdateRole

func (d DefaultSec) UpdateRole(dbConn *sql.DB, role Role) error

UpdateRole update a role

func (DefaultSec) UpdateUser

func (d DefaultSec) UpdateUser(dbConn *sql.DB, user User) error

UpdateUser update the user object

type Permission

type Permission struct {
	Name        string
	Description string
	Selected    bool
}

func DBGetPermissions

func DBGetPermissions(dbConn *sql.DB) ([]Permission, error)

DBGetPermissions get a complete list of possible permissions

type Role

type Role struct {
	Name        string
	Selected    bool
	Permissions map[string]Permission
	UpdateDate  string
	Token       string
}

func DBGetRole

func DBGetRole(dbConn *sql.DB, Name string) (Role, error)

DBGetRole get a role from the database by name

func DBGetRoles

func DBGetRoles(dbConn *sql.DB) ([]Role, error)

DBGetRoles get a list of all roles

type SecInterface

type SecInterface interface {
	Authorize(*sql.DB, string, string) error
	Login(*sql.DB, string, string) (string, error)
	Logout(*sql.DB, string) error
	ChangePassword(*sql.DB, string, string) error
	CompareUserToToken(*sql.DB, string, string) (bool, error)
	UpdateUser(*sql.DB, User) error
	AddUser(*sql.DB, User) error
	GetUser(*sql.DB, string) (User, error)
	GetAllUsers(*sql.DB) ([]User, error)
	DeleteUser(*sql.DB, string) error
	UpdateRole(*sql.DB, Role) error
	AddRole(*sql.DB, Role) error
	DeleteRole(*sql.DB, string) error
	GetAllRoles(*sql.DB) ([]Role, error)
	GetRole(*sql.DB, string) (Role, error)
	LogRole(Role)
	LogUser(User)
}

type Session

type Session struct {
	Name       string
	Token      string
	UpdateDate string
}

func DBGetSession

func DBGetSession(dbConn *sql.DB, token string) (Session, error)

DBGetSession get a user session

type User

type User struct {
	Name       string
	Password   string
	Roles      map[string]Role
	UpdateDate string
	Token      string
}

func DBGetAllUsers

func DBGetAllUsers(dbConn *sql.DB) ([]User, error)

DBGetAllUsers get a list of all users

func DBGetUser

func DBGetUser(dbConn *sql.DB, Name string) (User, error)

DBGetUser get a user from the database by name

Jump to

Keyboard shortcuts

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