auth

package
v0.0.0-...-29bd094 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 12 Imported by: 222

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateLDAPGroup = errors.New("a LDAP user group with same DN already exist")

ErrDuplicateLDAPGroup ...

View Source
var ErrInvalidLDAPGroupDN = errors.New("the LDAP group DN is invalid")

ErrInvalidLDAPGroupDN ...

View Source
var ErrNotSupported = errors.New("not supported")

ErrNotSupported ...

View Source
var ErrorGroupNotExist = errors.New("group does not exist")

ErrorGroupNotExist ...

View Source
var ErrorUserNotExist = errors.New("user does not exist")

ErrorUserNotExist ...

Functions

func IsSuperUser

func IsSuperUser(ctx context.Context, username string) bool

IsSuperUser checks if the user is super user(conventionally id == 1) of Harbor

func Login

func Login(ctx context.Context, m models.AuthModel) (*models.User, error)

Login authenticates user credentials based on setting.

func OnBoardGroup

func OnBoardGroup(ctx context.Context, userGroup *model.UserGroup, altGroupName string) error

OnBoardGroup - Create a user group in harbor db, if altGroupName is not empty, take the altGroupName as groupName in harbor DB

func OnBoardUser

func OnBoardUser(ctx context.Context, user *models.User) error

OnBoardUser will check if a user exists in user table, if not insert the user and put the id in the pointer of user model, if it does exist, return the user's profile.

func PostAuthenticate

func PostAuthenticate(ctx context.Context, u *models.User) error

PostAuthenticate -

func Register

func Register(name string, h AuthenticateHelper)

Register add different authenticators to registry map.

func SearchAndOnBoardGroup

func SearchAndOnBoardGroup(ctx context.Context, groupKey, altGroupName string) (int, error)

SearchAndOnBoardGroup ... if altGroupName is not empty, take the altGroupName as groupName in harbor DB

func SearchAndOnBoardUser

func SearchAndOnBoardUser(ctx context.Context, username string) (int, error)

SearchAndOnBoardUser ... Search user and OnBoard user, if user exist, return the ID of current user.

func SearchGroup

func SearchGroup(ctx context.Context, groupKey string) (*model.UserGroup, error)

SearchGroup -- Search group in authenticator, groupKey is the unique attribute of group in authenticator, for LDAP, the key is group DN

func SearchUser

func SearchUser(ctx context.Context, username string) (*models.User, error)

SearchUser --

Types

type AuthenticateHelper

type AuthenticateHelper interface {
	// Authenticate authenticate the user based on data in m.  Only when the error returned is an instance
	// of ErrAuth, it will be considered a bad credentials, other errors will be treated as server side error.
	Authenticate(ctx context.Context, m models.AuthModel) (*models.User, error)
	// OnBoardUser will check if a user exists in user table, if not insert the user and
	// put the id in the pointer of user model, if it does exist, fill in the user model based
	// on the data record of the user
	OnBoardUser(ctx context.Context, u *models.User) error
	// OnBoardGroup Create a group in harbor DB, if altGroupName is not empty, take the altGroupName as groupName in harbor DB.
	OnBoardGroup(ctx context.Context, g *model.UserGroup, altGroupName string) error
	// SearchUser Get user information from account repository
	SearchUser(ctx context.Context, username string) (*models.User, error)
	// SearchGroup Search a group based on specific authentication
	SearchGroup(ctx context.Context, groupDN string) (*model.UserGroup, error)
	// PostAuthenticate Update user information after authenticate, such as Onboard or sync info etc
	PostAuthenticate(ctx context.Context, u *models.User) error
}

AuthenticateHelper provides interface for user management in different auth modes.

type DefaultAuthenticateHelper

type DefaultAuthenticateHelper struct {
}

DefaultAuthenticateHelper - default AuthenticateHelper implementation

func (*DefaultAuthenticateHelper) Authenticate

Authenticate ...

func (*DefaultAuthenticateHelper) OnBoardGroup

OnBoardGroup - OnBoardGroup, it will set the ID of the user group, if altGroupName is not empty, take the altGroupName as groupName in harbor DB.

func (*DefaultAuthenticateHelper) OnBoardUser

func (d *DefaultAuthenticateHelper) OnBoardUser(_ context.Context, _ *models.User) error

OnBoardUser will check if a user exists in user table, if not insert the user and put the id in the pointer of user model, if it does exist, fill in the user model based on the data record of the user

func (*DefaultAuthenticateHelper) PostAuthenticate

func (d *DefaultAuthenticateHelper) PostAuthenticate(_ context.Context, _ *models.User) error

PostAuthenticate - Update user information after authenticate, such as OnBoard or sync info etc

func (*DefaultAuthenticateHelper) SearchGroup

func (d *DefaultAuthenticateHelper) SearchGroup(_ context.Context, groupKey string) (*model.UserGroup, error)

SearchGroup - Search ldap group by group key, groupKey is the unique attribute of group in authenticator, for LDAP, the key is group DN

func (*DefaultAuthenticateHelper) SearchUser

func (d *DefaultAuthenticateHelper) SearchUser(_ context.Context, username string) (*models.User, error)

SearchUser - Get user information from account repository

type ErrAuth

type ErrAuth struct {
	// contains filtered or unexported fields
}

ErrAuth is the type of error to indicate a failed authentication due to user's error.

func NewErrAuth

func NewErrAuth(msg string) ErrAuth

NewErrAuth ...

func (ErrAuth) Error

func (ea ErrAuth) Error() string

Error ...

type UserLock

type UserLock struct {
	// contains filtered or unexported fields
}

UserLock maintains a lock to block user from logging in within a short period of time.

func NewUserLock

func NewUserLock(freeze time.Duration) *UserLock

NewUserLock ...

func (*UserLock) IsLocked

func (ul *UserLock) IsLocked(username string) bool

IsLocked checks whether a login request is happened within a period of time or not if it is, the authenticator should ignore the login request and return a failure immediately

func (*UserLock) Lock

func (ul *UserLock) Lock(username string)

Lock marks a new login failure with the time it happens

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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