mirror of
https://github.com/h44z/wg-portal.git
synced 2026-11-20 20:53:40 +01:00
feat(auth): require changing default admin password (#778)
This commit is contained in:
@@ -19,6 +19,7 @@ const (
|
||||
|
||||
type UserAuthenticator interface {
|
||||
IsUserValid(ctx context.Context, id domain.UserIdentifier) bool
|
||||
IsDefaultPasswordInUse(ctx context.Context) bool
|
||||
}
|
||||
|
||||
type AuthenticationHandler struct {
|
||||
@@ -126,6 +127,21 @@ func (h AuthenticationHandler) UserIdMatch(idParameter string) func(next http.Ha
|
||||
}
|
||||
}
|
||||
|
||||
// RequireNonDefaultPassword prohibits actions if the default admin password is still in use.
|
||||
func (h AuthenticationHandler) RequireNonDefaultPassword() func(next http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if h.authenticator.IsDefaultPasswordInUse(r.Context()) {
|
||||
respond.JSON(w, http.StatusForbidden,
|
||||
model.Error{Code: http.StatusForbidden, Message: "default admin password must be changed first"})
|
||||
return
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func UserHasScopes(session SessionData, scopes ...Scope) bool {
|
||||
// No scopes give, so the check should succeed
|
||||
if len(scopes) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user