2021-11-05 09:37:30 +00:00
|
|
|
package group
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nmcclain/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/server"
|
|
|
|
"goauthentik.io/internal/outpost/ldap/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LDAPGroup struct {
|
|
|
|
DN string
|
|
|
|
CN string
|
|
|
|
Uid string
|
|
|
|
GidNumber string
|
|
|
|
Member []string
|
|
|
|
IsSuperuser bool
|
|
|
|
IsVirtualGroup bool
|
2022-05-27 14:28:26 +00:00
|
|
|
AKAttributes map[string]interface{}
|
2021-11-05 09:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (lg *LDAPGroup) Entry() *ldap.Entry {
|
|
|
|
attrs := utils.AKAttrsToLDAP(lg.AKAttributes)
|
|
|
|
|
|
|
|
objectClass := []string{constants.OCGroup, constants.OCGroupOfUniqueNames, constants.OCAKGroup}
|
|
|
|
if lg.IsVirtualGroup {
|
|
|
|
objectClass = append(objectClass, constants.OCAKVirtualGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs = utils.EnsureAttributes(attrs, map[string][]string{
|
|
|
|
"objectClass": objectClass,
|
|
|
|
"member": lg.Member,
|
|
|
|
"goauthentik.io/ldap/superuser": {utils.BoolToString(lg.IsSuperuser)},
|
|
|
|
"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.GetGidNumber(g),
|
|
|
|
Member: si.UsersForGroup(g),
|
|
|
|
IsVirtualGroup: false,
|
|
|
|
IsSuperuser: *g.IsSuperuser,
|
|
|
|
AKAttributes: 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.GetUidNumber(u),
|
|
|
|
Member: []string{si.GetUserDN(u.Username)},
|
|
|
|
IsVirtualGroup: true,
|
|
|
|
IsSuperuser: false,
|
|
|
|
AKAttributes: nil,
|
|
|
|
}
|
|
|
|
}
|