2021-11-05 09:37:30 +00:00
|
|
|
package ldap
|
|
|
|
|
|
|
|
import (
|
2023-02-22 14:26:41 +00:00
|
|
|
"fmt"
|
2022-10-16 20:32:18 +00:00
|
|
|
"strconv"
|
2023-02-22 14:26:41 +00:00
|
|
|
"strings"
|
2022-10-16 20:32:18 +00:00
|
|
|
|
2023-06-06 19:40:19 +00:00
|
|
|
"beryju.io/ldap"
|
2022-03-03 09:40:07 +00:00
|
|
|
"goauthentik.io/api/v3"
|
2021-11-05 09:37:30 +00:00
|
|
|
"goauthentik.io/internal/outpost/ldap/constants"
|
|
|
|
"goauthentik.io/internal/outpost/ldap/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (pi *ProviderInstance) UserEntry(u api.User) *ldap.Entry {
|
|
|
|
dn := pi.GetUserDN(u.Username)
|
2023-04-21 11:10:24 +00:00
|
|
|
attrs := utils.AttributesToLDAP(u.Attributes, func(key string) string {
|
|
|
|
return utils.AttributeKeySanitize(key)
|
|
|
|
}, func(value []string) []string {
|
2023-02-22 14:26:41 +00:00
|
|
|
for i, v := range value {
|
|
|
|
if strings.Contains(v, "%s") {
|
|
|
|
value[i] = fmt.Sprintf(v, u.Username)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return value
|
2023-04-21 11:10:24 +00:00
|
|
|
})
|
2021-11-05 09:37:30 +00:00
|
|
|
|
2022-09-23 20:11:47 +00:00
|
|
|
if u.IsActive == nil {
|
|
|
|
u.IsActive = api.PtrBool(false)
|
|
|
|
}
|
|
|
|
if u.Email == nil {
|
|
|
|
u.Email = api.PtrString("")
|
|
|
|
}
|
2021-11-05 09:37:30 +00:00
|
|
|
attrs = utils.EnsureAttributes(attrs, map[string][]string{
|
2023-02-22 13:18:22 +00:00
|
|
|
"ak-active": {strconv.FormatBool(*u.IsActive)},
|
|
|
|
"ak-superuser": {strconv.FormatBool(u.IsSuperuser)},
|
|
|
|
"memberOf": pi.GroupsForUser(u),
|
|
|
|
"cn": {u.Username},
|
|
|
|
"sAMAccountName": {u.Username},
|
|
|
|
"uid": {u.Uid},
|
|
|
|
"name": {u.Name},
|
|
|
|
"displayName": {u.Name},
|
|
|
|
"mail": {*u.Email},
|
2023-07-08 18:51:05 +00:00
|
|
|
"objectClass": {
|
|
|
|
constants.OCUser,
|
|
|
|
constants.OCOrgPerson,
|
|
|
|
constants.OCInetOrgPerson,
|
|
|
|
constants.OCAKUser,
|
|
|
|
constants.OCPosixAccount,
|
|
|
|
},
|
|
|
|
"uidNumber": {pi.GetUidNumber(u)},
|
|
|
|
"gidNumber": {pi.GetUidNumber(u)},
|
|
|
|
"homeDirectory": {fmt.Sprintf("/home/%s", u.Username)},
|
|
|
|
"sn": {u.Name},
|
2021-11-05 09:37:30 +00:00
|
|
|
})
|
|
|
|
return &ldap.Entry{DN: dn, Attributes: attrs}
|
|
|
|
}
|