mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 19:30:36 -06:00
1e5fc76601
* LDAP: improve POSIX support * Correctly abtain DN attributes result * Allow more flexibility with comparison mapping between POSIX group & user * Add devenv for POSIX LDAP server * Correct the docs Fixes #18140
58 lines
965 B
Go
58 lines
965 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 {
|
|
if strings.ToLower(name) == "dn" {
|
|
return entry.DN
|
|
}
|
|
|
|
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 {
|
|
if strings.ToLower(name) == "dn" {
|
|
return []string{entry.DN}
|
|
}
|
|
|
|
for _, attr := range entry.Attributes {
|
|
if attr.Name == name && len(attr.Values) > 0 {
|
|
return attr.Values
|
|
}
|
|
}
|
|
return []string{}
|
|
}
|