Documentation
¶
Overview ¶
Package passlist provides BasicAuth for Go web-servers.
Copyright © 2019 M.Watermann, 10247 Berlin, Germany
All rights reserved
EMail : <support@mwat.de>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU General Public License along with this program. If not, see the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for details.
Index ¶
- func Deny(aRealm string, aWriter http.ResponseWriter)
- func Wrap(aHandler http.Handler, aRealm, aPasswdFile string, aAuthDecider TAuthDecider) http.Handler
- type TAuthDecider
- type TAuthNeeder
- type TAuthSkipper
- type TPassList
- func (ul *TPassList) Add(aUser, aPassword string) error
- func (ul *TPassList) Clear() *TPassList
- func (ul *TPassList) Exists(aUser string) (rOK bool)
- func (ul *TPassList) Find(aUser string) (rHash string, rOK bool)
- func (ul *TPassList) IsAuthenticated(aRequest *http.Request) bool
- func (ul *TPassList) Len() int
- func (ul *TPassList) List() (rList []string)
- func (ul *TPassList) Load() error
- func (ul *TPassList) Matches(aUser, aPassword string) (rOK bool)
- func (ul *TPassList) Remove(aUser string) *TPassList
- func (ul *TPassList) Store() (int, error)
- func (ul *TPassList) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deny ¶
func Deny(aRealm string, aWriter http.ResponseWriter)
Deny sends an "Unauthorised" notice to the remote host.
`aRealm` is the symbolic name of the host/domain to protect.
`aWriter` is used by an HTTP handler to construct an HTTP response.
func Wrap ¶
func Wrap(aHandler http.Handler, aRealm, aPasswdFile string, aAuthDecider TAuthDecider) http.Handler
Wrap returns a handler function that includes authentication, wrapping the given `aHandler` and calling it internally.
`aHandler` responds to the actual HTTP request; this is the handler to be called after successful authentication.
`aRealm` is the symbolic name of the domain/host to protect.
`aPasswdFile` is the name of the password file to use.
Types ¶
type TAuthDecider ¶
type TAuthDecider interface {
// NeedAuthentication returns `true` if authentication is needed,
// or `false` otherwise.
//
// `aRequest` holds the URL to check.
NeedAuthentication(aRequest *http.Request) bool
}
TAuthDecider is an interface deciding whether a given URL needs authentication or not.
type TAuthNeeder ¶
type TAuthNeeder bool
TAuthNeeder provides a `TAuthDecider` implementation always returning `true`.
func (TAuthNeeder) NeedAuthentication ¶
func (ad TAuthNeeder) NeedAuthentication(aRequest *http.Request) bool
NeedAuthentication returns `true` thus requiring authentication for any URL.
type TAuthSkipper ¶
type TAuthSkipper bool
TAuthSkipper provides a `TAuthDecider` implementation always returning `false`.
func (TAuthSkipper) NeedAuthentication ¶
func (ad TAuthSkipper) NeedAuthentication(aRequest *http.Request) bool
NeedAuthentication returns `false` thus skipping any authentication.
type TPassList ¶
type TPassList tPassList
TPassList holds the list of username/password values.
func LoadPasswords ¶
LoadPasswords reads the given `aFilename` returning a `TUserList` instance filled with data read from the password file and a possible error condition.
This function reads one line at a time of the password file skipping both empty lines and comments (identified by `#` or `;` at line start).
`aFilename` is the name of the password file to read.
func NewList ¶
NewList returns a new `TUserList` instance.
`aFilename` is the name of the password file to use for `Load()` and `Store()`
func (*TPassList) Add ¶
Add inserts `aUser` with `aPassword` into the list.
Before storing `aPassword` it gets hashed.
`aUser` is the username to use.
`aPassword` is the user's password to store.
func (*TPassList) Exists ¶
Exists returns `true` if `aUser` exists in the list, or `false` if not found.
`aUser` is the username to lookup.
func (*TPassList) Find ¶
Find returns the hashed password of `aUser` and `true`, or an empty string and `false` if not found.
`aUser` is the username to lookup.
func (*TPassList) IsAuthenticated ¶
IsAuthenticated checks `aRequest` for authentication data, returning `true` for successful authentication, or `false` otherwise.
On success the username/password are stored in the `aRequest.URL.User` structure to allow for other handlers checking its existence and act accordingly.
`aRequest` is an HTTP request received by a server.
func (*TPassList) Load ¶
Load reads the password file named in `LoadPasswords()` or `NewList()` replacing any older list's contents with the file's.
func (*TPassList) Matches ¶
Matches checks whether `aPassword` of `aUser` matches the stored password.
`aUser` the username to lookup.
`aPassword` the (unhashed) password to check.