diff --git a/CHANGES.md b/CHANGES.md index 4e0e50ae81b..4ec81ddac21 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Release Notes. Apollo 2.0.1 ------------------ -* [Upgrade spring boot to fix search user issue](https://github.com/apolloconfig/apollo/issues/4366) +* [Upgrade spring boot to fix search user issue](https://github.com/apolloconfig/apollo/pull/4366) +* [Fix search user duplication issue](https://github.com/apolloconfig/apollo/pull/4371) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/12?closed=1) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserServiceImpl.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserServiceImpl.java index 0d31d4cd3eb..4cc90ed6f00 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserServiceImpl.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserServiceImpl.java @@ -23,7 +23,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -98,18 +100,22 @@ private List findUsers(String keyword) { if (StringUtils.isEmpty(keyword)) { return userRepository.findFirst20ByEnabled(1); } - List users = new ArrayList<>(); + Map users = new HashMap<>(); List byUsername = userRepository .findByUsernameLikeAndEnabled("%" + keyword + "%", 1); List byUserDisplayName = userRepository .findByUserDisplayNameLikeAndEnabled("%" + keyword + "%", 1); if (!CollectionUtils.isEmpty(byUsername)) { - users.addAll(byUsername); + for (UserPO user : byUsername) { + users.put(user.getId(), user); + } } if (!CollectionUtils.isEmpty(byUserDisplayName)) { - users.addAll(byUserDisplayName); + for (UserPO user : byUserDisplayName) { + users.put(user.getId(), user); + } } - return users; + return new ArrayList<>(users.values()); } @Override diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java index 55ebd651a2f..7bda22f64ef 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java @@ -24,6 +24,8 @@ import com.ctrip.framework.apollo.portal.repository.UserRepository; import com.ctrip.framework.apollo.portal.spi.UserService; +import java.util.HashMap; +import java.util.Map; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -91,18 +93,22 @@ private List findUsers(String keyword) { if (StringUtils.isEmpty(keyword)) { return userRepository.findFirst20ByEnabled(1); } - List users = new ArrayList<>(); + Map users = new HashMap<>(); List byUsername = userRepository .findByUsernameLikeAndEnabled("%" + keyword + "%", 1); List byUserDisplayName = userRepository .findByUserDisplayNameLikeAndEnabled("%" + keyword + "%", 1); if (!CollectionUtils.isEmpty(byUsername)) { - users.addAll(byUsername); + for (UserPO user : byUsername) { + users.put(user.getId(), user); + } } if (!CollectionUtils.isEmpty(byUserDisplayName)) { - users.addAll(byUserDisplayName); + for (UserPO user : byUserDisplayName) { + users.put(user.getId(), user); + } } - return users; + return new ArrayList<>(users.values()); } @Override