security

package
v0.0.0-...-4877f23 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 32 Imported by: 4

Documentation

Overview

Package security is a generated GoMock package.

Package security is a generated GoMock package.

Package security is a generated GoMock package.

Package security is a generated GoMock package.

Package security is a generated GoMock package.

Index

Constants

View Source
const (
	ApplicationCtxKey = "application"
	PrincipalCtxKey   = "principal"
)
View Source
const (
	Argon2PrefixKey = "{argon2}"
	BcryptPrefixKey = "{bcrypt}"
	Pbkdf2PrefixKey = "{pbkdf2}"
	ScryptPrefixKey = "{scrypt}"
)

Variables

View Source
var (
	ErrAccountExistingUsername    = errors.New("principal username already exists")
	ErrAccountInvalidUsername     = errors.New("principal username is invalid")
	ErrAccountEmptyRole           = errors.New("principal role is empty")
	ErrAccountInvalidRole         = errors.New("principal role is invalid")
	ErrAccountEmptyPassword       = errors.New("principal password is empty")
	ErrAccountInvalidPassword     = errors.New("principal password is invalid")
	ErrAccountEmptyPassphrase     = errors.New("principal passphrase is empty")
	ErrAccountInvalidPassphrase   = errors.New("principal passphrase is invalid")
	ErrAccountDisabled            = errors.New("principal is disabled")
	ErrAccountLocked              = errors.New("principal is locked")
	ErrAccountExpired             = errors.New("principal has expired")
	ErrAccountExpiredPassword     = errors.New("principal password has expired")
	ErrAccountEmptyAuthorities    = errors.New("principal authorities are empty")
	ErrAccountInvalidAuthorities  = errors.New("principal authorities are invalid")
	ErrAccountEmptyResource       = errors.New("principal resource is empty")
	ErrTokenFailedParsing         = errors.New("token failed to parse")
	ErrTokenInvalid               = errors.New("token is invalid")
	ErrTokenEmptyClaims           = errors.New("token claims is empty")
	ErrTokenEmptyUsernameClaim    = errors.New("token username claim is empty")
	ErrTokenInvalidUsernameClaim  = errors.New("token username claim is invalid")
	ErrTokenEmptyRoleClaim        = errors.New("token role claim is empty")
	ErrTokenInvalidRoleClaim      = errors.New("token role claim is invalid")
	ErrTokenEmptyResourcesClaim   = errors.New("token resources claim is empty")
	ErrTokenInvalidResourcesClaim = errors.New("token resources claim is invalid")
	ErrPasswordEncoderNotFound    = errors.New("password encoder not found")
	ErrPasswordLength             = errors.New("password length is too short")
	ErrPasswordSpecialChars       = errors.New("password must contain at least 2 special characters")
	ErrPasswordNumbers            = errors.New("password must contain at least 2 numbers")
	ErrPasswordUppercaseChars     = errors.New("password must contain at least 2 uppercase characters")
	ErrRawPasswordIsEmpty         = errors.New("rawPassword cannot be empty")
	ErrSaltIsNil                  = errors.New("salt cannot be nil")
	ErrSaltIsEmpty                = errors.New("salt cannot be empty")
	ErrHashFuncIsNil              = errors.New("hashFunc cannot be nil")
	ErrEncodedPasswordIsEmpty     = errors.New("encodedPassword cannot be empty")
	ErrEncodedPasswordNotAllowed  = errors.New("encodedPassword format not allowed")
	ErrBcryptCostNotAllowed       = errors.New("bcryptCost not allowed")
)
View Source
var SupportedDecoders = map[string]PasswordEncoder{
	Argon2PrefixKey: NewArgon2PasswordEncoder(),
	BcryptPrefixKey: NewBcryptPasswordEncoder(),
	Pbkdf2PrefixKey: NewPbkdf2PasswordEncoder(),
	ScryptPrefixKey: NewScryptPasswordEncoder(),
}

Functions

func AddApplicationToContext

func AddApplicationToContext(ctx *gin.Context, application string)

func AddPrincipalToContext

func AddPrincipalToContext(ctx *gin.Context, principal *Principal)

func Argon2Decode

func Argon2Decode(encodedPassword string) (*string, *int, *int, *int, *int, []byte, []byte, error)

func Argon2Encode

func Argon2Encode(rawPassword string, salt []byte, iterations int, memory int, threads int, keyLen int) (*string, error)

func ErrAuthenticationFailed

func ErrAuthenticationFailed(errs ...error) error

func ErrAuthorizationFailed

func ErrAuthorizationFailed(errs ...error) error

func ErrPasswordEncodingFailed

func ErrPasswordEncodingFailed(errs ...error) error

func ErrPasswordMatchingFailed

