diff --git a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java index d131ea8a49..80e5ef2614 100644 --- a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java +++ b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java @@ -76,6 +76,7 @@ import org.cloudfoundry.client.v3.spaces.SpacesV3; import org.cloudfoundry.client.v3.stacks.StacksV3; import org.cloudfoundry.client.v3.tasks.Tasks; +import org.cloudfoundry.client.v3.users.UsersV3; import org.cloudfoundry.reactor.ConnectionContext; import org.cloudfoundry.reactor.TokenProvider; import org.cloudfoundry.reactor.client.v2.applications.ReactorApplicationsV2; @@ -136,6 +137,7 @@ import org.cloudfoundry.reactor.client.v3.spaces.ReactorSpacesV3; import org.cloudfoundry.reactor.client.v3.stacks.ReactorStacksV3; import org.cloudfoundry.reactor.client.v3.tasks.ReactorTasks; +import org.cloudfoundry.reactor.client.v3.users.ReactorUsersV3; import org.immutables.value.Value; import reactor.core.publisher.Mono; @@ -509,6 +511,12 @@ public Users users() { return new ReactorUsers(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); } + @Override + @Value.Derived + public UsersV3 usersV3() { + return new ReactorUsersV3(getConnectionContext(), getRootV3(), getTokenProvider(), getRequestTags()); + } + /** * The connection context */ diff --git a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/users/ReactorUsersV3.java b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/users/ReactorUsersV3.java new file mode 100644 index 0000000000..69d48d9bae --- /dev/null +++ b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/users/ReactorUsersV3.java @@ -0,0 +1,85 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.reactor.client.v3.users; + +import java.util.Map; +import org.cloudfoundry.client.v3.users.*; +import org.cloudfoundry.reactor.ConnectionContext; +import org.cloudfoundry.reactor.TokenProvider; +import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations; +import reactor.core.publisher.Mono; + +/** + * The Reactor-based implementation of {@link UsersV3} + */ +public class ReactorUsersV3 extends AbstractClientV3Operations implements UsersV3 { + + /** + * Creates an instance + * + * @param connectionContext the {@link ConnectionContext} to use when communicating with the server + * @param root the root URI of the server. Typically, something like {@code https://api.cloudfoundry.your.company.com}. + * @param tokenProvider the {@link TokenProvider} to use when communicating with the server + * @param requestTags map with custom http headers which will be added to web request + */ + public ReactorUsersV3( + ConnectionContext connectionContext, + Mono root, + TokenProvider tokenProvider, + Map requestTags) { + super(connectionContext, root, tokenProvider, requestTags); + } + + @Override + public Mono create(CreateUserRequest request) { + return post(request, CreateUserResponse.class, builder -> builder.pathSegment("users")) + .checkpoint(); + } + + @Override + public Mono get(GetUserRequest request) { + return get( + request, + GetUserResponse.class, + builder -> builder.pathSegment("users", request.getUserId())) + .checkpoint(); + } + + @Override + public Mono list(ListUsersRequest request) { + return get(request, ListUsersResponse.class, builder -> builder.pathSegment("users")) + .checkpoint(); + } + + @Override + public Mono update(UpdateUserRequest request) { + return patch( + request, + UpdateUserResponse.class, + builder -> builder.pathSegment("users", request.getUserId())) + .checkpoint(); + } + + @Override + public Mono delete(DeleteUserRequest request) { + return delete( + request, + Void.class, + builder -> builder.pathSegment("users", request.getUserId())) + .checkpoint(); + } +} diff --git a/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/users/ReactorUsersV3Test.java b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/users/ReactorUsersV3Test.java new file mode 100644 index 0000000000..b9d78e9a69 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/users/ReactorUsersV3Test.java @@ -0,0 +1,215 @@ +package org.cloudfoundry.reactor.client.v3.users; + +import static io.netty.handler.codec.http.HttpMethod.*; +import static io.netty.handler.codec.http.HttpResponseStatus.*; + +import java.time.Duration; +import java.util.Collections; +import java.util.Map; +import org.cloudfoundry.client.v3.Link; +import org.cloudfoundry.client.v3.Metadata; +import org.cloudfoundry.client.v3.Pagination; +import org.cloudfoundry.client.v3.users.*; +import org.cloudfoundry.reactor.InteractionContext; +import org.cloudfoundry.reactor.TestRequest; +import org.cloudfoundry.reactor.TestResponse; +import org.cloudfoundry.reactor.client.AbstractClientApiTest; +import org.junit.jupiter.api.Test; +import reactor.test.StepVerifier; + +final class ReactorUsersV3Test extends AbstractClientApiTest { + private final ReactorUsersV3 users = + new ReactorUsersV3( + CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER, Collections.emptyMap()); + + @Test + void create() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(POST) + .path("/users") + .payload("fixtures/client/v3/users/POST_request.json") + .build()) + .response( + TestResponse.builder() + .status(CREATED) + .payload("fixtures/client/v3/users/POST_response.json") + .build()) + .build()); + + this.users + .create( + CreateUserRequest.builder() + .userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5") + .build()) + .as(StepVerifier::create) + .expectNext( + CreateUserResponse.builder() + .from( + expectedUserResource( + Collections.emptyMap(), Collections.emptyMap())) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + void get() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(GET) + .path("/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5") + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload("fixtures/client/v3/users/GET_{id}_response.json") + .build()) + .build()); + + this.users + .get( + GetUserRequest.builder() + .userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5") + .build()) + .as(StepVerifier::create) + .expectNext( + GetUserResponse.builder() + .from( + expectedUserResource( + Collections.emptyMap(), Collections.emptyMap())) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + void list() { + mockRequest( + InteractionContext.builder() + .request(TestRequest.builder().method(GET).path("/users").build()) + .response( + TestResponse.builder() + .status(OK) + .payload("fixtures/client/v3/users/GET_response.json") + .build()) + .build()); + + Link first = + Link.builder().href("https://api.example.org/v3/users?page=1&per_page=1").build(); + Link last = + Link.builder().href("https://api.example.org/v3/users?page=1&per_page=1").build(); + this.users + .list(ListUsersRequest.builder().build()) + .as(StepVerifier::create) + .expectNext( + ListUsersResponse.builder() + .pagination( + Pagination.builder() + .first(first) + .last(last) + .totalResults(1) + .totalPages(1) + .build()) + .resource( + expectedUserResource( + Collections.emptyMap(), Collections.emptyMap())) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + void update() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(PATCH) + .path("/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5") + .payload("fixtures/client/v3/users/PATCH_{id}_request.json") + .build()) + .response( + TestResponse.builder() + .status(CREATED) + .payload( + "fixtures/client/v3/users/PATCH_{id}_response.json") + .build()) + .build()); + + this.users + .update( + UpdateUserRequest.builder() + .userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5") + .metadata( + Metadata.builder() + .putAllAnnotations( + Collections.singletonMap( + "note", "detailed information")) + .putAllLabels( + Collections.singletonMap( + "environment", "production")) + .build()) + .build()) + .as(StepVerifier::create) + .expectNext( + UpdateUserResponse.builder() + .from( + expectedUserResource( + Collections.singletonMap( + "note", "detailed information"), + Collections.singletonMap( + "environment", "production"))) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + void delete() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(DELETE) + .path("/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5") + .build()) + .response(TestResponse.builder().status(ACCEPTED).build()) + .build()); + + this.users + .delete( + DeleteUserRequest.builder() + .userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5") + .build()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + UserResource expectedUserResource(Map labels, Map annotations) { + return UserResource.builder() + .id("3a5d3d89-3f89-4f05-8188-8a2b298c79d5") + .createdAt("2019-03-08T01:06:19Z") + .updatedAt("2019-03-08T01:06:19Z") + .username("some-name") + .presentationName("some-name") + .origin("uaa") + .metadata( + Metadata.builder() + .putAllAnnotations(labels) + .putAllLabels(annotations) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5") + .build()) + .build(); + } +} diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/GET_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/GET_response.json new file mode 100644 index 0000000000..c727d7dbe1 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/GET_response.json @@ -0,0 +1,33 @@ +{ + "pagination": { + "total_results": 1, + "total_pages": 1, + "first": { + "href": "https://api.example.org/v3/users?page=1&per_page=1" + }, + "last": { + "href": "https://api.example.org/v3/users?page=1&per_page=1" + }, + "next": null, + "previous": null + }, + "resources": [ + { + "guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5", + "created_at": "2019-03-08T01:06:19Z", + "updated_at": "2019-03-08T01:06:19Z", + "username": "some-name", + "presentation_name": "some-name", + "origin": "uaa", + "metadata": { + "labels": {}, + "annotations": {} + }, + "links": { + "self": { + "href": "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5" + } + } + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/GET_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/GET_{id}_response.json new file mode 100644 index 0000000000..b60ce5ab33 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/GET_{id}_response.json @@ -0,0 +1,17 @@ +{ + "guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5", + "created_at": "2019-03-08T01:06:19Z", + "updated_at": "2019-03-08T01:06:19Z", + "username": "some-name", + "presentation_name": "some-name", + "origin": "uaa", + "metadata": { + "labels": {}, + "annotations": {} + }, + "links": { + "self": { + "href": "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/PATCH_{id}_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/PATCH_{id}_request.json new file mode 100644 index 0000000000..52c4a1b610 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/PATCH_{id}_request.json @@ -0,0 +1,10 @@ +{ + "metadata": { + "labels": { + "environment": "production" + }, + "annotations": { + "note": "detailed information" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/PATCH_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/PATCH_{id}_response.json new file mode 100644 index 0000000000..f1729ecb51 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/PATCH_{id}_response.json @@ -0,0 +1,21 @@ +{ + "guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5", + "created_at": "2019-03-08T01:06:19Z", + "updated_at": "2019-03-08T01:06:19Z", + "username": "some-name", + "presentation_name": "some-name", + "origin": "uaa", + "metadata": { + "labels": { + "environment": "production" + }, + "annotations": { + "note": "detailed information" + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/POST_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/POST_request.json new file mode 100644 index 0000000000..e5463b4edb --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/POST_request.json @@ -0,0 +1,3 @@ +{ + "guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5" +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/POST_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/POST_response.json new file mode 100644 index 0000000000..b60ce5ab33 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/users/POST_response.json @@ -0,0 +1,17 @@ +{ + "guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5", + "created_at": "2019-03-08T01:06:19Z", + "updated_at": "2019-03-08T01:06:19Z", + "username": "some-name", + "presentation_name": "some-name", + "origin": "uaa", + "metadata": { + "labels": {}, + "annotations": {} + }, + "links": { + "self": { + "href": "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java index bfd4f1bd2a..0f85e973e5 100644 --- a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java @@ -74,6 +74,7 @@ import org.cloudfoundry.client.v3.spaces.SpacesV3; import org.cloudfoundry.client.v3.stacks.StacksV3; import org.cloudfoundry.client.v3.tasks.Tasks; +import org.cloudfoundry.client.v3.users.UsersV3; /** * Main entry point to the Cloud Foundry Client API @@ -375,4 +376,9 @@ public interface CloudFoundryClient { * Main entry point to the Cloud Foundry Users Client API */ Users users(); + + /** + * Main entry point to the Cloud Foundry Users V3 Client API + */ + UsersV3 usersV3(); } diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/User.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/User.java new file mode 100644 index 0000000000..cf6ffd4a89 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/User.java @@ -0,0 +1,56 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v3.Metadata; +import org.cloudfoundry.client.v3.Resource; + +/** + * Base class for responses that are users + */ +public abstract class User extends Resource { + + /** + * The name registered in UAA; will be null for UAA clients and non-UAA users + */ + @JsonProperty("username") + @Nullable + public abstract String getUsername(); + + /** + * The name displayed for the user; for UAA users, this is the same as the username. For UAA clients, this is the UAA client ID + */ + @JsonProperty("presentation_name") + @Nullable + public abstract String getPresentationName(); + + /** + * The identity provider for the UAA user; will be null for UAA clients + */ + @JsonProperty("origin") + @Nullable + public abstract String getOrigin(); + + /** + * The metadata Labels and Annotations applied to the user + */ + @JsonProperty("metadata") + @Nullable + public abstract Metadata getMetadata(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/UsersV3.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/UsersV3.java new file mode 100644 index 0000000000..906582ead3 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/UsersV3.java @@ -0,0 +1,65 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import reactor.core.publisher.Mono; + +/** + * Main entry point to the Cloud Foundry Users V3 Client API + */ +public interface UsersV3 { + + /** + * Makes the Create a User request + * + * @param request the Create User request + * @return the response from the Create User request + */ + Mono create(CreateUserRequest request); + + /** + * Makes the Get a User request + * + * @param request the Get User request + * @return the response from the Get User request + */ + Mono get(GetUserRequest request); + + /** + * Makes the List all Users request + * + * @param request the List Users request + * @return the response from the List Users request + */ + Mono list(ListUsersRequest request); + + /** + * Makes the Update a Stack request + * + * @param request the Update User request + * @return the response from the Update User request + */ + Mono update(UpdateUserRequest request); + + /** + * Makes the Delete a User request + * + * @param request the Delete User request + * @return void + */ + Mono delete(DeleteUserRequest request); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_CreateUserRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_CreateUserRequest.java new file mode 100644 index 0000000000..5f6441cbbd --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_CreateUserRequest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.cloudfoundry.client.v3.users; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v3.Metadata; +import org.immutables.value.Value; + +/** + * The request payload for the Create User operation + */ +@JsonSerialize +@Value.Immutable +abstract class _CreateUserRequest { + + /** + * Unique identifier for the user. For UAA users this will match the UAA user ID; in the case of UAA clients, this will match the UAA client ID + */ + @JsonProperty("guid") + abstract String getUserId(); + + /** + * Username of the user to be created. This can only be provided together with origin. + */ + @JsonProperty("username") + @Nullable + abstract String getUsername(); + + /** + * Origin of the user to be created. This can only be provided together with username and cannot be uaa. + */ + @JsonProperty("origin") + @Nullable + abstract String getOrigin(); + + /** + * The metadata Labels and Annotations applied to the user + */ + @JsonProperty("metadata") + @Nullable + abstract Metadata getMetadata(); +} \ No newline at end of file diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_CreateUserResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_CreateUserResponse.java new file mode 100644 index 0000000000..b1bdd0715d --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_CreateUserResponse.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.cloudfoundry.client.v3.users; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Create User operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _CreateUserResponse extends User { +} \ No newline at end of file diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_DeleteUserRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_DeleteUserRequest.java new file mode 100644 index 0000000000..5010b8193a --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_DeleteUserRequest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Delete User operation + * All roles associated with a user will be deleted if the user is deleted. + */ +@Value.Immutable +abstract class _DeleteUserRequest { + + /** + * The User id / guid + */ + @JsonIgnore + abstract String getUserId(); + +} \ No newline at end of file diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_GetUserRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_GetUserRequest.java new file mode 100644 index 0000000000..1f2d070586 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_GetUserRequest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Get User operation + */ +@Value.Immutable +abstract class _GetUserRequest { + + /** + * The User id / guid + */ + @JsonIgnore + abstract String getUserId(); +} \ No newline at end of file diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_GetUserResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_GetUserResponse.java new file mode 100644 index 0000000000..76adda2fc0 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_GetUserResponse.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Get User operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _GetUserResponse extends User { +} \ No newline at end of file diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_ListUsersRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_ListUsersRequest.java new file mode 100644 index 0000000000..c8606ab59c --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_ListUsersRequest.java @@ -0,0 +1,49 @@ + + +package org.cloudfoundry.client.v3.users; + +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v3.FilterParameter; +import org.cloudfoundry.client.v3.PaginatedRequest; +import org.immutables.value.Value; + +import java.util.List; + +/** + * The request payload for the List Users operation. + */ +@Value.Immutable +abstract class _ListUsersRequest extends PaginatedRequest { + + /** + * Comma-delimited list of user guids to filter by + */ + @FilterParameter("guids") + @Nullable + abstract List getGuids(); + + /** + * Comma-delimited list of usernames to filter by. Mutually exclusive with partial_usernames + */ + @FilterParameter("usernames") + abstract List getUsernames(); + + /** + * Comma-delimited list of strings to search by. When using this query parameter, all the users that contain the string provided in their username will be returned. Mutually exclusive with usernames + */ + @FilterParameter("partial_usernames") + abstract List getPartialUsernames(); + + /** + * Comma-delimited list of user origins (user stores) to filter by, for example, users authenticated by UAA have the origin “uaa”; users authenticated by an LDAP provider have the origin “ldap”; when filtering by origins, usernames must be included + */ + @FilterParameter("origins") + abstract List getOrigins(); + + /** + * A query string containing a list of label selector requirements + */ + @FilterParameter("label_selector") + @Nullable + abstract String getLabelSelector(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_ListUsersResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_ListUsersResponse.java new file mode 100644 index 0000000000..1cf5a2e87e --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_ListUsersResponse.java @@ -0,0 +1,16 @@ +package org.cloudfoundry.client.v3.users; + + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.client.v3.PaginatedResponse; +import org.cloudfoundry.client.v3.users.UserResource; +import org.immutables.value.Value; + +/** + * The response payload for the List Users operation. + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListUsersResponse extends PaginatedResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_UpdateUserRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_UpdateUserRequest.java new file mode 100644 index 0000000000..6258711533 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_UpdateUserRequest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v3.Metadata; +import org.immutables.value.Value; + +/** + * The request payload for the Update User operation + */ +@JsonSerialize +@Value.Immutable +abstract class _UpdateUserRequest { + + /** + * The User id / guid + */ + @JsonIgnore + abstract String getUserId(); + + /** + * The metadata Labels and Annotations applied to the user + */ + @JsonProperty("metadata") + @Nullable + abstract Metadata getMetadata(); + +} \ No newline at end of file diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_UpdateUserResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_UpdateUserResponse.java new file mode 100644 index 0000000000..b264d5bcb1 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_UpdateUserResponse.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Update User operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _UpdateUserResponse extends User { +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_UserResource.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_UserResource.java new file mode 100644 index 0000000000..65c08410c9 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/users/_UserResource.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The Resource response payload for the List User operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _UserResource extends User{ +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/CreateUserRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/CreateUserRequestTest.java new file mode 100644 index 0000000000..9dff18b7e3 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/CreateUserRequestTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +class CreateUserRequestTest { + @Test + void noUserId() { + assertThrows(IllegalStateException.class, () -> CreateUserRequest.builder().build()); + } + + @Test + void valid() { + CreateUserRequest.builder().userId("test-user-id").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/DeleteUserRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/DeleteUserRequestTest.java new file mode 100644 index 0000000000..6d65354fb3 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/DeleteUserRequestTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class DeleteUserRequestTest { + + @Test + void noUserId() { + assertThrows(IllegalStateException.class, () -> DeleteUserRequest.builder().build()); + } + + @Test + void valid() { + DeleteUserRequest.builder().userId("test-stack-id").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/GetUserRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/GetUserRequestTest.java new file mode 100644 index 0000000000..83bb8541b9 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/GetUserRequestTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +class GetUserRequestTest { + + @Test + void noUserId() { + assertThrows(IllegalStateException.class, () -> GetUserRequest.builder().build()); + } + + @Test + void valid() { + GetUserRequest.builder().userId("test-user-id").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/ListUsersRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/ListUsersRequestTest.java new file mode 100644 index 0000000000..bf30fb14ff --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/ListUsersRequestTest.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import org.junit.jupiter.api.Test; + +public class ListUsersRequestTest { + + @Test + void valid() { + ListUsersRequest.builder().build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/UpdateUserRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/UpdateUserRequestTest.java new file mode 100644 index 0000000000..8a1c131cda --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/users/UpdateUserRequestTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.users; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +final class UpdateUserRequestTest { + + @Test + void noOrganizationQuotaId() { + assertThrows(IllegalStateException.class, () -> UpdateUserRequest.builder().build()); + } + + @Test + void valid() { + UpdateUserRequest.builder().userId("test-id").build(); + } +} diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/UsersTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/UsersTest.java new file mode 100644 index 0000000000..e3dbab91cb --- /dev/null +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/UsersTest.java @@ -0,0 +1,155 @@ +/* + * Copyright 2013-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; +import org.cloudfoundry.AbstractIntegrationTest; +import org.cloudfoundry.CloudFoundryVersion; +import org.cloudfoundry.IfCloudFoundryVersion; +import org.cloudfoundry.client.CloudFoundryClient; +import org.cloudfoundry.client.v3.users.*; +import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +@IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_4_v3) +public final class UsersTest extends AbstractIntegrationTest { + + @Autowired private CloudFoundryClient cloudFoundryClient; + + @Test + public void create() { + String userId = this.nameFactory.getUserId(); + + this.cloudFoundryClient + .usersV3() + .create(CreateUserRequest.builder().userId(userId).build()) + .single() + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void get() { + String userId = this.nameFactory.getUserId(); + + createUser(this.cloudFoundryClient, userId) + .flatMap( + createUserResponse -> + this.cloudFoundryClient + .usersV3() + .get(GetUserRequest.builder().userId(userId).build())) + .map(GetUserResponse::getId) + .as(StepVerifier::create) + .expectNext(userId) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void list() { + String userId = this.nameFactory.getUserId(); + createUser(this.cloudFoundryClient, userId) + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .usersV3() + .list( + ListUsersRequest.builder() + .page(page) + .build()))) + .filter(resource -> userId.equals(resource.getId())) + .map(UserResource::getId) + .as(StepVerifier::create) + .expectNext(userId) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void update() { + String userId = this.nameFactory.getUserId(); + + createUser(this.cloudFoundryClient, userId) + .flatMap( + createUserResponse -> + this.cloudFoundryClient + .usersV3() + .update( + UpdateUserRequest.builder() + .userId(userId) + .metadata( + Metadata.builder() + .annotation( + "annotationKey", + "annotationValue") + .label( + "labelKey", + "labelValue") + .build()) + .build())) + .then(getUser(cloudFoundryClient, userId)) + .as(StepVerifier::create) + .consumeNextWith( + GetUserResponse -> { + Metadata metadata = GetUserResponse.getMetadata(); + assertThat(metadata.getAnnotations().get("annotationKey")) + .isEqualTo("annotationValue"); + assertThat(metadata.getLabels().get("labelKey")) + .isEqualTo("labelValue"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void delete() { + String userId = this.nameFactory.getUserId(); + + createUser(this.cloudFoundryClient, userId) + .flatMap( + createUserResponse -> + this.cloudFoundryClient + .usersV3() + .delete( + DeleteUserRequest.builder() + .userId(createUserResponse.getId()) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono createUser( + CloudFoundryClient cloudFoundryClient, String userId) { + return cloudFoundryClient + .usersV3() + .create(CreateUserRequest.builder().userId(userId).build()); + } + + private static Mono getUser( + CloudFoundryClient cloudFoundryClient, String userId) { + return cloudFoundryClient.usersV3().get(GetUserRequest.builder().userId(userId).build()); + } +}