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:
parent
1c756b4db9
commit
d685adb029
1 changed files with 11 additions and 3 deletions
|
@ -173,8 +173,11 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]
|
|||
}
|
||||
|
||||
attributes := lc.Attributes
|
||||
|
||||
attributes = append(attributes, "dn")
|
||||
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
|
||||
|
||||
var userGroups []string
|
||||
|
||||
if lc.UserGroupAttribute != "" && len(search.Entries[0].Attributes) > 0 {
|
||||
userAttributes := search.Entries[0].Attributes[0]
|
||||
userGroups := userAttributes.Values
|
||||
userGroups = userAttributes.Values
|
||||
}
|
||||
user := map[string]string{}
|
||||
|
||||
for _, attr := range lc.Attributes {
|
||||
|
|
Loading…
Reference in a new issue