mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
91582ba03d
* Make LDAP attribute mapping case-insensitive * Add test case with attribute name different from schema's * Add fix to getArrayAttribute also and add test with mismatched letter case. * Update pkg/services/ldap/helpers.go Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
58 lines
999 B
Go
58 lines
999 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 strings.EqualFold(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 strings.EqualFold(attr.Name, name) && len(attr.Values) > 0 {
|
|
return attr.Values
|
|
}
|
|
}
|
|
return []string{}
|
|
}
|