func ErrPasswordMatchingFailed(errs ...error) error

func ErrPasswordUpgradeEncodingValidationFailed

func ErrPasswordUpgradeEncodingValidationFailed(errs ...error) error

func ErrPasswordValidationFailed

func ErrPasswordValidationFailed(errs ...error) error

func ErrTokenGenerationFailed

func ErrTokenGenerationFailed(errs ...error) error

func ErrTokenValidationFailed

func ErrTokenValidationFailed(errs ...error) error

func GenerateSalt

func GenerateSalt(saltSize int) ([]byte, error)

func GetApplicationFromContext

func GetApplicationFromContext(ctx *gin.Context) (string, bool)

func Pbkdf2Decode

func Pbkdf2Decode(encodedPassword string) (*string, *int, []byte, []byte, error)

func Pbkdf2Encode

func Pbkdf2Encode(rawPassword string, salt []byte, iterations int, keyLength int, fn HashFunc) (*string, error)

func ScryptDecode

func ScryptDecode(encodedPassword string) (*string, *int, *int, *int, []byte, []byte, error)

func ScryptEncode

func ScryptEncode(rawPassword string, salt []byte, N int, r int, p int, keyLen int) (*string, error)

Types

type Argon2PasswordEncoder

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

func NewArgon2PasswordEncoder

func NewArgon2PasswordEncoder(options ...Argon2PasswordEncoderOption) *Argon2PasswordEncoder

func (*Argon2PasswordEncoder) Encode

func (encoder *Argon2PasswordEncoder) Encode(rawPassword string) (*string, error)

func (*Argon2PasswordEncoder) Matches

func (encoder *Argon2PasswordEncoder) Matches(encodedPassword string, rawPassword string) (*bool, error)

func (*Argon2PasswordEncoder) UpgradeEncoding

func (encoder *Argon2PasswordEncoder) UpgradeEncoding(encodedPassword string) (*bool, error)

type Argon2PasswordEncoderOption

type Argon2PasswordEncoderOption func(encoder *Argon2PasswordEncoder)

func WithArgon2Iterations

func WithArgon2Iterations(iterations int) Argon2PasswordEncoderOption

func WithArgon2KeyLength

func WithArgon2KeyLength(keyLength int) Argon2PasswordEncoderOption

func WithArgon2Memory

func WithArgon2Memory(memory int) Argon2PasswordEncoderOption

func WithArgon2SaltLength

func WithArgon2SaltLength(saltLength int) Argon2PasswordEncoderOption

func WithArgon2Threads

func WithArgon2Threads(threads int) Argon2PasswordEncoderOption

type AuthAccessControlList

type AuthAccessControlList struct {
	Role       *string `gorm:"primaryKey" json:"role,omitempty"`
	Resource   *string `gorm:"primaryKey" json:"resource,omitempty"`
	Permission *string `gorm:"primaryKey" json:"permission,omitempty"`
	Enabled    *bool   `gorm:"enabled" json:"enabled,omitempty"`
}

type AuthPrincipal

type AuthPrincipal struct {
	Username    *string `gorm:"username" json:"username,omitempty"`
	Role        *string `gorm:"role" json:"role,omitempty"`
	Application *string `gorm:"application" json:"application,omitempty"`
	Resource    *string `gorm:"resource" json:"resource,omitempty"`
	Permission  *string `gorm:"permission" json:"permission,omitempty"`
	Password    *string `gorm:"password" json:"password,omitempty"`
	Passphrase  *string `gorm:"passphrase" json:"passphrase,omitempty"`
	Enabled     *bool   `gorm:"enabled" json:"enabled,omitempty"`
}

type AuthResource

type AuthResource struct {
	Name        *string `gorm:"primaryKey" json:"name,omitempty"`
	Application *string `gorm:"primaryKey" json:"application,omitempty"`
	Enabled     *bool   `gorm:"enabled" json:"enabled,omitempty"`
}

type AuthRole

type AuthRole struct {
	Name    *string `gorm:"primaryKey" json:"name,omitempty"`
	Enabled *bool   `gorm:"enabled" json:"enabled,omitempty"`
}

type AuthUser

type AuthUser struct {
	Username   *string `gorm:"primaryKey" json:"username,omitempty"`
	Role       *string `gorm:"role" json:"role,omitempty"`
	Password   *string `gorm:"password" json:"password,omitempty"`
	Passphrase *string `gorm:"passphrase" json:"passphrase,omitempty"`
	Enabled    *bool   `gorm:"enabled" json:"enabled,omitempty"`
}

type AuthenticationEndpoint

type AuthenticationEndpoint interface {
	Authenticate(ctx *gin.Context)
}

type AuthenticationService

