From 9c6a25ab6ce05a9cd0ef3c95ab335f4937ee8546 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Wed, 20 Dec 2023 19:43:17 +0000 Subject: [PATCH] fix: npe if ldap query doesn't return attributes We cannot assume the LDAP server will have group attributes programmed everytime. So handle it accordingly. --- pkg/api/ldap.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/api/ldap.go b/pkg/api/ldap.go index 608e14b45e..2e64b1c03b 100644 --- a/pkg/api/ldap.go +++ b/pkg/api/ldap.go @@ -216,8 +216,11 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string] } userDN := search.Entries[0].DN - userAttributes := search.Entries[0].Attributes[0] - userGroups := userAttributes.Values + var userGroups []string + if len(search.Entries[0].Attributes) > 0 { + userAttributes := search.Entries[0].Attributes[0] + userGroups = userAttributes.Values + } user := map[string]string{} for _, attr := range lc.Attributes {