This commit is contained in:
laodaming 2023-11-22 13:13:12 +08:00
parent e5a73420b6
commit 79faa6a377

View File

@ -29,13 +29,17 @@ func (l *Ldap) GetLdapUserInfo(userDN string) (*LdapUserInfo, error) {
if len(res.Entries) != 1 {
return nil, errors.New("查询到不到用户信息")
}
user := &LdapUserInfo{}
for _, entry := range res.Entries {
if entry.DN != userDN {
continue
if len(res.Entries) == 0 {
return nil, errors.New("ldap user not exists(entry not exists)")
}
user.UserDN = entry.DN
for _, attr := range entry.Attributes {
userEntry := res.Entries[0]
if userEntry.DN != userDN {
return nil, errors.New("ldap user not exists(DN not match)")
}
user := &LdapUserInfo{
UserDN: userEntry.DN,
}
for _, attr := range userEntry.Attributes {
switch attr.Name {
case "uidNumber": //用户id
if len(attr.Values) == 0 {
@ -73,8 +77,6 @@ func (l *Ldap) GetLdapUserInfo(userDN string) (*LdapUserInfo, error) {
}
}
}
break
}
if user.UserId == 0 {
return nil, errors.New("查询到的不是用户信息!!!")
}