auth

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SESSION_DURATION   = time.Second * 60 * 10 * 1000
	SESSION_KEY_FORMAT = "account_id:%v:token"
)
View Source
const (
	//Account
	CodeInvalidGroupId                                  = "400-12001"
	CodeAccountCreateParamError                         = "400-12002"
	CodeAccountCreateAuthenticatorError                 = "503-12003"
	CodeAccountGetAccountError                          = "503-12004"
	CodeAccountGetAccountNotFoundError                  = "503-12005"
	CodeAccountLoginParamError                          = "400-12006"
	CodeAccountLoginFailedError                         = "401-12007"
	CodeAccountLogoutError                              = "503-12008"
	CodeAccountGroupAccountsGroupIdNotValidError        = "400-12009"
	CodeAccountGroupAccountsNotFoundError               = "404-12010"
	CodeAccountAccoutGroupsAccountIdNotValidError       = "400-12011"
	CodeAccountAccoutGroupsNotFoundError                = "503-12012"
	CodeAccountGetGroupGroupIdNotValidError             = "503-12013"
	CodeAccountGetGroupGroupIdNotFoundError             = "404-12014"
	CodeAccountListGroupNotFoundError                   = "503-12015"
	CodeAccountAuthenticatorModificationNotAllowedError = "503-12016"
	CodeAccountCreateGroupParamError                    = "400-12017"
	CodeAccountCreateGroupFailedError                   = "503-12018"
	CodeAccountUpdateGroupParamError                    = "400-12019"
	CodeAccountUpdateGroupFailedError                   = "503-12020"
	CodeAccountDeleteGroupGroupIdNotValidError          = "503-12021"
	CodeAccountDeleteGroupFailedError                   = "503-12022"
	CodeAccountJoinGroupGroupIdNotValidError            = "503-12023"
	CodeAccountJoinGroupAccountIdNotValidError          = "503-12024"
	CodeAccountJoinGroupFailedError                     = "503-12025"
	CodeAccountLeaveGroupGroupIdNotValidError           = "503-12026"
	CodeAccountLeaveGroupAccountIdNotValidError         = "503-12027"
	CodeAccountLeaveGroupFailedError                    = "503-12028"
	CodeAccountGrantServicePermissionParamError         = "400-12029"
	CodeAccountGrantServicePermissionFailedError        = "503-12030"
	CodeAccountRevokeServicePermissionParamError        = "400-12031"
	CodeAccountRevokeServicePermissionFailedError       = "503-12032"
	CodeAccountTokenInvalidError                        = "401-12033"
	CodeAccountLoginFailedEmailNotValidError            = "401-12034"
	CodeAccountLoginFailedPasswordNotValidError         = "401-12035"
)
View Source
const (
	DEFAULT_SALT = "thequickbrownfoxjumpdog"
)
View Source
const (
	PERMISSION_LABEL_PREFIX = "crane.reserved.permissions"
)

Variables

View Source
var (
	ErrLoginFailed     = errors.New("account login failed")
	ErrAccountNotFound = errors.New("account not found")
	ErrGroupNotFound   = errors.New("group not found")
)
View Source
var (
	AuthError          error
	AccountError       error
	CreateAccountError error
	AccountsError      error
)

Functions

func GenToken

func GenToken(a *Account) string

func PermissionGrantLabelsPairFromGroupIdAndPerm

func PermissionGrantLabelsPairFromGroupIdAndPerm(groupId uint64, perm string) map[string]string

func PermissionRevokeLabelKeysFromPermissionId

func PermissionRevokeLabelKeysFromPermissionId(permissionId string) []string

Types

type Account

type Account struct {
	ID       uint64    `json:"Id"`
	Title    string    `json:"Title"`
	Email    string    `json:"Email" gorm:"not null"`
	Phone    string    `json:"Phone"`
	LoginAt  time.Time `json:"LoginAt"`
	Password string    `json:"Password" gorm:"not null"`
	Token    string    `json:"-" gorm:"-"`
}

func ReferenceToValue

func ReferenceToValue(a *Account) Account

type AccountFilter

type AccountFilter url.Values

type AccountGroup

type AccountGroup struct {
	ID        uint64 `json:"Id"`
	AccountId uint64 `json:"AccountId"`
	GroupId   uint64 `json:"GroupId"`
}

type Authenticator

