mirror of
https://github.com/goauthentik/authentik
synced 2026-04-28 02:18:11 +02:00
* packages/client-go: init Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove mod/sum Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix translate Signed-off-by: Jens Langhammer <jens@goauthentik.io> * no go replace Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update rust makefile with pwd Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * fix build Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * don't need a version ig? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * exclude go client from cspell Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix main docker build Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Jens Langhammer <jens@goauthentik.io>
77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package group
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"beryju.io/ldap"
|
|
|
|
"goauthentik.io/internal/outpost/ldap/constants"
|
|
"goauthentik.io/internal/outpost/ldap/server"
|
|
"goauthentik.io/internal/outpost/ldap/utils"
|
|
api "goauthentik.io/packages/client-go"
|
|
)
|
|
|
|
type LDAPGroup struct {
|
|
DN string
|
|
CN string
|
|
Uid string
|
|
GidNumber string
|
|
Member []string
|
|
MemberOf []string
|
|
IsSuperuser bool
|
|
IsVirtualGroup bool
|
|
Attributes map[string]any
|
|
}
|
|
|
|
func (lg *LDAPGroup) Entry() *ldap.Entry {
|
|
attrs := utils.AttributesToLDAP(lg.Attributes, func(key string) string {
|
|
return utils.AttributeKeySanitize(key)
|
|
}, func(value []string) []string {
|
|
return value
|
|
})
|
|
|
|
objectClass := []string{constants.OCGroup, constants.OCGroupOfUniqueNames, constants.OCGroupOfNames, constants.OCAKGroup, constants.OCPosixGroup}
|
|
if lg.IsVirtualGroup {
|
|
objectClass = append(objectClass, constants.OCAKVirtualGroup)
|
|
}
|
|
|
|
attrs = utils.EnsureAttributes(attrs, map[string][]string{
|
|
"ak-superuser": {strconv.FormatBool(lg.IsSuperuser)},
|
|
"objectClass": objectClass,
|
|
"member": lg.Member,
|
|
"memberOf": lg.MemberOf,
|
|
"cn": {lg.CN},
|
|
"uid": {lg.Uid},
|
|
"sAMAccountName": {lg.CN},
|
|
"gidNumber": {lg.GidNumber},
|
|
})
|
|
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),
|
|
GidNumber: si.GetGroupGidNumber(g),
|
|
Member: si.MembersForGroup(g),
|
|
MemberOf: si.MemberOfForGroup(g),
|
|
IsVirtualGroup: false,
|
|
IsSuperuser: *g.IsSuperuser,
|
|
Attributes: g.Attributes,
|
|
}
|
|
}
|
|
|
|
func FromAPIUser(u api.User, si server.LDAPServerInstance) *LDAPGroup {
|
|
return &LDAPGroup{
|
|
DN: si.GetVirtualGroupDN(u.Username),
|
|
CN: u.Username,
|
|
Uid: u.Uid,
|
|
GidNumber: si.GetUserGidNumber(u),
|
|
Member: []string{si.GetUserDN(u.Username)},
|
|
IsVirtualGroup: true,
|
|
IsSuperuser: false,
|
|
Attributes: nil,
|
|
}
|
|
}
|