iuser

package
v0.0.0-...-01681b2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PASSWORD string = "password"
	SMS      string = "sms"
)

Variables

View Source
var (
	ErrUserNotFound = errors.New("User not found")
	ErrInvalidSub   = errors.New("Invalid sub")
)
View Source
var (
	ErrMethodNotSupported = errors.New("methods not supported")
)

Functions

This section is empty.

Types

type BackendGroup

type BackendGroup interface {
	GetId() int
	GetName() string

	// rules as fullnames
	GetRules() interface{}

	AddUser(user User) error
	GetUser(u User) (bool, error)
	RemoveUser(user User) error
	ListUsers() ([]User, error)
}

ssolib 中的 group 有 member 的概念,即 User + role 为了简单,Backend Group 不规定 Role 的接口

type BackendWithGroup

type BackendWithGroup interface {
	UserBackend

	// 给定 group 名字,返回是否创建成功,若不成功,建议返回 error 非空
	// 若 success 为 false, 可以返回非空 group, 表示已存在满足 rules 的 group
	CreateBackendGroup(name string, rules interface{}) (success bool, group BackendGroup, err error)

	// name 为 ssolib 中的组名
	GetBackendGroupByName(name string) (BackendGroup, error)

	// id 为 ssolib 中的组 Id
	GetBackendGroup(id int) (BackendGroup, error)

	DeleteBackendGroup(BackendGroup) error

	GetBackendGroupsOfUser(user User) ([]BackendGroup, error)

	// 现在还想不清楚 groupId 到底重不重要,按照已有的函数,可能会需要下面的接口函数
	SetBackendGroupId(name string, Id int) error
}

拥有 BackendGroup 的 Backend

type GroupType

type GroupType int8

Type of Backend Group or SSOLIBGROUP

const (
	SSOLIBGROUP GroupType = iota
	BACKENDGROUP
)

type User

type User interface {
	GetMobile() string

	// sso v2 中 不同后端对应不同的 sso 实例,所以暂时不需要大一统的 sub
	GetId() int

	// 尽量全局唯一,可以作为 <id, backend> 的单射
	GetSub() string

	GetProfile() UserProfile

	GetPublicProfile() UserProfile

	// 本接口的实现中,应该有一个属性用来区分不同的后端, 具体逻辑待定
	// 另一方面,由于在逻辑上,属于不同后端的同一个人在 sso 中被看待为不同的用户,
	// 所以从逻辑上,我们的 user 的实现是一个 “用户身份” 而非 “用户”
	SetBackend(back UserBackend)

	// 下面的设计来源于旧的 sso,为了兼容 sso v1 api
	GetName() string
}

type UserBackend

type UserBackend interface {
	// 全局已经注册两个认证用户身份的方法:
	// "password" "sms"
	SupportedVerificationMethods() []string

	// 可能的返回值为 "sso" "sso-ldap"
	Name() string

	// 应该有一种将 id 对应成全局 sub 的方法
	UserIdToSub(id int) string

	UserSubToId(sub string) (int, error)

	GetUserByFeature(string) (User, error)
	GetUserByEmail(string) (User, error)
	GetUser(id int) (User, error)

	AuthPassword(sub, password string) (bool, error)
	AuthPasswordByFeature(feature, password string) (bool, User, error)

	// 下面的方法是为了简单地兼容 sso 原有代码,也许会有很多冗余
	ListUsers(ctx context.Context) ([]User, error)
	GetUserByName(name string) (User, error)
	CreateUser(user User, passwordHashed bool) error
	DeleteUser(User) error

	// 处理一些如管理员组设定等依赖后端的初始化
	InitModel(model interface{})
}

type UserProfile

type UserProfile interface {
	// UserProfile 的数据可能涉及隐私,所以需要实现如下接口,
	// 若具体实现不希望暴露对应信息或对应信息为空,则可以返回空值
	GetName() string
	GetMobile() string
	GetEmail() string
}

Jump to

Keyboard shortcuts

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