type AuthenticationService interface {
	Authenticate(ctx context.Context, principal *Principal) error
	Validate(principal *Principal) []error
}

type AuthorizationFilter

type AuthorizationFilter interface {
	Authorize(ctx *gin.Context)
}

type AuthorizationService

type AuthorizationService interface {
	Authorize(ctx context.Context, tokenString string) (*Principal, error)
}

type BasePrincipalManager

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

func NewBasePrincipalManager

func NewBasePrincipalManager(passwordManager PasswordManager) *BasePrincipalManager

func (*BasePrincipalManager) ChangePassword

func (manager *BasePrincipalManager) ChangePassword(ctx context.Context, username string, password string) error

func (*BasePrincipalManager) Create

func (manager *BasePrincipalManager) Create(ctx context.Context, principal *Principal) error

func (*BasePrincipalManager) Delete

func (manager *BasePrincipalManager) Delete(ctx context.Context, username string) error

func (*BasePrincipalManager) Exists

func (manager *BasePrincipalManager) Exists(ctx context.Context, username string) error

func (*BasePrincipalManager) Find

func (manager *BasePrincipalManager) Find(ctx context.Context, username string) (*Principal, error)

func (*BasePrincipalManager) Update

func (manager *BasePrincipalManager) Update(ctx context.Context, principal *Principal) error

func (*BasePrincipalManager) VerifyResource

func (manager *BasePrincipalManager) VerifyResource(ctx context.Context, username string, resource string) error

type BcryptPasswordEncoder

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

func NewBcryptPasswordEncoder

func NewBcryptPasswordEncoder(options ...BcryptPasswordEncoderOption) *BcryptPasswordEncoder

func (*BcryptPasswordEncoder) Encode

func (encoder *BcryptPasswordEncoder) Encode(rawPassword string) (*string, error)

func (*BcryptPasswordEncoder) Matches

func (encoder *BcryptPasswordEncoder) Matches(encodedPassword string, rawPassword string) (*bool, error)

func (*BcryptPasswordEncoder) UpgradeEncoding

func (encoder *BcryptPasswordEncoder) UpgradeEncoding(encodedPassword string) (*bool, error)

type BcryptPasswordEncoderOption

type BcryptPasswordEncoderOption func(encoder *BcryptPasswordEncoder)

func WithBcryptCost

func WithBcryptCost(cost int) BcryptPasswordEncoderOption

type Claims

type Claims struct {
	jwt.RegisteredClaims
	Principal
}

type DefaultAuthenticationEndpoint

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

func NewDefaultAuthenticationEndpoint

func NewDefaultAuthenticationEndpoint(authenticationService AuthenticationService) *DefaultAuthenticationEndpoint

func (*DefaultAuthenticationEndpoint) Authenticate

func (endpoint *DefaultAuthenticationEndpoint) Authenticate(ctx *gin.Context)

type DefaultAuthenticationService

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

func NewDefaultAuthenticationService

func NewDefaultAuthenticationService(passwordEncoder PasswordEncoder, principalManager PrincipalManager, tokenManager TokenManager) *DefaultAuthenticationService

func (*DefaultAuthenticationService) Authenticate

func (service *DefaultAuthenticationService) Authenticate(ctx context.Context, principal *Principal) error

func (*DefaultAuthenticationService) Validate

func (service *DefaultAuthenticationService) Validate(principal *Principal) []error

type DefaultAuthorizationFilter

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

func NewDefaultAuthorizationFilter

func NewDefaultAuthorizationFilter(authorizationService AuthorizationService) *DefaultAuthorizationFilter

func (*DefaultAuthorizationFilter) Authorize

func (filter *DefaultAuthorizationFilter) Authorize(ctx *gin.Context)

type DefaultAuthorizationService

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

func NewDefaultAuthorizationService

func NewDefaultAuthorizationService(tokenManager TokenManager, principalManager PrincipalManager) *DefaultAuthorizationService

func (*DefaultAuthorizationService) Authorize

func (service *DefaultAuthorizationService) Authorize(ctx context.Context, tokenString string) (*Principal, error)

type DelegatingPasswordEncoder

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

func (*DelegatingPasswordEncoder) Encode

func (delegate *DelegatingPasswordEncoder) Encode(rawPassword string) (*string, error)

func (*DelegatingPasswordEncoder) Matches

func (delegate *DelegatingPasswordEncoder) Matches(encodedPassword string, rawPassword string) (*bool, error)

func (*DelegatingPasswordEncoder) UpgradeEncoding

func (delegate *DelegatingPasswordEncoder) UpgradeEncoding(encodedPassword string) (*bool, error)

type DelegatingPasswordEncoderOption

type DelegatingPasswordEncoderOption func(encoder *DelegatingPasswordEncoder)

