1b1d951495
* LDAP: use only one struct * Use only models.ExternalUserInfo * Add additional helper method :/ * Move all the helpers to one module * LDAP: refactoring * Rename some of the public methods and change their behaviour * Remove outdated methods * Simplify logic * More tests There is no and never were tests for settings.go, added tests for helper methods (cover is now about 100% for them). Added tests for the main LDAP logic, but there is some stuff to add. Dial() is not tested and not decoupled. It might be a challenge to do it properly * Restructure tests: * they wouldn't depend on external modules * more consistent naming * logical division * More guards for erroneous paths * Login: make login service an explicit dependency * LDAP: remove no longer needed test helper fns * LDAP: remove useless import * LDAP: Use new interface in multildap module * LDAP: corrections for the groups of multiple users * In case there is several users their groups weren't detected correctly * Simplify helpers module
50 lines
839 B
Go
50 lines
839 B
Go
package ldap
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"gopkg.in/ldap.v3"
|
|
)
|
|
|
|
func isMemberOf(memberOf []string, group string) bool {
|
|
if group == "*" {
|
|
return true
|
|
}
|
|
|
|
for _, member := range memberOf {
|
|
if strings.EqualFold(member, group) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func appendIfNotEmpty(slice []string, values ...string) []string {
|
|
for _, v := range values {
|
|
if v != "" {
|
|
slice = append(slice, v)
|
|
}
|
|
}
|
|
return slice
|
|
}
|
|
|
|
func getAttribute(name string, entry *ldap.Entry) string {
|
|
for _, attr := range entry.Attributes {
|
|
if attr.Name == name {
|
|
if len(attr.Values) > 0 {
|
|
return attr.Values[0]
|
|
}
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func getArrayAttribute(name string, entry *ldap.Entry) []string {
|
|
for _, attr := range entry.Attributes {
|
|
if attr.Name == name && len(attr.Values) > 0 {
|
|
return attr.Values
|
|
}
|
|
}
|
|
return []string{}
|
|
}
|