0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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 {