func WithSupportedDecoders

func WithSupportedDecoders(decoders map[string]PasswordEncoder) DelegatingPasswordEncoderOption

type GormPrincipalManager

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

func NewGormPrincipalManager

func NewGormPrincipalManager(transactionHandler datasource.TransactionHandler[*gorm.DB], passwordManager PasswordManager) *GormPrincipalManager

func (*GormPrincipalManager) ChangePassword

func (manager *GormPrincipalManager) ChangePassword(_ context.Context, _ string, _ string) error

func (*GormPrincipalManager) Create

func (manager *GormPrincipalManager) Create(_ context.Context, _ *Principal) error

func (*GormPrincipalManager) Delete

func (manager *GormPrincipalManager) Delete(_ context.Context, _ string) error

func (*GormPrincipalManager) Exists

func (manager *GormPrincipalManager) Exists(_ context.Context, _ string) error

func (*GormPrincipalManager) Find

func (manager *GormPrincipalManager) Find(ctx context.Context, username string) (*Principal, error)

func (*GormPrincipalManager) Update

func (manager *GormPrincipalManager) Update(_ context.Context, _ *Principal) error

func (*GormPrincipalManager) VerifyResource

func (manager *GormPrincipalManager) VerifyResource(ctx context.Context, username string, resource string) error

type HashFunc

type HashFunc func() hash.Hash

type JwtTokenManager

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

func NewJwtTokenManager

func NewJwtTokenManager(options ...JwtTokenManagerOptions) *JwtTokenManager

func (*JwtTokenManager) Generate

func (manager *JwtTokenManager) Generate(principal *Principal) (*string, error)

func (*JwtTokenManager) Validate

func (manager *JwtTokenManager) Validate(tokenString string) (*Principal, error)

type JwtTokenManagerOptions

type JwtTokenManagerOptions func(tokenManager TokenManager)

func NewJwtTokenManagerOptions

func NewJwtTokenManagerOptions() JwtTokenManagerOptions

func (JwtTokenManagerOptions) WithIssuer

func (options JwtTokenManagerOptions) WithIssuer(issuer string) JwtTokenManagerOptions

func (JwtTokenManagerOptions) WithSigningKey

func (options JwtTokenManagerOptions) WithSigningKey(signingKey any) JwtTokenManagerOptions

func (JwtTokenManagerOptions) WithSigningMethod

func (options JwtTokenManagerOptions) WithSigningMethod(signingMethod jwt.SigningMethod) JwtTokenManagerOptions

func (JwtTokenManagerOptions) WithTimeout

func (options JwtTokenManagerOptions) WithTimeout(timeout time.Duration) JwtTokenManagerOptions

func (JwtTokenManagerOptions) WithVerifyingKey

func (options JwtTokenManagerOptions) WithVerifyingKey(verifyingKey any) JwtTokenManagerOptions

type JwtTokenManagerOptionsChain

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

func JwtTokenManagerOptionsChainBuilder

func JwtTokenManagerOptionsChainBuilder() *JwtTokenManagerOptionsChain

func (*JwtTokenManagerOptionsChain) Build

func (*JwtTokenManagerOptionsChain) WithIssuer

func (options *JwtTokenManagerOptionsChain) WithIssuer(issuer string) *JwtTokenManagerOptionsChain

func (*JwtTokenManagerOptionsChain) WithSigningKey

func (options *JwtTokenManagerOptionsChain) WithSigningKey(signingKey any) *JwtTokenManagerOptionsChain

func (*JwtTokenManagerOptionsChain) WithSigningMethod

func (options *JwtTokenManagerOptionsChain) WithSigningMethod(signingMethod jwt.SigningMethod) *JwtTokenManagerOptionsChain

func (*JwtTokenManagerOptionsChain) WithTimeout

func (*JwtTokenManagerOptionsChain) WithVerifyingKey

func (options *JwtTokenManagerOptionsChain) WithVerifyingKey(verifyingKey any) *JwtTokenManagerOptionsChain

type MockAuthenticationEndpoint

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

MockAuthenticationEndpoint is a mock of AuthenticationEndpoint interface.

func NewMockAuthenticationEndpoint

func NewMockAuthenticationEndpoint(ctrl *gomock.Controller) *MockAuthenticationEndpoint

NewMockAuthenticationEndpoint creates a new mock instance.

func (*MockAuthenticationEndpoint) Authenticate

func (m *MockAuthenticationEndpoint) Authenticate(ctx *gin.Context)

Authenticate mocks base method.

func (*MockAuthenticationEndpoint) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockAuthenticationEndpointMockRecorder

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

MockAuthenticationEndpointMockRecorder is the mock recorder for MockAuthenticationEndpoint.

