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-05-16 19:07:01 +00:00
|
|
|
"goauthentik.io/outpost/api"
|
2021-04-19 22:30:27 +00:00
|
|
|
)
|
|
|
|
|
2021-07-01 09:50:51 +00:00
|
|
|
func BoolToString(in bool) string {
|
|
|
|
if in {
|
|
|
|
return "true"
|
|
|
|
}
|
|
|
|
return "false"
|
|
|
|
}
|
|
|
|
|
2021-04-19 22:30:27 +00:00
|
|
|
func AKAttrsToLDAP(attrs interface{}) []*ldap.EntryAttribute {
|
|
|
|
attrList := []*ldap.EntryAttribute{}
|
2021-05-24 14:09:05 +00:00
|
|
|
a := attrs.(*map[string]interface{})
|
|
|
|
for attrKey, attrValue := range *a {
|
2021-04-19 22:30:27 +00:00
|
|
|
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-07-01 09:50:51 +00:00
|
|
|
case bool:
|
|
|
|
entry.Values = []string{BoolToString(t)}
|
2021-04-19 22:30:27 +00:00
|
|
|
}
|
|
|
|
attrList = append(attrList, entry)
|
|
|
|
}
|
|
|
|
return attrList
|
|
|
|
}
|
2021-04-26 17:51:24 +00:00
|
|
|
|
2021-05-16 19:07:01 +00:00
|
|
|
func (pi *ProviderInstance) GroupsForUser(user api.User) []string {
|
2021-04-26 17:51:24 +00:00
|
|
|
groups := make([]string, len(user.Groups))
|
|
|
|
for i, group := range user.Groups {
|
|
|
|
groups[i] = pi.GetGroupDN(group)
|
|
|
|
}
|
|
|
|
return groups
|
|
|
|
}
|
|
|
|
|
2021-05-16 19:07:01 +00:00
|
|
|
func (pi *ProviderInstance) GetGroupDN(group api.Group) string {
|
|
|
|
return fmt.Sprintf("cn=%s,%s", group.Name, pi.GroupDN)
|
2021-04-26 17:51:24 +00:00
|
|
|
}
|