2019-06-13 09:47:52 -05:00
|
|
|
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 {
|
2019-07-24 04:49:18 -05:00
|
|
|
if strings.ToLower(name) == "dn" {
|
|
|
|
return entry.DN
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:47:52 -05:00
|
|
|
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 {
|
2019-07-24 04:49:18 -05:00
|
|
|
if strings.ToLower(name) == "dn" {
|
|
|
|
return []string{entry.DN}
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:47:52 -05:00
|
|
|
for _, attr := range entry.Attributes {
|
|
|
|
if attr.Name == name && len(attr.Values) > 0 {
|
|
|
|
return attr.Values
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return []string{}
|
|
|
|
}
|