Repository navigation
fix(authserver): one admin client API at /admin/oauth2/clients; locked updates and token revocation; client create on every database (#344) - #359
Conversation
…es and token revocation lock the client; client create works on every database (#344) #344 part 3a (owner design, 2026-11-30): - OAuth2ClientManagementController moves from /api/v1/oauth2/clients to /admin/oauth2/clients and takes OAuthAdminController's client delete and token revocation. The token and authorization lists that answered with hard-coded sample data are removed (D1); DELETE /admin/oauth2/tokens/{id} stays and no longer echoes the token. - #348: an update locks the client row and applies the change to the client read after the lock, in one transaction (ClientAdminService), so a client deleted meanwhile is 404 instead of re-inserted by save. - #349: DELETE /admin/oauth2/clients/{clientId}/tokens deletes the client's authorizations under the same lock, audits the count and answers 404 for an unknown client, instead of reporting a revocation it never made. - #351: create wrote espi_application_info columns only PostgreSQL has, and enum columns as text, so it failed on every database after saving the client. It now writes columns all three have, in one transaction with the client; PostgreSQL enum parameters are cast (EnumParameters, generalising #345's statusParameterFor); H2 V13 adds the columns; PostgreSQL V13 gives espi_application_info.uuid a default. The list's securityLevel filter takes only standard/high/maximum. - #353: max-failures-before-lock and default-lock-duration-minutes are removed, and failure_count is no longer reported. - Create -> suspend -> reactivate -> update -> revoke tokens -> delete is tested end to end on MySQL and PostgreSQL, and the writes on H2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…renames and updates are recorded (#344 review) Round 1 of the PR #359 review: - #1: on MySQL's REPEATABLE READ the update's first plain read fixed the snapshot, so the re-read after FOR UPDATE returned the client as it was before another administrator's committed change, which the update then overwrote. The lock (SELECT id ... WHERE client_id = ? FOR UPDATE) is now the transaction's first statement, for the update and the token revocation. A MySQL test holds the lock in another transaction, commits a change while the update waits, and checks the change is kept; it fails with the old order. - #4: a rename is recorded in espi_application_info.client_name too. - #5: an update is audited (client_updated) under the signed-in administrator, with the names of the fields it set. - #2, #3: openapi.yaml's client_description maxLength is 500; the docs that named /api/v1/oauth2/clients, or the removed token and authorization lists, name the new paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o the two cannot deadlock (#344 review) Round 2 of the PR #359 review: - #1: round 1 made the update and token revocation lock by client_id (MySQL: the client_id index record, then the row), while the delete still locked the row by id and then needed the index record, so a delete and an update of the same client could deadlock. deleteById(id) becomes deleteByClientId(clientId), which locks by client_id first; every writer now takes the locks in one order. A MySQL test shows an update waiting on a delete in progress finds the client gone. - #2: every update writes the client's name to espi_application_info, so a name that differed before is repaired too. - #3: the deleteAuthorizations Javadoc links lockByClientId. - #4: update and revokeTokens run in a transaction of their own (REQUIRES_NEW), so the lock is always its first statement. - #6: the application-info name Javadoc says the seeded default clients' names are reset at startup in oauth2_registered_client only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Round 2 ( This stays as it is, on purpose. An audit insert inside the transaction would let a failed audit write roll back the update on PostgreSQL, where any error aborts the transaction even when it is caught ( 🤖 Generated with Claude Code |
…t_id; Javadoc links name deleteByClientId (#344 review) Round 3 of the PR #359 review: - #1: the MySQL delete/update test is named for what it checks (an update waiting on a delete finds the client gone), not a deadlock it cannot reproduce; the lock order is checked by RegisteredClientAdminDaoTest. - #3: two Javadoc links still named the removed deleteById. - #4: the controller's delete tests lock only the path's client_id and verify the lock, and lose their unused stubs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Round 3 ( This stays as it is. No caller runs them inside a transaction: the controller is not transactional. Holding a client's lock and then calling the service that takes that lock would be a misuse in any design. 🤖 Generated with Claude Code |
#344 part 3a, per the owner's design of 2026-11-30 (decision). Part 3b follows with the shared registration validator (D2), the #343 docs and #355.
Closes #348
Closes #349
Closes #351
Closes #353
Refs #344 (stays open for part 3b)
One admin client API at
/admin/oauth2/clientsGET /admin/oauth2/clients/api/v1/oauth2/clients); replacesOAuthAdminController's list, which answered with mock clients on failurePOST /admin/oauth2/clientsGET /admin/oauth2/clients/{clientId}PUT /admin/oauth2/clients/{clientId}savePUT /admin/oauth2/clients/{clientId}/statusDELETE /admin/oauth2/clients/{clientId}OAuthAdminController; the response is now{"status","client_id","authorizations_deleted"}DELETE /admin/oauth2/clients/{clientId}/tokensclient_tokens_revoked) and returned, and an unknown client is 404/api/v1/oauth2/clientsis removed outright. Nothing called it and nothing is deployed. It is also gone fromADMIN_API_PATHSandADMIN_BEARER_API_PATHS, since/admin/**covers the new path.GET /admin/oauth2/tokensandGET /admin/oauth2/authorizationsreturned hard-coded sample data, so they are removed.DELETE /admin/oauth2/tokens/{tokenId}stays and no longer echoes the token value.#351: create failed on every database
The issue described PostgreSQL's enum columns and H2's missing columns. While moving the code I found that the create's
espi_application_infoINSERT also nameduuid,client_description,scopeandgrant_types, which only PostgreSQL has. So a create failed on MySQL and H2 too, after the client had already been saved. No test caught it because the controller test mocks the database.ClientAdminService.createsaves the client, its application info and its ESPI columns in one transaction, so a failed write keeps nothing.client_descriptiongoes tothird_party_application_description(varchar(500)on MySQL and H2), so its limit is now 500 characters instead of 1000.scopeandgrant_typesduplicated the client's own.EnumParameterscasts the text to the enum type on PostgreSQL. It generalises AS: suspending or revoking a client has no effect: client_status is never checked at the token, authorization or introspection endpoints #345'sstatusParameterForand coversclient_status,security_level,security_classificationandcertification_status, in create, update, the status change and the list'ssecurityLevelfilter.espi_application_info.uuida default (gen_random_uuid()), since only PostgreSQL has that NOT NULL column.securityLevelfilter takes onlystandard,highormaximum, as thestatusfilter does. Anything else, including a blank value, is 400. A test checks the list against the requests'@Pattern.The SQL for these writes moved from the controller to
RegisteredClientAdminDao.#353
max-failures-before-lockanddefault-lock-duration-minutesare removed fromOAuth2ClientManagementConfig, the docker profile and the docs, andfailure_countis no longer reported. There is no failure lockout; if one is wanted, it is a new issue (D3).Tests
End to end on MySQL and PostgreSQL (
ClientAdminScenarios, run by bothClientSuspension*IntegrationTests):Also on both databases: an update, status change or token revocation of a deleted client is 404 and brings nothing back.
H2 (
ClientAdminH2Test, the real H2 migrations):Controller (
OAuth2ClientManagementControllerTest, now with the real service and DAO over a mocked database):securityLevelfilter: the 400s, PostgreSQL's cast, and the list matching the@Pattern.Unit:
EnumParametersTest, the DAO's SQL per database, andOAuthAdminControllerTestreduced to token revocation (the D1 lists are gone).Security:
AdminEndpointAuthorizationIntegrationTestcovers the new paths (customer 403, anonymous 401 or login, ADMIN and DC_ADMIN allowed, password-only admin sent to the passkey step) and method security on both controllers.Full AS suite: 654 tests, 0 failures (WSL, Docker).
Review findings
Round 1,
/code-review high(the whole PR):FOR UPDATEreturned the client as it was before another administrator's committed change. The update then overwrote that change: the lost update #348 was meant to preventSELECT id … WHERE client_id = ? FOR UPDATE) is now the transaction's first statement, for the update and the token revocation. A MySQL test holds the lock in another transaction and commits a change while the update waits; it fails with the old order and passes nowopenapi.yamlgaveclient_descriptionmaxLength: 1000after this PR lowered it to 500, and lacks the two DELETE operations/api/v1/oauth2/clientsDEPLOYMENT_GUIDE,QUICK_START,API_DOCUMENTATION,INTEGRATION_GUIDE,ESPI_COMPLIANCE_GUIDE,docs/READMEand the ASREADME(which also listed the removed token and authorization lists). The rest of their content stays with #343 in part 3bespi_application_info.client_nameunchangedclient_updated, under the signed-in administrator, with the names of the fields setDELETE /admin/oauth2/tokens/{tokenId}puts the access token in the URL, where access logs keep itRound 1 found a real bug in this PR, so round 2 goes up a level to
xhigh, scoped to 3403180.Round 2,
/code-review xhigh(scoped to 3403180):client_id(the index record, then the row), but the delete locked the row byidfirst and then needed the index record. A delete and an update of the same client could therefore deadlock, and one of them would answer 500deleteById(id)becamedeleteByClientId(clientId), which locks byclient_idfirst, so every writer takes the locks in one order. A MySQL test shows that an update waiting on a delete in progress finds the client gone (404), with no deadlockespi_application_infodeleteAuthorizations' Javadoc linked the removedlockByIdupdateandrevokeTokensareREQUIRES_NEWclient_updatedaudit row is written after the commit, so two updates can be audited out of orderoauth2_registered_clientonlyRound 2 also found a real bug in this PR. Under CLAUDE.md, going up from
xhighmeansultra, and the owner chose to stay atxhighfor round 3, scoped to 08069d0. If round 3 still finds a real bug, the automated reviews stop and the owner reviews the design.Full AS suite after the round-2 fixes: 661 tests, 0 failures.
Round 3,
/code-review xhigh(scoped to 08069d0). No real bug. The reviewer confirmed that update, token revocation and delete now take the client's locks in one order, so none of them can deadlock with another.RegisteredClientAdminDaoTestREQUIRES_NEWwould wait on itself under a caller already holding the client's lock in its own transactionREQUIRES_NEWguarantees the lock is the transaction's first statementdeleteByIdRound 3 found no real bug, so round 4 steps down to
high, scoped to 6dabe62 (tests and Javadoc only).Full AS suite after the round-3 fixes: 661 tests, 0 failures.
Round 4,
/code-review high(scoped to 6dabe62): no findings. No furthersrc/change, so the review cycle is complete.Not in this PR
Part 3b:
/oauth2/register;API_DOCUMENTATION.md,INTEGRATION_GUIDE.md,README.md,QUICK_START.mdandDEPLOYMENT_GUIDE.mdstill name/api/v1/oauth2/clients, among their other stale content;OAUTH2_CLIENT_MANAGEMENT_API.mdand theopenapi.yamlpath keys are updated here, becauseClientManagementOpenApiTestreads them.fix(authserver): prod and dev-mysql Flyway targets skip MySQL V7, V9 and V11 #352: the
prodanddev-mysqlFlyway caps (MySQL needs no migration for this PR).🤖 Generated with Claude Code