2021-04-19 22:30:27 +00:00
|
|
|
package ldap
|
|
|
|
|
|
|
|
import (
|
2021-04-26 17:51:24 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-05-04 19:49:15 +00:00
|
|
|
"github.com/nmcclain/ldap"
|
2021-04-26 17:51:24 +00:00
|
|
|
"goauthentik.io/outpost/pkg/models"
|
2021-04-19 22:30:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func AKAttrsToLDAP(attrs interface{}) []*ldap.EntryAttribute {
|
|
|
|
attrList := []*ldap.EntryAttribute{}
|
|
|
|
for attrKey, attrValue := range attrs.(map[string]interface{}) {
|
|
|
|
entry := &ldap.EntryAttribute{Name: attrKey}
|
2021-04-26 10:24:46 +00:00
|
|
|
switch t := attrValue.(type) {
|
2021-04-19 22:30:27 +00:00
|
|
|
case []string:
|
2021-04-26 10:24:46 +00:00
|
|
|
entry.Values = t
|
2021-04-19 22:30:27 +00:00
|
|
|
case string:
|
2021-04-26 10:24:46 +00:00
|
|
|
entry.Values = []string{t}
|
2021-04-19 22:30:27 +00:00
|
|
|
}
|
|
|
|
attrList = append(attrList, entry)
|
|
|
|
}
|
|
|
|
return attrList
|
|
|
|
}
|
2021-04-26 17:51:24 +00:00
|
|
|
|
|
|
|
func (pi *ProviderInstance) GroupsForUser(user *models.User) []string {
|
|
|
|
groups := make([]string, len(user.Groups))
|
|
|
|
for i, group := range user.Groups {
|
|
|
|
groups[i] = pi.GetGroupDN(group)
|
|
|
|
}
|
|
|
|
return groups
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pi *ProviderInstance) GetGroupDN(group *models.Group) string {
|
|
|
|
return fmt.Sprintf("cn=%s,%s", *group.Name, pi.GroupDN)
|
|
|
|
}
|