func (*MockAuthenticationEndpointMockRecorder) Authenticate

func (mr *MockAuthenticationEndpointMockRecorder) Authenticate(ctx any) *gomock.Call

Authenticate indicates an expected call of Authenticate.

type MockAuthenticationService

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

MockAuthenticationService is a mock of AuthenticationService interface.

func NewMockAuthenticationService

func NewMockAuthenticationService(ctrl *gomock.Controller) *MockAuthenticationService

NewMockAuthenticationService creates a new mock instance.

func (*MockAuthenticationService) Authenticate

func (m *MockAuthenticationService) Authenticate(ctx context.Context, principal *Principal) error

Authenticate mocks base method.

func (*MockAuthenticationService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockAuthenticationService) Validate

func (m *MockAuthenticationService) Validate(principal *Principal) []error

Validate mocks base method.

type MockAuthenticationServiceMockRecorder

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

MockAuthenticationServiceMockRecorder is the mock recorder for MockAuthenticationService.

func (*MockAuthenticationServiceMockRecorder) Authenticate

func (mr *MockAuthenticationServiceMockRecorder) Authenticate(ctx, principal any) *gomock.Call

Authenticate indicates an expected call of Authenticate.

func (*MockAuthenticationServiceMockRecorder) Validate

func (mr *MockAuthenticationServiceMockRecorder) Validate(principal any) *gomock.Call

Validate indicates an expected call of Validate.

type MockAuthorizationFilter

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

MockAuthorizationFilter is a mock of AuthorizationFilter interface.

func NewMockAuthorizationFilter

func NewMockAuthorizationFilter(ctrl *gomock.Controller) *MockAuthorizationFilter

NewMockAuthorizationFilter creates a new mock instance.

func (*MockAuthorizationFilter) Authorize

func (m *MockAuthorizationFilter) Authorize(ctx *gin.Context)

Authorize mocks base method.

func (*MockAuthorizationFilter) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockAuthorizationFilterMockRecorder

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

MockAuthorizationFilterMockRecorder is the mock recorder for MockAuthorizationFilter.

func (*MockAuthorizationFilterMockRecorder) Authorize

func (mr *MockAuthorizationFilterMockRecorder) Authorize(ctx any) *gomock.Call

Authorize indicates an expected call of Authorize.

type MockAuthorizationService

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

MockAuthorizationService is a mock of AuthorizationService interface.

func NewMockAuthorizationService

func NewMockAuthorizationService(ctrl *gomock.Controller) *MockAuthorizationService

NewMockAuthorizationService creates a new mock instance.

func (*MockAuthorizationService) Authorize

func (m *MockAuthorizationService) Authorize(ctx context.Context, tokenString string) (*Principal, error)

Authorize mocks base method.

func (*MockAuthorizationService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockAuthorizationServiceMockRecorder

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

MockAuthorizationServiceMockRecorder is the mock recorder for MockAuthorizationService.

func (*MockAuthorizationServiceMockRecorder) Authorize

func (mr *MockAuthorizationServiceMockRecorder) Authorize(ctx, tokenString any) *gomock.Call

Authorize indicates an expected call of Authorize.

type MockPasswordEncoder

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

MockPasswordEncoder is a mock of PasswordEncoder interface.

func NewMockPasswordEncoder

func NewMockPasswordEncoder(ctrl *gomock.Controller) *MockPasswordEncoder

NewMockPasswordEncoder creates a new mock instance.

func (*MockPasswordEncoder) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPasswordEncoder) Encode

func (m *MockPasswordEncoder) Encode(rawPassword string) (*string, error)

Encode mocks base method.

func (*MockPasswordEncoder) Matches

func (m *MockPasswordEncoder) Matches(encodedPassword, rawPassword string) (*bool, error)

Matches mocks base method.

func (*MockPasswordEncoder) UpgradeEncoding

func (m *MockPasswordEncoder) UpgradeEncoding(encodedPassword string) (*bool, error)

UpgradeEncoding mocks base method.

type MockPasswordEncoderMockRecorder

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

MockPasswordEncoderMockRecorder is the mock recorder for MockPasswordEncoder.

func (*MockPasswordEncoderMockRecorder) Encode

func (mr *MockPasswordEncoderMockRecorder) Encode(rawPassword any) *gomock.Call

Encode indicates an expected call of Encode.

func (*MockPasswordEncoderMockRecorder) Matches

func (mr *MockPasswordEncoderMockRecorder) Matches(encodedPassword, rawPassword any) *gomock.Call

Matches indicates an expected call of Matches.

func (*MockPasswordEncoderMockRecorder) UpgradeEncoding

func (mr *MockPasswordEncoderMockRecorder) UpgradeEncoding(encodedPassword any) *gomock.Call

