You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2023/07/28 03:26:09 UTC

[james-project] 02/07: JAMES-3930 ReadOnlyLDAPUsersDAO::list and ReadOnlyLDAPUsersDAO::countUsers should return distinct users

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 4ea43d2521af98690d1aed7e466e92aed505cfae
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Fri Jul 21 15:56:18 2023 +0700

    JAMES-3930 ReadOnlyLDAPUsersDAO::list and ReadOnlyLDAPUsersDAO::countUsers should return distinct users
    
    e.g we have some LDAP entries
    1. uid: alice-app1
       mail: alice@domain.tld
    
    2. uid: alice-app2
       mail: alice@domain.tld
    
    Then ReadOnlyLDAPUsersDAO::list should return only 1 Username `alice@domain.tld`
---
 .../main/java/org/apache/james/user/ldap/ReadOnlyLDAPUsersDAO.java  | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyLDAPUsersDAO.java b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyLDAPUsersDAO.java
index 0717a8326b..9c7d1d7fff 100644
--- a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyLDAPUsersDAO.java
+++ b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyLDAPUsersDAO.java
@@ -269,7 +269,8 @@ public class ReadOnlyLDAPUsersDAO implements UsersDAO, Configurable {
             .flatMap(Throwing.<String, Stream<SearchResultEntry>>function(s -> entriesFromDN(s, ldapConfiguration.getUserIdAttribute())).sneakyThrow())
             .flatMap(entry -> Optional.ofNullable(entry.getAttribute(ldapConfiguration.getUserIdAttribute())).stream())
             .map(Attribute::getValue)
-            .map(Username::of);
+            .map(Username::of)
+            .distinct();
     }
 
     /**
@@ -355,6 +356,8 @@ public class ReadOnlyLDAPUsersDAO implements UsersDAO, Configurable {
         return getValidUserDNs().stream()
             .map(Throwing.function(this::buildUser).sneakyThrow())
             .flatMap(Optional::stream)
+            .map(ReadOnlyLDAPUser::getUserName)
+            .distinct()
             .count();
     }
 
@@ -377,6 +380,7 @@ public class ReadOnlyLDAPUsersDAO implements UsersDAO, Configurable {
             return buildUserCollection(getValidUserDNs())
                 .stream()
                 .map(ReadOnlyLDAPUser::getUserName)
+                .distinct()
                 .iterator();
         } catch (LDAPException e) {
             throw new UsersRepositoryException("Unable to list users from ldap", e);


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org