From 4f6d1fec68f53a9dee3f1727f2abfb1b95dfd738 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Wed, 16 Aug 2023 09:19:41 +0200 Subject: [PATCH] Fix errors in ldap auth --- internal/auth/auth.go | 13 +++++++------ internal/auth/ldap.go | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 8149bc1..500ef1a 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -158,12 +158,13 @@ func Init(db *sqlx.DB, } if config, ok := configs["ldap"]; ok { - auth.LdapAuth = &LdapAuthenticator{} - if err := auth.LdapAuth.Init(auth, config); err != nil { - log.Error("Error while initializing authentication -> ldapAuth init failed") - return nil, err + ldapAuth := &LdapAuthenticator{} + if err := ldapAuth.Init(auth, config); err != nil { + log.Warn("Error while initializing authentication -> ldapAuth init failed") + } else { + auth.LdapAuth = ldapAuth + auth.authenticators = append(auth.authenticators, auth.LdapAuth) } - auth.authenticators = append(auth.authenticators, auth.LdapAuth) } jwtSessionAuth := &JWTSessionAuthenticator{} @@ -174,7 +175,7 @@ func Init(db *sqlx.DB, } jwtCookieSessionAuth := &JWTCookieSessionAuthenticator{} - if err := jwtSessionAuth.Init(auth, configs["jwt"]); err != nil { + if err := jwtCookieSessionAuth.Init(auth, configs["jwt"]); err != nil { log.Warn("Error while initializing authentication -> jwtCookieSessionAuth init failed") } else { auth.authenticators = append(auth.authenticators, jwtCookieSessionAuth) diff --git a/internal/auth/ldap.go b/internal/auth/ldap.go index 17b5c0c..9feebc1 100644 --- a/internal/auth/ldap.go +++ b/internal/auth/ldap.go @@ -59,6 +59,8 @@ func (la *LdapAuthenticator) Init( log.Print("sync done") } }() + } else { + return fmt.Errorf("missing LDAP configuration") } return nil @@ -73,7 +75,7 @@ func (la *LdapAuthenticator) CanLogin( if user != nil && user.AuthSource == AuthViaLDAP { return true } else { - if la.config.SyncUserOnLogin { + if la.config != nil && la.config.SyncUserOnLogin { l, err := la.getLdapConnection(true) if err != nil { log.Error("LDAP connection error")