UpgradeEncoding indicates an expected call of UpgradeEncoding.

type MockPasswordGenerator

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

MockPasswordGenerator is a mock of PasswordGenerator interface.

func NewMockPasswordGenerator

func NewMockPasswordGenerator(ctrl *gomock.Controller) *MockPasswordGenerator

NewMockPasswordGenerator creates a new mock instance.

func (*MockPasswordGenerator) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPasswordGenerator) Generate

func (m *MockPasswordGenerator) Generate() string

Generate mocks base method.

func (*MockPasswordGenerator) Validate

func (m *MockPasswordGenerator) Validate(rawPassword string) error

Validate mocks base method.

type MockPasswordGeneratorMockRecorder

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

MockPasswordGeneratorMockRecorder is the mock recorder for MockPasswordGenerator.

func (*MockPasswordGeneratorMockRecorder) Generate

Generate indicates an expected call of Generate.

func (*MockPasswordGeneratorMockRecorder) Validate

func (mr *MockPasswordGeneratorMockRecorder) Validate(rawPassword any) *gomock.Call

Validate indicates an expected call of Validate.

type MockPasswordManager

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

MockPasswordManager is a mock of PasswordManager interface.

func NewMockPasswordManager

func NewMockPasswordManager(ctrl *gomock.Controller) *MockPasswordManager

NewMockPasswordManager creates a new mock instance.

func (*MockPasswordManager) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPasswordManager) Encode

func (m *MockPasswordManager) Encode(rawPassword string) (*string, error)

Encode mocks base method.

func (*MockPasswordManager) Generate

func (m *MockPasswordManager) Generate() string

Generate mocks base method.

func (*MockPasswordManager) Matches

func (m *MockPasswordManager) Matches(encodedPassword, rawPassword string) (*bool, error)

Matches mocks base method.

func (*MockPasswordManager) UpgradeEncoding

func (m *MockPasswordManager) UpgradeEncoding(encodedPassword string) (*bool, error)

UpgradeEncoding mocks base method.

func (*MockPasswordManager) Validate

func (m *MockPasswordManager) Validate(rawPassword string) error

Validate mocks base method.

type MockPasswordManagerMockRecorder

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

MockPasswordManagerMockRecorder is the mock recorder for MockPasswordManager.

func (*MockPasswordManagerMockRecorder) Encode

func (mr *MockPasswordManagerMockRecorder) Encode(rawPassword any) *gomock.Call

Encode indicates an expected call of Encode.

func (*MockPasswordManagerMockRecorder) Generate

Generate indicates an expected call of Generate.

func (*MockPasswordManagerMockRecorder) Matches

func (mr *MockPasswordManagerMockRecorder) Matches(encodedPassword, rawPassword any) *gomock.Call

Matches indicates an expected call of Matches.

func (*MockPasswordManagerMockRecorder) UpgradeEncoding

func (mr *MockPasswordManagerMockRecorder) UpgradeEncoding(encodedPassword any) *gomock.Call

UpgradeEncoding indicates an expected call of UpgradeEncoding.

func (*MockPasswordManagerMockRecorder) Validate

func (mr *MockPasswordManagerMockRecorder) Validate(rawPassword any) *gomock.Call

Validate indicates an expected call of Validate.

type MockPrincipalManager

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

MockPrincipalManager is a mock of PrincipalManager interface.

func NewMockPrincipalManager

func NewMockPrincipalManager(ctrl *gomock.Controller) *MockPrincipalManager

NewMockPrincipalManager creates a new mock instance.

func (*MockPrincipalManager) ChangePassword

func (m *MockPrincipalManager) ChangePassword(ctx context.Context, username, password string) error

ChangePassword mocks base method.

func (*MockPrincipalManager) Create

func (m *MockPrincipalManager) Create(ctx context.Context, principal *Principal) error

Create mocks base method.

func (*MockPrincipalManager) Delete

func (m *MockPrincipalManager) Delete(ctx context.Context, username string) error

Delete mocks base method.

func (*MockPrincipalManager) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPrincipalManager) Exists

func (m *MockPrincipalManager) Exists(ctx context.Context, username string) error

Exists mocks base method.

func (*MockPrincipalManager) Find

func (m *MockPrincipalManager) Find(ctx context.Context, username string) (*Principal, error)

Find mocks base method.

func (*MockPrincipalManager) Update

func (m *MockPrincipalManager) Update(ctx context.Context, principal *Principal) error

Update mocks base method.

func (*MockPrincipalManager) VerifyResource

func (m *MockPrincipalManager) VerifyResource(ctx context.Context, username, resource string) error

VerifyResource mocks base method.

type MockPrincipalManagerMockRecorder

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

MockPrincipalManagerMockRecorder is the mock recorder for MockPrincipalManager.

