2021-11-05 09:37:30 +00:00
|
|
|
package group
|
|
|
|
|
|
|
|
import (
|
2022-10-16 20:32:18 +00:00
|
|
|
"strconv"
|
|
|
|
|
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/server"
|
|
|
|
"goauthentik.io/internal/outpost/ldap/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LDAPGroup struct {
|
|
|
|
DN string
|
|
|
|
CN string
|
|
|
|
Uid string
|
|
|
|
GidNumber string
|
|
|
|
Member []string
|
|
|
|
IsSuperuser bool
|
|
|
|
IsVirtualGroup bool
|
2023-02-22 14:26:41 +00:00
|
|
|
Attributes map[string]interface{}
|
2021-11-05 09:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (lg *LDAPGroup) Entry() *ldap.Entry {
|
2023-02-22 14:26:41 +00:00
|
|
|
attrs := utils.AttributesToLDAP(lg.Attributes, func(key string) string {
|
|
|
|
return utils.AttributeKeySanitize(key)
|
|
|
|
}, func(value []string) []string {
|
|
|
|
return value
|
|
|
|
})
|
2021-11-05 09:37:30 +00:00
|
|
|
|
2023-02-22 14:26:41 +00:00
|
|
|
objectClass := []string{constants.OCGroup, constants.OCGroupOfUniqueNames, constants.OCGroupOfNames, constants.OCAKGroup, constants.OCPosixGroup}
|
2021-11-05 09:37:30 +00:00
|
|
|
if lg.IsVirtualGroup {
|
|
|
|
objectClass = append(objectClass, constants.OCAKVirtualGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs = utils.EnsureAttributes(attrs, map[string][]string{
|
2023-02-22 13:18:22 +00:00
|
|
|
"ak-superuser": {strconv.FormatBool(lg.IsSuperuser)},
|
|
|
|
"objectClass": objectClass,
|
|
|
|
"member": lg.Member,
|
|
|
|
"cn": {lg.CN},
|
|
|
|
"uid": {lg.Uid},
|
|
|
|
"sAMAccountName": {lg.CN},
|
|
|
|
"gidNumber": {lg.GidNumber},
|
2021-11-05 09:37:30 +00:00
|
|
|
})
|
|
|
|
return &ldap.Entry{DN: lg.DN, Attributes: attrs}
|
|
|
|
}
|
|
|
|
|
|
|
|
func FromAPIGroup(g api.Group, si server.LDAPServerInstance) *LDAPGroup {
|
|
|
|
return &LDAPGroup{
|
|
|
|
DN: si.GetGroupDN(g.Name),
|
|
|
|
CN: g.Name,
|
|
|
|
Uid: string(g.Pk),
|
2023-12-28 13:21:08 +00:00
|
|
|
GidNumber: si.GetGroupGidNumber(g),
|
2021-11-05 09:37:30 +00:00
|
|
|
Member: si.UsersForGroup(g),
|
|
|
|
IsVirtualGroup: false,
|
|
|
|
IsSuperuser: *g.IsSuperuser,
|
2023-02-22 14:26:41 +00:00
|
|
|
Attributes: g.Attributes,
|
2021-11-05 09:37:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func FromAPIUser(u api.User, si server.LDAPServerInstance) *LDAPGroup {
|
|
|
|
return &LDAPGroup{
|
|
|
|
DN: si.GetVirtualGroupDN(u.Username),
|
|
|
|
CN: u.Username,
|
|
|
|
Uid: u.Uid,
|
2023-12-28 13:21:08 +00:00
|
|
|
GidNumber: si.GetUserGidNumber(u),
|
2021-11-05 09:37:30 +00:00
|
|
|
Member: []string{si.GetUserDN(u.Username)},
|
|
|
|
IsVirtualGroup: true,
|
|
|
|
IsSuperuser: false,
|
2023-02-22 14:26:41 +00:00
|
|
|
Attributes: nil,
|
2021-11-05 09:37:30 +00:00
|
|
|
}
|
|
|
|
}
|