Documentation ¶
Overview ¶
Package auth defines potentially multiple mechanisms to determine whether supplied user credentials via an IMAP session can be found in a defined user information system. Examples include an authenticator based on a user database in a PostgreSQL database and a simple lookup function if username and password match.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileAuthenticator ¶
type FileAuthenticator struct { File string Separator string Users []User // contains filtered or unexported fields }
FileAuthenticator contains file based authentication information including the in-memory map of username to password mapping.
func NewFileAuthenticator ¶
func NewFileAuthenticator(file string, sep string) (*FileAuthenticator, error)
NewFileAuthenticator takes in a file name and a separator, reads in specified file and parses it line by line as username - password elements separated by the separator. At the end, the returned struct contains the information and an in-memory map of username mapped to password.
func (*FileAuthenticator) AuthenticatePlain ¶
func (f *FileAuthenticator) AuthenticatePlain(username string, password string, clientAddr string) (int, string, error)
AuthenticatePlain performs the actual authentication process by taking supplied credentials and attempting to find a matching entry the in-memory list taken from the authentication file.
func (*FileAuthenticator) GetWorkerForUser ¶
func (f *FileAuthenticator) GetWorkerForUser(workers map[string]config.Worker, id int) (string, error)
GetWorkerForUser returns the name of the worker node that is responsible for handling the user's mailbox.
type PlainAuthenticator ¶
type PlainAuthenticator interface { // GetWorkerForUser allows us to route an IMAP request to the // worker node responsible for a specific user. GetWorkerForUser(workers map[string]config.Worker, id int) (string, error) // AuthenticatePlain will be implemented by each of the // authentication methods of type PLAIN to perform the // actual part of checking supplied credentials. AuthenticatePlain(username string, password string, clientAddr string) (int, string, error) }
PlainAuthenticator defines the methods required to perform an IMAP AUTH=PLAIN authentication in order to reach authenticated state (also LOGIN).
type PostgresAuthenticator ¶ added in v0.1.6
type PostgresAuthenticator struct {
Conn *pgx.Conn
}
PostgresAuthenticator carries all relevant information needed to allow the PostgreSQL-based authenticator to properly authenticate incoming client requests.
func NewPostgresAuthenticator ¶ added in v0.1.6
func NewPostgresAuthenticator(ip string, port uint16, db string, user string, password string, useTLS bool) (*PostgresAuthenticator, error)
NewPostgresAuthenticator expects to be supplied with PostgreSQL database connection information from the config file. It then tries to connect to the database and returns an initialized struct above.
func (*PostgresAuthenticator) AuthenticatePlain ¶ added in v0.1.6
func (p *PostgresAuthenticator) AuthenticatePlain(username string, password string, clientAddr string) (int, string, error)
AuthenticatePlain is used to perform the actual process of looking up if the client supplied user credentials exist and match with an user entry in the PostgreSQL database.
func (*PostgresAuthenticator) GetWorkerForUser ¶ added in v0.1.6
func (p *PostgresAuthenticator) GetWorkerForUser(workers map[string]config.Worker, id int) (string, error)
GetWorkerForUser returns the name of the worker node that is responsible for handling the user's mailbox.
type UsersByName ¶
type UsersByName []User
UsersByName defines a list type of users to search efficiently.
func (UsersByName) Less ¶
func (u UsersByName) Less(i, j int) bool
func (UsersByName) Swap ¶
func (u UsersByName) Swap(i, j int)