func (*MockPrincipalManagerMockRecorder) ChangePassword

func (mr *MockPrincipalManagerMockRecorder) ChangePassword(ctx, username, password any) *gomock.Call

ChangePassword indicates an expected call of ChangePassword.

func (*MockPrincipalManagerMockRecorder) Create

func (mr *MockPrincipalManagerMockRecorder) Create(ctx, principal any) *gomock.Call

Create indicates an expected call of Create.

func (*MockPrincipalManagerMockRecorder) Delete

func (mr *MockPrincipalManagerMockRecorder) Delete(ctx, username any) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockPrincipalManagerMockRecorder) Exists

func (mr *MockPrincipalManagerMockRecorder) Exists(ctx, username any) *gomock.Call

Exists indicates an expected call of Exists.

func (*MockPrincipalManagerMockRecorder) Find

func (mr *MockPrincipalManagerMockRecorder) Find(ctx, username any) *gomock.Call

Find indicates an expected call of Find.

func (*MockPrincipalManagerMockRecorder) Update

func (mr *MockPrincipalManagerMockRecorder) Update(ctx, principal any) *gomock.Call

Update indicates an expected call of Update.

func (*MockPrincipalManagerMockRecorder) VerifyResource

func (mr *MockPrincipalManagerMockRecorder) VerifyResource(ctx, username, resource any) *gomock.Call

VerifyResource indicates an expected call of VerifyResource.

type MockTokenManager

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

MockTokenManager is a mock of TokenManager interface.

func NewMockTokenManager

func NewMockTokenManager(ctrl *gomock.Controller) *MockTokenManager

NewMockTokenManager creates a new mock instance.

func (*MockTokenManager) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTokenManager) Generate

func (m *MockTokenManager) Generate(principal *Principal) (*string, error)

Generate mocks base method.

func (*MockTokenManager) Validate

func (m *MockTokenManager) Validate(tokenString string) (*Principal, error)

Validate mocks base method.

type MockTokenManagerMockRecorder

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

MockTokenManagerMockRecorder is the mock recorder for MockTokenManager.

func (*MockTokenManagerMockRecorder) Generate

func (mr *MockTokenManagerMockRecorder) Generate(principal any) *gomock.Call

Generate indicates an expected call of Generate.

func (*MockTokenManagerMockRecorder) Validate

func (mr *MockTokenManagerMockRecorder) Validate(tokenString any) *gomock.Call

Validate indicates an expected call of Validate.

type PasswordEncoder

type PasswordEncoder interface {
	Encode(rawPassword string) (*string, error)
	Matches(encodedPassword string, rawPassword string) (*bool, error)
	UpgradeEncoding(encodedPassword string) (*bool, error)
}

type PasswordGenerator

type PasswordGenerator interface {
	Generate() string
	Validate(rawPassword string) error
	// contains filtered or unexported methods
}

func NewPasswordGenerator

func NewPasswordGenerator(options ...PasswordGeneratorOptions) PasswordGenerator

type PasswordGeneratorOptions

type PasswordGeneratorOptions func(generator PasswordGenerator)

func NewPasswordGeneratorOptions

func NewPasswordGeneratorOptions() PasswordGeneratorOptions

func (PasswordGeneratorOptions) WithMinNum

func (options PasswordGeneratorOptions) WithMinNum(minNum int) PasswordGeneratorOptions

func (PasswordGeneratorOptions) WithMinSpecialChar

func (options PasswordGeneratorOptions) WithMinSpecialChar(minSpecialChar int) PasswordGeneratorOptions

func (PasswordGeneratorOptions) WithMinUpperCase

func (options PasswordGeneratorOptions) WithMinUpperCase(minUpperCase int) PasswordGeneratorOptions

func (PasswordGeneratorOptions) WithPasswordLength

func (options PasswordGeneratorOptions) WithPasswordLength(passwordLength int) PasswordGeneratorOptions

type PasswordGeneratorOptionsChain

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

func PasswordGeneratorOptionsChainBuilder

func PasswordGeneratorOptionsChainBuilder() *PasswordGeneratorOptionsChain

func (*PasswordGeneratorOptionsChain) Build

func (*PasswordGeneratorOptionsChain) WithMinNum

func (*PasswordGeneratorOptionsChain) WithMinSpecialChar

func (options *PasswordGeneratorOptionsChain) WithMinSpecialChar(minSpecialChar int) *PasswordGeneratorOptionsChain

func (*PasswordGeneratorOptionsChain) WithMinUpperCase

func (options *PasswordGeneratorOptionsChain) WithMinUpperCase(minUpperCase int) *PasswordGeneratorOptionsChain

func (*PasswordGeneratorOptionsChain) WithPasswordLength

