2018-01-24 02:26:26 +00:00
|
|
|
package auth
|
|
|
|
|
2018-02-07 22:25:00 +00:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
2018-01-24 02:26:26 +00:00
|
|
|
|
2018-03-24 16:12:02 +00:00
|
|
|
type AuthData struct {
|
2021-05-29 21:14:15 +00:00
|
|
|
User string
|
|
|
|
Group string
|
|
|
|
Properties map[string]string
|
2018-03-24 16:12:02 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 02:26:26 +00:00
|
|
|
type AuthManager interface {
|
2018-03-24 16:12:02 +00:00
|
|
|
AddUser(user string, group string, password string) error
|
|
|
|
DeleteUser(user string) error
|
|
|
|
DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, bool)
|
2018-01-24 02:26:26 +00:00
|
|
|
}
|
2018-03-24 16:12:02 +00:00
|
|
|
|
2021-01-19 03:02:59 +00:00
|
|
|
type Authenticator interface {
|
|
|
|
DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, bool)
|
|
|
|
}
|
|
|
|
|
2018-03-24 16:12:02 +00:00
|
|
|
//----------------------------------------------------------------------------------------------------------------------
|
|
|
|
func NewAuth(kind string) AuthManager {
|
|
|
|
switch kind {
|
|
|
|
case "basic":
|
|
|
|
return NewBasicAuth()
|
|
|
|
|
|
|
|
case "token":
|
|
|
|
return NewTokenAuth()
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NewNoAuth()
|
|
|
|
}
|
2021-01-19 03:23:52 +00:00
|
|
|
}
|