mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-28 09:42:05 +01:00
Merge pull request #15864 from stonezdj/21oct25_fix_crash_missing_ldap_attribut
Check empty ldap attributes value
This commit is contained in:
commit
465240216a
@ -154,6 +154,9 @@ func (s *Session) SearchUser(username string) ([]model.User, error) {
|
|||||||
groupDNList := make([]string, 0)
|
groupDNList := make([]string, 0)
|
||||||
groupAttr := strings.ToLower(s.groupCfg.MembershipAttribute)
|
groupAttr := strings.ToLower(s.groupCfg.MembershipAttribute)
|
||||||
for _, attr := range ldapEntry.Attributes {
|
for _, attr := range ldapEntry.Attributes {
|
||||||
|
if attr == nil || len(attr.Values) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// OpenLdap sometimes contain leading space in username
|
// OpenLdap sometimes contain leading space in username
|
||||||
val := strings.TrimSpace(attr.Values[0])
|
val := strings.TrimSpace(attr.Values[0])
|
||||||
log.Debugf("Current ldap entry attr name: %s\n", attr.Name)
|
log.Debugf("Current ldap entry attr name: %s\n", attr.Name)
|
||||||
@ -374,7 +377,9 @@ func (s *Session) searchGroup(groupDN, filter, gName, groupNameAttribute string)
|
|||||||
return ldapGroups, nil
|
return ldapGroups, nil
|
||||||
}
|
}
|
||||||
groupName := ""
|
groupName := ""
|
||||||
if len(result.Entries[0].Attributes) > 0 {
|
if len(result.Entries[0].Attributes) > 0 &&
|
||||||
|
result.Entries[0].Attributes[0] != nil &&
|
||||||
|
len(result.Entries[0].Attributes[0].Values) > 0 {
|
||||||
groupName = result.Entries[0].Attributes[0].Values[0]
|
groupName = result.Entries[0].Attributes[0].Values[0]
|
||||||
} else {
|
} else {
|
||||||
groupName = groupDN
|
groupName = groupDN
|
||||||
|
Loading…
Reference in New Issue
Block a user