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"
|
2023-12-28 13:21:08 +00:00
|
|
|
|
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-10-09 11:17:46 +00:00
|
|
|
"ak-active": {strings.ToUpper(strconv.FormatBool(*u.IsActive))},
|
|
|
|
"ak-superuser": {strings.ToUpper(strconv.FormatBool(u.IsSuperuser))},
|
2023-02-22 13:18:22 +00:00
|
|
|
"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": {
|
2023-10-09 11:17:46 +00:00
|
|
|
constants.OCTop,
|
|
|
|
constants.OCPerson,
|
2023-07-08 18:51:05 +00:00
|
|
|
constants.OCOrgPerson,
|
|
|
|
constants.OCInetOrgPerson,
|
2023-10-09 11:17:46 +00:00
|
|
|
constants.OCUser,
|
2023-07-08 18:51:05 +00:00
|
|
|
constants.OCPosixAccount,
|
2023-10-09 11:17:46 +00:00
|
|
|
constants.OCAKUser,
|
2023-07-08 18:51:05 +00:00
|
|
|
},
|
2023-12-28 13:21:08 +00:00
|
|
|
"uidNumber": {pi.GetUserUidNumber(u)},
|
|
|
|
"gidNumber": {pi.GetUserGidNumber(u)},
|
2023-07-08 18:51:05 +00:00
|
|
|
"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}
|
|
|
|
}
|