func (options *PasswordGeneratorOptionsChain) WithPasswordLength(length int) *PasswordGeneratorOptionsChain

type PasswordManager

type PasswordManager interface {
	PasswordEncoder
	PasswordGenerator
}

func NewPasswordManager

func NewPasswordManager(passwordEncoder PasswordEncoder, passwordGenerator PasswordGenerator) PasswordManager

type Pbkdf2PasswordEncoder

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

func NewPbkdf2PasswordEncoder

func NewPbkdf2PasswordEncoder(options ...Pbkdf2PasswordEncoderOption) *Pbkdf2PasswordEncoder

func (*Pbkdf2PasswordEncoder) Encode

func (encoder *Pbkdf2PasswordEncoder) Encode(rawPassword string) (*string, error)

func (*Pbkdf2PasswordEncoder) Matches

func (encoder *Pbkdf2PasswordEncoder) Matches(encodedPassword string, rawPassword string) (*bool, error)

func (*Pbkdf2PasswordEncoder) UpgradeEncoding

func (encoder *Pbkdf2PasswordEncoder) UpgradeEncoding(encodedPassword string) (*bool, error)

type Pbkdf2PasswordEncoderOption

type Pbkdf2PasswordEncoderOption func(encoder *Pbkdf2PasswordEncoder)

func WithHashFunc

func WithHashFunc(hashFunc HashFunc) Pbkdf2PasswordEncoderOption

func WithPbkdf2Iterations

func WithPbkdf2Iterations(iterations int) Pbkdf2PasswordEncoderOption

func WithPbkdf2KeyLength

func WithPbkdf2KeyLength(keyLength int) Pbkdf2PasswordEncoderOption

func WithPbkdf2SaltLength

func WithPbkdf2SaltLength(saltLength int) Pbkdf2PasswordEncoderOption

type Principal

type Principal struct {
	Username           *string  `json:"username,omitempty" binding:"required"`
	Role               *string  `json:"role,omitempty"`
	Password           *string  `json:"password,omitempty" binding:"required"`
	Passphrase         *string  `json:"passphrase,omitempty" `
	Enabled            *bool    `json:"enabled,omitempty"`
	NonLocked          *bool    `json:"non_locked,omitempty"`
	NonExpired         *bool    `json:"non_expired,omitempty"`
	PasswordNonExpired *bool    `json:"password_non_expired,omitempty"`
	SignUpDone         *bool    `json:"signup_done,omitempty"`
	Resources          []string `json:"resources,omitempty"`
	Token              *string  `json:"token,omitempty"`
}

func GetPrincipalFromContext

func GetPrincipalFromContext(ctx *gin.Context) (*Principal, bool)

type PrincipalManager

type PrincipalManager interface {
	Create(ctx context.Context, principal *Principal) error
	Update(ctx context.Context, principal *Principal) error
	Delete(ctx context.Context, username string) error
	Find(ctx context.Context, username string) (*Principal, error)
	Exists(ctx context.Context, username string) error

	ChangePassword(ctx context.Context, username string, password string) error
	VerifyResource(ctx context.Context, username string, resource string) error
}

type ResourceCtxKey

type ResourceCtxKey struct{}

type ScryptPasswordEncoder

type ScryptPasswordEncoder struct {
	N int
	// contains filtered or unexported fields
}

func NewScryptPasswordEncoder

func NewScryptPasswordEncoder(options ...ScryptPasswordEncoderOption) *ScryptPasswordEncoder

func (*ScryptPasswordEncoder) Encode

func (encoder *ScryptPasswordEncoder) Encode(rawPassword string) (*string, error)

func (*ScryptPasswordEncoder) Matches

func (encoder *ScryptPasswordEncoder) Matches(encodedPassword string, rawPassword string) (*bool, error)

func (*ScryptPasswordEncoder) UpgradeEncoding

func (encoder *ScryptPasswordEncoder) UpgradeEncoding(encodedPassword string) (*bool, error)

type ScryptPasswordEncoderOption

type ScryptPasswordEncoderOption func(encoder *ScryptPasswordEncoder)

func WithScryptKeyLength

func WithScryptKeyLength(keyLength int) ScryptPasswordEncoderOption

func WithScryptN

func WithScryptN(N int) ScryptPasswordEncoderOption

func WithScryptP

func WithScryptP(p int) ScryptPasswordEncoderOption

func WithScryptR

func WithScryptR(r int) ScryptPasswordEncoderOption

func WithScryptSaltLength

func WithScryptSaltLength(saltLength int) ScryptPasswordEncoderOption

type TokenManager

type TokenManager interface {
	Generate(principal *Principal) (*string, error)
	Validate(tokenString string) (*Principal, error)
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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