Fix errors in ldap auth

This commit is contained in:
Jan Eitzinger 2023-08-16 09:19:41 +02:00
parent 202521cbfd
commit 4f6d1fec68
2 changed files with 10 additions and 7 deletions

View File

@ -158,13 +158,14 @@ 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)
}
}
jwtSessionAuth := &JWTSessionAuthenticator{}
if err := jwtSessionAuth.Init(auth, configs["jwt"]); err != nil {
@ -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)

View File

@ -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")