Prevent duplicated entries

Signed-off-by: Yann David <davidyann88@gmail.com>
This commit is contained in:
Yann David 2019-08-07 13:16:26 -04:00
parent 51eb8bc60f
commit 6435f32bc5
No known key found for this signature in database
GPG Key ID: B005C1919206F2E0

View File

@ -230,9 +230,14 @@ func (session *Session) SearchUser(username string) ([]models.LdapUser, error) {
}
for _, groupEntry := range result.Entries {
if !contains(u.GroupDNList, groupEntry.DN) {
nestedGroupDNList = append(nestedGroupDNList, strings.TrimSpace(groupEntry.DN))
log.Debugf("Found group %v", groupEntry.DN)
} else {
log.Debugf("%v is already in GroupDNList", groupEntry.DN)
}
}
u.GroupDNList = append(u.GroupDNList, nestedGroupDNList...)
log.Debugf("Done searching for nested groups")
@ -441,3 +446,12 @@ func createNestedGroupFilter(userDN string) string {
filter = "(&(objectClass=group)(member:1.2.840.113556.1.4.1941:=" + userDN + "))"
return filter
}
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}