Amazon Ergo 1.0 · Heavy
implement-access-token-context-encoding-framework-keycloak
Keycloak · Java · L · 300–799 lines · 6 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.
- Gold bugs found
- 4 of 5
- Comments published
- 10
- Comments matching a bug
- 4
- Comments not matching
- 6
- Cost of this PR
- $5.651
Published comments (10)
Abstract getShortcut() breaks third-party grant factories at startup — Third-party `OAuth2GrantTypeFactory` implementations compiled against the previous SPI fail at startup with `AbstractMethodError` when `DefaultTokenContextEncoderProviderFactory.postInit()` calls `getShortcut()`. Make `getShortcut()` a default method returning `getId()` to preserve compatibility.
GRANT_TYPE unset for client-credentials and token-exchange grants — Client-credentials and legacy/V1 token-exchange access tokens encode `na` instead of `cc`/`te`, losing their grant context. Set `Constants.GRANT_TYPE` where `ClientCredentialsGrantType` and `AbstractTokenExchangeProvider` call `TokenManager.responseBuilder`, or derive it centrally during token creation.
testIncorrectGrantType accepts unrelated RuntimeException failures — Use `Assert.assertThrows` with `IllegalArgumentException.class` around `getTokenContextFromTokenId` so only the expected failure passes.
Null rawTokenId check validates grantType instead — The duplicated `grantType` check lets a null `rawTokenId` through, encoding it as `null` in the token ID or causing downstream failures. Change the second `Objects.requireNonNull` call to validate `rawTokenId`.
Grant shortcut is read from the wrong token ID indices — `substring(3, 5)` reads `ta` from `onrtac:...` instead of the grant shortcut `ac`, so assertions would still fail after fixing the inverted condition. Use `substring(4, 6)` for the two-character shortcut at indices 4-5.
Access-token matcher reads the grant shortcut at the wrong offset — `substring(3, 5)` extracts the last token-type character plus the first grant character, so `isAccessTokenId` never compares the expected two-character grant shortcut. Update the comment and use `substring(4, 6)` to match `DefaultTokenContextEncoderProvider.encodeTokenId`.
Access token grant shortcut is read from the wrong offset — `substring(3, 5)` reads one token-type character and one grant character, yielding `ta` instead of `ac` for `onrtac:<uuid>`. Use `substring(4, 6)` with a length check so malformed IDs return false instead of risking an out-of-bounds exception.
Grant shortcut check uses wrong offset and inverted match — `substring(3, 5)` captures one token-type character and one grant character, so the comparison can never match a two-character shortcut such as `ac`, even after fixing the inverted condition. Read indices 4-5 with `substring(4, 6)`, matching `DefaultTokenContextEncoderProvider.encodeTokenId`.
Access token matcher misreads and inverts the grant shortcut check — The expected grant shortcut is never actually compared, so `isAccessTokenId` silently accepts any grant whose raw ID is a UUID. Read it with `substring(4, 6)` and negate the `expectedGrantShortcut` comparison so mismatches return false, matching `DefaultTokenContextEncoderProvider.encodeTokenId`.
isAccessTokenId rejects matching grant shortcuts — `isAccessTokenId` accepts any token with a UUID raw ID regardless of grant, disabling grant verification for its callers. Negate the `expectedGrantShortcut` comparison so a mismatch, not a match, returns false.