providers/ldap: fix duplicate attributes (#4972)

closes #4971

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-03-16 12:14:17 +01:00 committed by Jens Langhammer
parent 01d2cce9ca
commit ceab1f732d
No known key found for this signature in database
3 changed files with 15 additions and 4 deletions

View File

@ -12,3 +12,6 @@ indent_size = 2
[*.{yaml,yml}] [*.{yaml,yml}]
indent_size = 2 indent_size = 2
[*.go]
indent_style = tab

View File

@ -30,11 +30,15 @@ func (pi *ProviderInstance) UserEntry(u api.User) *ldap.Entry {
// Only append attributes that don't already exist // Only append attributes that don't already exist
// TODO: Remove in 2023.3 // TODO: Remove in 2023.3
for _, rawAttr := range rawAttrs { for _, rawAttr := range rawAttrs {
exists := false
for _, attr := range attrs { for _, attr := range attrs {
if !strings.EqualFold(attr.Name, rawAttr.Name) { if strings.EqualFold(attr.Name, rawAttr.Name) {
attrs = append(attrs, rawAttr) exists = true
} }
} }
if !exists {
attrs = append(attrs, rawAttr)
}
} }
if u.IsActive == nil { if u.IsActive == nil {

View File

@ -36,11 +36,15 @@ func (lg *LDAPGroup) Entry() *ldap.Entry {
// Only append attributes that don't already exist // Only append attributes that don't already exist
// TODO: Remove in 2023.3 // TODO: Remove in 2023.3
for _, rawAttr := range rawAttrs { for _, rawAttr := range rawAttrs {
exists := false
for _, attr := range attrs { for _, attr := range attrs {
if !strings.EqualFold(attr.Name, rawAttr.Name) { if strings.EqualFold(attr.Name, rawAttr.Name) {
attrs = append(attrs, rawAttr) exists = true
} }
} }
if !exists {
attrs = append(attrs, rawAttr)
}
} }
objectClass := []string{constants.OCGroup, constants.OCGroupOfUniqueNames, constants.OCGroupOfNames, constants.OCAKGroup, constants.OCPosixGroup} objectClass := []string{constants.OCGroup, constants.OCGroupOfUniqueNames, constants.OCGroupOfNames, constants.OCAKGroup, constants.OCPosixGroup}