Skip to content

Enable credential reordering via Account REST - #51257

Open
jganczorz-revolve wants to merge 1 commit into
keycloak:mainfrom
jganczorz-revolve:issue-41160
Open

Enable credential reordering via Account REST#51257
jganczorz-revolve wants to merge 1 commit into
keycloak:mainfrom
jganczorz-revolve:issue-41160

Conversation

@jganczorz-revolve

Copy link
Copy Markdown

Summary

Enables users to reorder their own credentials via the Account REST API. Previously, changing credential priority (e.g. moving a passkey ahead of OTP) required an administrator to do it through the admin console or admin REST API, even for users who already hold manage-account. The endpoints existed but were commented out in AccountCredentialResource with a // TODO: This is kept here for now and commented. note, calling a UserCredentialManager API that no longer exists.

This uncomments and modernises them, mirroring the existing admin equivalents in UserResource.

Changes

  • AccountCredentialResource: added

    • POST /realms/{realm}/account/credentials/{credentialId}/moveToFirst
    • POST /realms/{realm}/account/credentials/{credentialId}/moveAfter/{newPreviousCredentialId}

    Both require manage-account (auth.require(AccountRoles.MANAGE_ACCOUNT), same as the sibling label/DELETE endpoints). Unlike the admin version, both the credential being moved and newPreviousCredentialId are validated up front and return 404 if unknown — the admin endpoint silently discards the move when the "previous" id doesn't exist, which would be a confusing no-op behind a 204 for a brand-new endpoint. No event is fired, consistent with the admin move endpoints and the account setLabel endpoint.

  • AccountRestServiceTest: added testMoveCredentials (reordering across three credentials, including a self-move no-op), testMoveCredentialWithUnknownPreviousCredential (404), testMoveCredentialRequiresManageAccount (403), and extended testCRUDCredentialOfDifferentUser with 404 checks for moving another user's credential.

Test plan

  • ./mvnw -pl tests/base test -Dtest=AccountRestServiceTest — 60/60 passing
  • ./mvnw -pl tests/base test -Dtest=AccountRestServiceLightweightTokenTest — 60/60 passing (lightweight-token variant)
  • ./mvnw -pl tests/base test -Dtest=UserCredentialTest (admin-side credential reordering) — 11/11 passing, no regressions
  • ./mvnw spotless:check -pl services,tests/base — clean

No OpenAPI/documentation changes: the Account REST API isn't part of the OpenAPI generation pipeline (scanProfiles=admin in services/pom.xml), and none of the existing account credential endpoints carry OpenAPI annotations either.

Closes #41160


This PR was implemented with the assistance of an AI coding agent (Claude Code), which drafted the endpoint implementation and tests from a prompt describing the issue. I have reviewed the change, understand it, and verified it against the existing admin implementation and the test suite.

Uncomment and modernize the moveToFirst/moveCredentialAfter endpoints
in AccountCredentialResource, mirroring the existing admin UserResource
endpoints, so users with manage-account can reorder their own
credentials without administrator involvement.

Closes keycloak#41160

Signed-off-by: Jakub Gańczorz <jakub.ganczorz@revolve.pro>
@jganczorz-revolve
jganczorz-revolve requested a review from a team as a code owner July 29, 2026 06:32
Copilot AI review requested due to automatic review settings July 29, 2026 06:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables users with manage-account to reorder their own credentials through Account REST.

Changes:

  • Adds credential reordering endpoints with authorization and ownership validation.
  • Adds tests for ordering, invalid credentials, authorization, and cross-user access.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
services/.../AccountCredentialResource.java Implements Account REST credential reordering.
tests/.../AccountRestServiceTest.java Covers successful moves and failure scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User should be able to set priority of credentials via Account REST

2 participants