type Authenticator interface {
	AccountPermissions(account *Account) (*[]string, error)

	Login(account *Account) (token string, err error)
	EncryptPassword(password string) string

	DeleteGroup(groupId uint64) error
	Groups(listOptions model.ListOptions) (*[]Group, error)
	Group(id uint64) (*Group, error)
	CreateGroup(role *Group) error
	UpdateGroup(role *Group) error
	GroupAccounts(account model.ListOptions) (*[]Account, error)

	AccountGroups(account model.ListOptions) (*[]Group, error)
	Accounts(listOptions model.ListOptions) (*[]Account, error)
	Account(id interface{}) (*Account, error)
	CreateAccount(groupId uint64, a *Account) error
	UpdateAccount(a *Account) error

	JoinGroup(accountId, groupId uint64) error
	LeaveGroup(accountId, groupId uint64) error

	ModificationAllowed() bool
	GetDefaultAccounts() []Account
}

type Group

type Group struct {
	ID        uint64 `json:"Id"`
	Name      string `json:"Name" gorm:"not null"`
	CreaterId uint64 `json:"CreaterId"`
}

type GroupFilter

type GroupFilter url.Values

type GroupPermission

type GroupPermission struct {
	Permission Permission `json:"Permission"`
	GroupID    uint64     `json:"GroupID"`
}

type MockAuthenticator

type MockAuthenticator struct {
	Authenticator
}

func NewMockAuthenticator

func NewMockAuthenticator() *MockAuthenticator

func (*MockAuthenticator) Account

func (d *MockAuthenticator) Account(id interface{}) (*Account, error)

func (*MockAuthenticator) AccountGroups

func (d *MockAuthenticator) AccountGroups(account model.ListOptions) (*[]Group, error)

func (*MockAuthenticator) AccountPermissions

func (d *MockAuthenticator) AccountPermissions(account *Account) (*[]string, error)

func (*MockAuthenticator) Accounts

func (d *MockAuthenticator) Accounts(listOptions model.ListOptions) (auths *[]Account, err error)

func (*MockAuthenticator) CreateAccount

func (d *MockAuthenticator) CreateAccount(groupId uint64, a *Account) error

func (*MockAuthenticator) CreateGroup

func (d *MockAuthenticator) CreateGroup(g *Group) error

func (*MockAuthenticator) DeleteGroup

func (d *MockAuthenticator) DeleteGroup(groupId uint64) error

func (*MockAuthenticator) EncryptPassword

func (d *MockAuthenticator) EncryptPassword(password string) string

func (*MockAuthenticator) GetDefaultAccounts

func (d *MockAuthenticator) GetDefaultAccounts() (account []Account)

func (*MockAuthenticator) Group

func (d *MockAuthenticator) Group(id uint64) (*Group, error)

func (*MockAuthenticator) GroupAccounts

func (d *MockAuthenticator) GroupAccounts(account model.ListOptions) (*[]Account, error)

func (*MockAuthenticator) Groups

func (d *MockAuthenticator) Groups(options model.ListOptions) (auths *[]Group, err error)

func (*MockAuthenticator) JoinGroup

func (d *MockAuthenticator) JoinGroup(accountId, groupId uint64) error

func (*MockAuthenticator) LeaveGroup

func (d *MockAuthenticator) LeaveGroup(accountId, groupId uint64) error

func (*MockAuthenticator) Login

func (d *MockAuthenticator) Login(a *Account) (token string, err error)

func (*MockAuthenticator) ModificationAllowed

func (d *MockAuthenticator) ModificationAllowed() bool

func (*MockAuthenticator) UpdateAccount

func (d *MockAuthenticator) UpdateAccount(a *Account) error

func (*MockAuthenticator) UpdateGroup

func (d *MockAuthenticator) UpdateGroup(g *Group) error

type Permission

type Permission struct {
	Perm    int    `json:"Perm"`
	Display string `json:"Display"`
}
var (
	PermReadOnly  Permission = Permission{Perm: 0, Display: "r"}
	PermReadWrite Permission = Permission{Perm: 1, Display: "w"}
	PermAdmin     Permission = Permission{Perm: 2, Display: "x"}

	Perms []Permission = []Permission{PermReadOnly, PermReadWrite, PermAdmin}
)

func NewPermission

func NewPermission(display string) Permission

func PermGreaterOrEqualThan

func PermGreaterOrEqualThan(p Permission) []Permission

func PermLessOrEqualThan

func PermLessOrEqualThan(p Permission) []Permission

func (Permission) Normalize

func (p Permission) Normalize() Permission

type TokenStore

type TokenStore interface {
	Set(ctx *gin.Context, token, account_id string, expired_at time.Time) error
	Get(ctx *gin.Context, token string) (string, error)
	Del(ctx *gin.Context, token string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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