Documentation
¶
Index ¶
- Constants
- Variables
- func Authorizate(ctx context.Context, authoriztor Authorizer, user *User) (ok bool, err error)
- func Grant(ctx context.Context, authoriztor Authorizer, user *User) (err error)
- func NewUserContext(ctx context.Context, user *User) context.Context
- func Revoke(ctx context.Context, authoriztor Authorizer, user *User) (err error)
- type Action
- type AuthenticateManager
- func (m *AuthenticateManager) Authenticate(ctx context.Context, param *AuthenticateParam) (user *User, err error)
- func (m *AuthenticateManager) CreateInnerUser(ctx context.Context) (user *User, err error)
- func (m *AuthenticateManager) CreateUser(ctx context.Context, param *UserParam) (err error)
- func (m *AuthenticateManager) DeleteUser(ctx context.Context, userName string) (err error)
- func (m *AuthenticateManager) DestroySessionKey(ctx context.Context, sessionKey string) (err error)
- func (m *AuthenticateManager) FetchInnerUserList(ctx context.Context) (users []*User, err error)
- func (m *AuthenticateManager) FetchNormalUserList(ctx context.Context, param *UserParam) (users []*User, err error)
- func (m *AuthenticateManager) FetchUser(ctx context.Context, userName string) (user *User, err error)
- func (m *AuthenticateManager) UpdateUserPassword(ctx context.Context, pcd *PasswordChangeData) (err error)
- type AuthenticateParam
- type AuthenticateStorager
- type Authorizer
- type Feature
- type FeatureAuthorizer
- type MultiAuthorizer
- type Op
- type PasswordChangeData
- type ProductAuthorizateManager
- func (pa *ProductAuthorizateManager) Authorizate(ctx context.Context, user *User) (bool, error)
- func (pa *ProductAuthorizateManager) FetchProducts(ctx context.Context, user *User) ([]int64, error)
- func (pa *ProductAuthorizateManager) Grant(ctx context.Context, user *User) error
- func (pa *ProductAuthorizateManager) GrantedUsers(ctx context.Context) ([]*User, error)
- func (pa *ProductAuthorizateManager) Revoke(ctx context.Context, user *User) error
- type ProductAuthorizateStorager
- type Role
- type User
- type UserFilter
- type UserParam
Constants ¶
View Source
const ( RoleNameAdmin = "admin" RoleNameProduct = "product" RoleNameInner = "inner" )
View Source
const ( AuthTypePassword = "Password" AuthTypeSessionKey = "Session" AuthTypeSkip = "Skip" )
Variables ¶
View Source
var ( FA = NewFeatureAuthorizer FAP = NewFeatureAuthorizerWithFactoryWithProduct )
View Source
var AllowRoles = map[string]bool{ RoleNameAdmin: true, RoleNameProduct: true, RoleNameInner: true, }
View Source
var Authenticators = map[string]func(ctx context.Context, param *AuthenticateParam, manager *AuthenticateManager) (*User, error){ AuthTypePassword: authTypePassword, AuthTypeSessionKey: func(ctx context.Context, param *AuthenticateParam, manager *AuthenticateManager) (user *User, err error) { user, err = manager.storager.FetchUser(ctx, &UserFilter{ SessionKey: ¶m.Identify, }) if err != nil { return nil, err } if user == nil { return nil, xerror.WrapAuthenticateFailErrorWithMsg("Session Key Wrong") } if user.SessionCreateAt.AddDate(0, 0, stateful.DefaultConfig.RunTime.SessionExpireDay).Before(time.Now()) { return nil, xerror.WrapAuthenticateFailErrorWithMsg("Session Key Expired") } return user, nil }, AuthTypeSkip: func(ctx context.Context, param *AuthenticateParam, manager *AuthenticateManager) (user *User, err error) { if !stateful.DefaultConfig.RunTime.SkipTokenValidate { return nil, xerror.WrapAuthenticateFailErrorWithMsg("Bad Authorization Flag") } return newFakeUser(&Role{ Name: param.Identify, }), nil }, }
View Source
var RoleInner = &Role{ Name: RoleNameInner, }
Functions ¶
func Authorizate ¶
Types ¶
type AuthenticateManager ¶
type AuthenticateManager struct {
// contains filtered or unexported fields
}
func NewAuthenticateManager ¶
func NewAuthenticateManager(txn itxn.TxnStorager, storager AuthenticateStorager) *AuthenticateManager
func (*AuthenticateManager) Authenticate ¶
func (m *AuthenticateManager) Authenticate(ctx context.Context, param *AuthenticateParam) (user *User, err error)
func (*AuthenticateManager) CreateInnerUser ¶
func (m *AuthenticateManager) CreateInnerUser(ctx context.Context) (user *User, err error)
func (*AuthenticateManager) CreateUser ¶
func (m *AuthenticateManager) CreateUser(ctx context.Context, param *UserParam) (err error)
func (*AuthenticateManager) DeleteUser ¶
func (m *AuthenticateManager) DeleteUser(ctx context.Context, userName string) (err error)
func (*AuthenticateManager) DestroySessionKey ¶
func (m *AuthenticateManager) DestroySessionKey(ctx context.Context, sessionKey string) (err error)
func (*AuthenticateManager) FetchInnerUserList ¶
func (m *AuthenticateManager) FetchInnerUserList(ctx context.Context) (users []*User, err error)
func (*AuthenticateManager) FetchNormalUserList ¶
func (*AuthenticateManager) UpdateUserPassword ¶
func (m *AuthenticateManager) UpdateUserPassword(ctx context.Context, pcd *PasswordChangeData) (err error)
type AuthenticateParam ¶
type AuthenticateStorager ¶
type AuthenticateStorager interface {
FetchUserList(ctx context.Context, param *UserFilter) ([]*User, error)
FetchUser(ctx context.Context, param *UserFilter) (*User, error)
UpdateUser(ctx context.Context, user *User, param *UserParam) error
CreateUser(ctx context.Context, param *UserParam) error
DeleteUser(ctx context.Context, user *User) error
}
type Authorizer ¶
type Feature ¶
type Feature string
const ( // global resource FeatureProxyPool Feature = "ProxyPool" FeatureBFECluster Feature = "BFECluster" FeatureBFEPool Feature = "BFEPool" FeatureArea Feature = "Area" FeatureDomain Feature = "Domain" FeatureProduct Feature = "Product" FeatureExtraFile Feature = "ExtraFile" // product resource FeatureProductPool Feature = "ProductPool" FeatureRoute Feature = "Route" FeatureSubCluster Feature = "SubCluster" FeatureProductCluster Feature = "ProductCluster" FeatureTraffic Feature = "Traffic" FeatureCert Feature = "Cert" FeatureActiveHealthCheck Feature = "ActiveHealthCheck" // product resource, module FeatureModHeader Feature = "mod.header" FeatureModRewrite Feature = "mod.rewrite" // auth FeatureProductUser Feature = "AuthProductUser" FeatureUser Feature = "User" // nlb resource FeatureNLBPool Feature = "NLBPool" FeatureNLBCluster Feature = "NLBCluster" )
type FeatureAuthorizer ¶
func NewFeatureAuthorizer ¶
func NewFeatureAuthorizer(f Feature, a Action) *FeatureAuthorizer
func (*FeatureAuthorizer) Authorizate ¶
type MultiAuthorizer ¶
type MultiAuthorizer struct {
// contains filtered or unexported fields
}
func NewFeatureAuthorizerWithFactoryWithProduct ¶
func NewFeatureAuthorizerWithFactoryWithProduct(f Feature, a Action) *MultiAuthorizer
func NewMultiAuthorizer ¶
func NewMultiAuthorizer(as []Authorizer, op Op) *MultiAuthorizer
func NewMultiAuthorizerWithFactory ¶
func NewMultiAuthorizerWithFactory(asFactories []func() Authorizer, op Op) *MultiAuthorizer
func (*MultiAuthorizer) Authorizate ¶
type PasswordChangeData ¶
type ProductAuthorizateManager ¶
type ProductAuthorizateManager struct {
// contains filtered or unexported fields
}
var DefaultProductAuthorizateManager *ProductAuthorizateManager
func NewProductAuthorizateManager ¶
func NewProductAuthorizateManager(storager ProductAuthorizateStorager) *ProductAuthorizateManager
func (*ProductAuthorizateManager) Authorizate ¶
func (*ProductAuthorizateManager) FetchProducts ¶
func (*ProductAuthorizateManager) Grant ¶
func (pa *ProductAuthorizateManager) Grant(ctx context.Context, user *User) error
func (*ProductAuthorizateManager) GrantedUsers ¶
func (pa *ProductAuthorizateManager) GrantedUsers(ctx context.Context) ([]*User, error)
type ProductAuthorizateStorager ¶
type ProductAuthorizateStorager interface {
FetchGrantedUsers(context.Context, *ibasic.Product) ([]*User, error)
FetchUser(context.Context, *ibasic.Product, *User) (*User, error)
FetchProducts(context.Context, *User) ([]int64, error)
Grant(context.Context, *ibasic.Product, *User) error
Revoke(context.Context, *ibasic.Product, *User) error
}
type User ¶
type UserFilter ¶
Click to show internal directories.
Click to hide internal directories.