diff --git a/api/src/main/java/org/apache/cloudstack/query/QueryService.java b/api/src/main/java/org/apache/cloudstack/query/QueryService.java index de9fbb55a26c..74c7a6158218 100644 --- a/api/src/main/java/org/apache/cloudstack/query/QueryService.java +++ b/api/src/main/java/org/apache/cloudstack/query/QueryService.java @@ -88,6 +88,8 @@ public interface QueryService { ListResponse searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException; + ListResponse searchForAllUsers(ListUsersCmd cmd); + ListResponse searchForEvents(ListEventsCmd cmd); ListResponse listTags(ListTagsCmd cmd); diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListUsersCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListUsersCmd.java index b2266dc8fd3b..dfc4f8bdbdf4 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListUsersCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListUsersCmd.java @@ -109,7 +109,7 @@ private String getListType() { } private boolean isACloudstackUser(final LdapUser ldapUser) { - final ListResponse response = _queryService.searchForUsers(new ListUsersCmd()); + final ListResponse response = _queryService.searchForAllUsers(new ListUsersCmd()); final List cloudstackUsers = response.getResponses(); if (cloudstackUsers != null && cloudstackUsers.size() != 0) { for (final UserResponse cloudstackUser : response.getResponses()) { diff --git a/plugins/user-authenticators/ldap/src/test/groovy/org/apache/cloudstack/ldap/LdapListUsersCmdSpec.groovy b/plugins/user-authenticators/ldap/src/test/groovy/org/apache/cloudstack/ldap/LdapListUsersCmdSpec.groovy index d6410d968669..1630e7290aa2 100644 --- a/plugins/user-authenticators/ldap/src/test/groovy/org/apache/cloudstack/ldap/LdapListUsersCmdSpec.groovy +++ b/plugins/user-authenticators/ldap/src/test/groovy/org/apache/cloudstack/ldap/LdapListUsersCmdSpec.groovy @@ -90,7 +90,7 @@ class LdapListUsersCmdSpec extends spock.lang.Specification { ListResponse queryServiceResponse = new ListResponse() queryServiceResponse.setResponses(responses) - queryService.searchForUsers(_) >> queryServiceResponse + queryService.searchForAllUsers(_) >> queryServiceResponse def ldapUser = new LdapUser("rmurphy", "rmurphy@cloudstack.org", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org", null, false, null) def ldapListUsersCmd = new LdapListUsersCmd(ldapManager,queryService) @@ -107,7 +107,7 @@ class LdapListUsersCmdSpec extends spock.lang.Specification { def ldapManager = Mock(LdapManager) def queryService = Mock(QueryService) - queryService.searchForUsers(_) >> new ListResponse() + queryService.searchForAllUsers(_) >> new ListResponse() def ldapUser = new LdapUser("rmurphy", "rmurphy@cloudstack.org", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org", null, false, null) def ldapListUsersCmd = new LdapListUsersCmd(ldapManager,queryService) diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index 9c728ef0f78a..8a33af6023e7 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -393,6 +393,24 @@ public ListResponse searchForUsers(ListUsersCmd cmd) throws Permis return response; } + @Override + public ListResponse searchForAllUsers(ListUsersCmd cmd) { + Pair, Integer> result = null; + Account caller = CallContext.current().getCallingAccount(); + + Filter searchFilter = new Filter(UserAccountJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchBuilder sb = _userAccountJoinDao.createSearchBuilder(); + SearchCriteria sc = sb.create(); + + result = _userAccountJoinDao.searchAndCount(sc, searchFilter); + ListResponse response = new ListResponse(); + List userResponses = + ViewResponseHelper.createUserResponse(CallContext.current().getCallingAccount().getDomainId(), + result.first().toArray(new UserAccountJoinVO[result.first().size()])); + response.setResponses(userResponses, result.second()); + return response; + } + private Pair, Integer> searchForUsersInternal(ListUsersCmd cmd) throws PermissionDeniedException { Account caller = CallContext.current().getCallingAccount();