Commit b32d420a by Leonard Gram

ldap: refactoring.

parent 21a1507c
...@@ -273,25 +273,28 @@ func (a *ldapAuther) initialBind(username, userPassword string) error { ...@@ -273,25 +273,28 @@ func (a *ldapAuther) initialBind(username, userPassword string) error {
return nil return nil
} }
func appendIfNotEmpty(slice []string, values ...string) []string {
for _, v := range values {
if v != "" {
slice = append(slice, v)
}
}
return slice
}
func (a *ldapAuther) searchForUser(username string) (*LdapUserInfo, error) { func (a *ldapAuther) searchForUser(username string) (*LdapUserInfo, error) {
var searchResult *ldap.SearchResult var searchResult *ldap.SearchResult
var err error var err error
for _, searchBase := range a.server.SearchBaseDNs { for _, searchBase := range a.server.SearchBaseDNs {
attributes := make([]string, 0) attributes := make([]string, 0)
inputs := a.server.Attr
appendIfNotEmpty := func(slice []string, attr string) []string { attributes = appendIfNotEmpty(attributes,
if attr == "" { inputs.Username,
return slice inputs.Surname,
} inputs.Email,
return append(slice, attr) inputs.Name,
} inputs.MemberOf)
attributes = appendIfNotEmpty(attributes, a.server.Attr.Username)
attributes = appendIfNotEmpty(attributes, a.server.Attr.Surname)
attributes = appendIfNotEmpty(attributes, a.server.Attr.Email)
attributes = appendIfNotEmpty(attributes, a.server.Attr.Name)
attributes = appendIfNotEmpty(attributes, a.server.Attr.MemberOf)
searchReq := ldap.SearchRequest{ searchReq := ldap.SearchRequest{
BaseDN: searchBase, BaseDN: searchBase,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment