From f0685919fdc98979e045732cb63a4bd577a30fd1 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Thu, 15 Jun 2023 12:00:45 +0200 Subject: [PATCH] Streamline auth error handling --- internal/auth/ldap.go | 5 +++-- internal/auth/local.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/auth/ldap.go b/internal/auth/ldap.go index 672f10d..81b0d93 100644 --- a/internal/auth/ldap.go +++ b/internal/auth/ldap.go @@ -6,6 +6,7 @@ package auth import ( "errors" + "fmt" "net/http" "os" "strings" @@ -85,8 +86,8 @@ func (la *LdapAuthenticator) Login( userDn := strings.Replace(la.config.UserBind, "{username}", user.Username, -1) if err := l.Bind(userDn, r.FormValue("password")); err != nil { - log.Error("Error while binding to ldap connection") - return nil, err + log.Errorf("AUTH/LOCAL > Authentication for user %s failed: %v", user.Username, err) + return nil, fmt.Errorf("AUTH/LDAP > Authentication failed") } return user, nil diff --git a/internal/auth/local.go b/internal/auth/local.go index 0813e23..29996a4 100644 --- a/internal/auth/local.go +++ b/internal/auth/local.go @@ -8,6 +8,7 @@ import ( "fmt" "net/http" + "github.com/ClusterCockpit/cc-backend/pkg/log" "golang.org/x/crypto/bcrypt" ) @@ -39,7 +40,8 @@ func (la *LocalAuthenticator) Login( r *http.Request) (*User, error) { if e := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(r.FormValue("password"))); e != nil { - return nil, fmt.Errorf("AUTH/LOCAL > user '%s' provided the wrong password (%w)", user.Username, e) + log.Errorf("AUTH/LOCAL > Authentication for user %s failed!", user.Username) + return nil, fmt.Errorf("AUTH/LOCAL > Authentication failed") } return user, nil