diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/UserManagementClient.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/UserManagementClient.java index 5b9c8ee3a6d7..eba3147d7ec1 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/UserManagementClient.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/UserManagementClient.java @@ -26,6 +26,10 @@ public interface UserManagementClient { Single listUsers(String accessToken); + Single listUsers(@NonNull ListUsersRequest request); + + Single listUsers(@NonNull ListUsersRequest request, String accessToken); + Single grantUserRights(@NonNull GrantUserRightsRequest request); Single grantUserRights( diff --git a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/UserManagementClientImpl.java b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/UserManagementClientImpl.java index 280ffa38821e..ed0990c6f090 100644 --- a/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/UserManagementClientImpl.java +++ b/language-support/java/bindings-rxjava/src/main/java/com/daml/ledger/rxjava/grpc/UserManagementClientImpl.java @@ -80,21 +80,36 @@ public Single deleteUser( return deleteUser(request, Optional.of(accessToken)); } - private Single listUsers(@NonNull Optional maybeToken) { + private Single listUsers( + @NonNull Optional maybeRequest, @NonNull Optional maybeToken) { + UserManagementServiceOuterClass.ListUsersRequest request = + maybeRequest + .map(ListUsersRequest::toProto) + .orElse(UserManagementServiceOuterClass.ListUsersRequest.getDefaultInstance()); return Single.fromFuture( - StubHelper.authenticating(this.serviceFutureStub, maybeToken) - .listUsers(UserManagementServiceOuterClass.ListUsersRequest.getDefaultInstance())) + StubHelper.authenticating(this.serviceFutureStub, maybeToken).listUsers(request)) .map(ListUsersResponse::fromProto); } @Override public Single listUsers() { - return listUsers(Optional.empty()); + return listUsers(Optional.empty(), Optional.empty()); } @Override public Single listUsers(String accessToken) { - return listUsers(Optional.of(accessToken)); + return listUsers(Optional.empty(), Optional.of(accessToken)); + } + + @Override + public Single listUsers(@NonNull ListUsersRequest request) { + return listUsers(Optional.of(request), Optional.empty()); + } + + @Override + public Single listUsers( + @NonNull ListUsersRequest request, String accessToken) { + return listUsers(Optional.of(request), Optional.of(accessToken)); } private Single grantUserRights( diff --git a/language-support/java/bindings-rxjava/src/test/scala/com/daml/ledger/rxjava/grpc/UserManagementClientImplTest.scala b/language-support/java/bindings-rxjava/src/test/scala/com/daml/ledger/rxjava/grpc/UserManagementClientImplTest.scala index 061fdc2ebb16..32494221ec1e 100644 --- a/language-support/java/bindings-rxjava/src/test/scala/com/daml/ledger/rxjava/grpc/UserManagementClientImplTest.scala +++ b/language-support/java/bindings-rxjava/src/test/scala/com/daml/ledger/rxjava/grpc/UserManagementClientImplTest.scala @@ -10,6 +10,8 @@ import com.daml.ledger.rxjava.grpc.helpers.LedgerServices import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers +import java.util.Optional + class UserManagementClientImplTest extends AnyFlatSpec with Matchers with AuthMatchers { private val ledgerServices = new LedgerServices("user-management-service-ledger") @@ -22,6 +24,8 @@ class UserManagementClientImplTest extends AnyFlatSpec with Matchers with AuthMa client.getUser(new GetUserRequest("get")).blockingGet() client.deleteUser(new DeleteUserRequest("delete")).blockingGet() client.listUsers().blockingGet() + client.listUsers(new ListUsersRequest(Optional.empty(), 10)).blockingGet() + client.listUsers(new ListUsersRequest(Optional.of("page-token"), 20)).blockingGet() client .grantUserRights( new GrantUserRightsRequest( @@ -39,7 +43,7 @@ class UserManagementClientImplTest extends AnyFlatSpec with Matchers with AuthMa client.listUserRights(new ListUserRightsRequest("listRights")).blockingGet() val requests = service.requests() - requests should have length 7 + requests should have length 9 requests should contain theSameElementsAs Array( proto.CreateUserRequest( Some(proto.User("createId", "createParty")), @@ -48,6 +52,8 @@ class UserManagementClientImplTest extends AnyFlatSpec with Matchers with AuthMa proto.GetUserRequest("get"), proto.DeleteUserRequest("delete"), proto.ListUsersRequest(), + proto.ListUsersRequest(pageSize = 10), + proto.ListUsersRequest("page-token", 20), proto.GrantUserRightsRequest( "grant", Vector( @@ -97,6 +103,11 @@ class UserManagementClientImplTest extends AnyFlatSpec with Matchers with AuthMa client.listUsers().blockingGet() } } + expectUnauthenticated { + toAuthenticatedServer { client => + client.listUsers(new ListUsersRequest(Optional.empty(), 100)).blockingGet() + } + } } withClue("grantUserRights") { expectUnauthenticated { @@ -157,6 +168,11 @@ class UserManagementClientImplTest extends AnyFlatSpec with Matchers with AuthMa client.listUsers(emptyToken).blockingGet() } } + expectUnauthenticated { + toAuthenticatedServer { client => + client.listUsers(new ListUsersRequest(Optional.empty(), 100), emptyToken).blockingGet() + } + } } withClue("grantUserRights") { expectUnauthenticated { @@ -212,6 +228,9 @@ class UserManagementClientImplTest extends AnyFlatSpec with Matchers with AuthMa toAuthenticatedServer { client => client.listUsers(adminToken).blockingGet() } + toAuthenticatedServer { client => + client.listUsers(new ListUsersRequest(Optional.empty(), 100), adminToken).blockingGet() + } } withClue("grantUserRights") { toAuthenticatedServer { client => diff --git a/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ListUsersRequest.java b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ListUsersRequest.java new file mode 100644 index 000000000000..af8b8a09ab92 --- /dev/null +++ b/language-support/java/bindings/src/main/java/com/daml/ledger/javaapi/data/ListUsersRequest.java @@ -0,0 +1,55 @@ +// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.daml.ledger.javaapi.data; + +import com.daml.ledger.api.v1.admin.UserManagementServiceOuterClass; +import java.util.Objects; +import java.util.Optional; +import org.checkerframework.checker.nullness.qual.NonNull; + +public final class ListUsersRequest { + + private final Optional pageToken; + + private final Integer pageSize; + + public ListUsersRequest(@NonNull Optional pageToken, @NonNull Integer pageSize) { + this.pageToken = pageToken; + this.pageSize = pageSize; + } + + public Optional getPageToken() { + return pageToken; + } + + public Integer getPageSize() { + return pageSize; + } + + @Override + public String toString() { + return "ListUsersRequest{" + "pageToken=" + pageToken + ", pageSize=" + pageSize + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ListUsersRequest that = (ListUsersRequest) o; + return Objects.equals(pageToken, that.pageToken) && Objects.equals(pageSize, that.pageSize); + } + + @Override + public int hashCode() { + return Objects.hash(pageToken, pageSize); + } + + public UserManagementServiceOuterClass.ListUsersRequest toProto() { + UserManagementServiceOuterClass.ListUsersRequest.Builder builder = + UserManagementServiceOuterClass.ListUsersRequest.newBuilder(); + pageToken.ifPresent(builder::setPageToken); + builder.setPageSize(pageSize); + return builder.build(); + } +}