Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: add authorization check to User lookup endpoint in API #1035

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import com.walmartlabs.concord.server.sdk.metrics.WithTimer;
import com.walmartlabs.concord.server.sdk.rest.Resource;
import com.walmartlabs.concord.server.sdk.validation.ValidationErrorsException;
import com.walmartlabs.concord.server.security.Roles;
import com.walmartlabs.concord.server.security.UnauthorizedException;
import com.walmartlabs.concord.server.security.UserPrincipal;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

Expand Down Expand Up @@ -72,6 +75,15 @@ public List<UserEntry> list(@QueryParam("offset") @DefaultValue("0") int offset,
@WithTimer
@Operation(description = "Get an existing user", operationId = "getUser")
public UserEntry get(@PathParam("id") UUID id) {

UserPrincipal loggedIn = UserPrincipal.assertCurrent();

UUID authenticatedId = loggedIn.getId();

if(!authenticatedId.equals(id) && !Roles.isAdmin()) {
throw new UnauthorizedException("Users can only view their own information or must have admin privileges.");
}

return userDao.get(id);
}
}
Loading