diff --git a/wsmaster/che-core-api-user/src/main/java/org/eclipse/che/api/user/server/UserService.java b/wsmaster/che-core-api-user/src/main/java/org/eclipse/che/api/user/server/UserService.java index a5efd1e094..7499dc819e 100644 --- a/wsmaster/che-core-api-user/src/main/java/org/eclipse/che/api/user/server/UserService.java +++ b/wsmaster/che-core-api-user/src/main/java/org/eclipse/che/api/user/server/UserService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2025 Red Hat, Inc. + * Copyright (c) 2012-2026 Red Hat, Inc. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -11,7 +11,9 @@ */ package org.eclipse.che.api.user.server; +import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN; +import static org.eclipse.che.dto.server.DtoFactory.newDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -21,6 +23,7 @@ import jakarta.ws.rs.Produces; import javax.inject.Inject; import org.eclipse.che.api.core.rest.Service; +import org.eclipse.che.api.user.shared.dto.UserDto; import org.eclipse.che.commons.env.EnvironmentContext; /** @@ -51,6 +54,20 @@ public String getId() { return userId(); } + @GET + @Produces(APPLICATION_JSON) + @Operation( + summary = "Get current user", + responses = { + @ApiResponse( + responseCode = "200", + description = "The response contains current user's object with name and email fields"), + }) + public UserDto getUser() { + String userName = EnvironmentContext.getCurrent().getSubject().getUserName(); + return newDto(UserDto.class).withName(userName).withEmail(userName + "@che"); + } + private static String userId() { return EnvironmentContext.getCurrent().getSubject().getUserId(); }