fix: npe if ldap query doesn't return attributes (#2151)

We cannot assume the LDAP server will have group attributes programmed
everytime. So handle it accordingly.

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
Ramkumar Chinchani
2024-01-12 14:08:35 -08:00
committed by GitHub
parent 1c756b4db9
commit d685adb029
+11 -3
View File
@@ -173,8 +173,11 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]
}
attributes := lc.Attributes
attributes = append(attributes, "dn")
attributes = append(attributes, lc.UserGroupAttribute)
if lc.UserGroupAttribute != "" {
attributes = append(attributes, lc.UserGroupAttribute)
}
searchScope := ldap.ScopeSingleLevel
@@ -216,8 +219,13 @@ 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 lc.UserGroupAttribute != "" && len(search.Entries[0].Attributes) > 0 {
userAttributes := search.Entries[0].Attributes[0]
userGroups = userAttributes.Values
}
user := map[string]string{}
for _, attr := range lc.Attributes {