Implement access token context encoding framework#3
Conversation
closes #37118 Signed-off-by: mposolda <mposolda@gmail.com>
Codoki PR ReviewSummary: Introduce grant shortcuts, tag token exchange Issues (Critical & High only)
Showing top 2 issues. Critical: 0, High: 2. See inline suggestions for more. Key Feedback (click to expand)
Confidence: 3/5 — Needs work before merge (2 high · status: Requires changes · scope: large PR (28 files)) React with 👍 or 👎 if you found this review useful. |
| Objects.requireNonNull(sessionType, "Null sessionType not allowed"); | ||
| Objects.requireNonNull(tokenType, "Null tokenType not allowed"); | ||
| Objects.requireNonNull(grantType, "Null grantType not allowed"); | ||
| Objects.requireNonNull(grantType, "Null rawTokenId not allowed"); |
There was a problem hiding this comment.
| Objects.requireNonNull(grantType, "Null rawTokenId not allowed"); | |
| ```java | |
| Objects.requireNonNull(rawTokenId, "Null rawTokenId not allowed"); |
| @@ -1045,7 +1048,11 @@ protected IDToken applyMapper(IDToken token, Map.Entry<ProtocolMapperModel, Prot | |||
| protected AccessToken initToken(KeycloakSession session, RealmModel realm, ClientModel client, UserModel user, UserSessionModel userSession, | |||
| ClientSessionContext clientSessionCtx, UriInfo uriInfo) { | |||
| AccessToken token = new AccessToken(); | |||
There was a problem hiding this comment.
🔷 Medium: Possible NPE if the provider is not registered; this would break token issuance. Consider a defensive fallback to the original UUID-only ID to preserve runtime behavior if the provider is unavailable.
java
TokenContextEncoderProvider encoder = session.getProvider(TokenContextEncoderProvider.class);
if (encoder == null) {
token.id(KeycloakModelUtils.generateId());
} else {
AccessTokenContext tokenCtx = encoder.getTokenContextFromClientSessionContext(clientSessionCtx, KeycloakModelUtils.generateId());
token.id(encoder.encodeTokenId(tokenCtx));
}
| } | ||
| grantShortcut = grantsToShortcuts.get(grantType); | ||
| } | ||
| return grantShortcut; |
There was a problem hiding this comment.
🔷 Medium: Returning null here propagates an absent shortcut to callers and risks NPEs or malformed token context encoding when an unknown or newly registered grant type is encountered; prefer a stable UNKNOWN fallback.
| }); | ||
| grantType = grantsByShortcuts.get(shortcut); | ||
| } | ||
| return grantType; |
There was a problem hiding this comment.
🔷 Medium: Symmetric to getShortcutByGrantType, returning null for an unknown shortcut can lead to NPEs or inconsistent encoding; use the UNKNOWN sentinel for stability.
| */ | ||
| public class DefaultTokenContextEncoderProviderFactory implements TokenContextEncoderProviderFactory { | ||
|
|
||
| private KeycloakSessionFactory sessionFactory; |
There was a problem hiding this comment.
🔷 Medium: sessionFactory is written in postInit and read in mapping methods potentially from other threads; without a visibility guarantee this can be observed as null, causing sporadic NPEs. Mark as volatile to ensure safe publication.
| private KeycloakSessionFactory sessionFactory; | |
| private volatile KeycloakSessionFactory sessionFactory; |
No description provided.