From ceab1f732d2ea01c1df48748b73c61cc4cc4c774 Mon Sep 17 00:00:00 2001 From: Jens L Date: Thu, 16 Mar 2023 12:14:17 +0100 Subject: [PATCH] providers/ldap: fix duplicate attributes (#4972) closes #4971 Signed-off-by: Jens Langhammer --- .editorconfig | 3 +++ internal/outpost/ldap/entries.go | 8 ++++++-- internal/outpost/ldap/group/group.go | 8 ++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2a5b1f870..b80ea6f1a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ indent_size = 2 [*.{yaml,yml}] indent_size = 2 + +[*.go] +indent_style = tab diff --git a/internal/outpost/ldap/entries.go b/internal/outpost/ldap/entries.go index 9912188f9..af389f27d 100644 --- a/internal/outpost/ldap/entries.go +++ b/internal/outpost/ldap/entries.go @@ -30,11 +30,15 @@ func (pi *ProviderInstance) UserEntry(u api.User) *ldap.Entry { // Only append attributes that don't already exist // TODO: Remove in 2023.3 for _, rawAttr := range rawAttrs { + exists := false for _, attr := range attrs { - if !strings.EqualFold(attr.Name, rawAttr.Name) { - attrs = append(attrs, rawAttr) + if strings.EqualFold(attr.Name, rawAttr.Name) { + exists = true } } + if !exists { + attrs = append(attrs, rawAttr) + } } if u.IsActive == nil { diff --git a/internal/outpost/ldap/group/group.go b/internal/outpost/ldap/group/group.go index 089be6ebb..dc48f4a39 100644 --- a/internal/outpost/ldap/group/group.go +++ b/internal/outpost/ldap/group/group.go @@ -36,11 +36,15 @@ func (lg *LDAPGroup) Entry() *ldap.Entry { // Only append attributes that don't already exist // TODO: Remove in 2023.3 for _, rawAttr := range rawAttrs { + exists := false for _, attr := range attrs { - if !strings.EqualFold(attr.Name, rawAttr.Name) { - attrs = append(attrs, rawAttr) + if strings.EqualFold(attr.Name, rawAttr.Name) { + exists = true } } + if !exists { + attrs = append(attrs, rawAttr) + } } objectClass := []string{constants.OCGroup, constants.OCGroupOfUniqueNames, constants.OCGroupOfNames, constants.OCAKGroup, constants.OCPosixGroup}