mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
7e97dbde65
* update ldap library and use go module path * add TLS min version and accepted min TLS version * set default min ver to library default * set default min ver to library default * add cipher list to toml * Update pkg/services/ldap/settings.go Co-authored-by: Karl Persson <kalle.persson@grafana.com> * Apply suggestions from code review Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com> * lint --------- Co-authored-by: Karl Persson <kalle.persson@grafana.com> Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
58 lines
1009 B
Go
58 lines
1009 B
Go
package ldap
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/go-ldap/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{}
|
|
}
|