BUG- [AEM 6.5 SP26] Regression: Granite OAuth 2.0 token generation fails with IllegalArgumentException on :externalId attribute
Hi,
I would like to raise a bug found while upgrading to AEM SP26.
Product & Version Information
AEM Version:
AEM 6.5.26.0 (Service Pack 26)
Affected Bundles:
org.apache.jackrabbit.oak-core (Version: 1.22.25)
com.adobe.granite.auth.oauth (Version: 1.10.60)
Java Version: Java 11
Summary
In AEM 6.5.26.0 (SP26), authentication via Granite OAuth (com.adobe.granite.auth.oauth) fails to issue a JCR login-token cookie. During token creation in Oak (oak-core 1.22.25), TokenProviderImpl.createTokenNode() attempts to persist all credentials attributes returned by OAuthIdentityProvider directly as JCR properties on the rep:Token node. Because OAuthIdentityProvider.getAttributes() includes internal metadata with the reserved prefix :externalId, Oak's AbstractMutableTree.setProperty() rejects the property name and throws:java.lang.IllegalArgumentException: Invalid property name :externalId (or NullPointerException if the value is null). Consequently, token creation fails silently inside JAAS commit, OAuthCredentials.getAttribute(".token") remains null, and OAuthAuthenticationHandler.updateCookie() never emits the Set-Cookie: login-token header to the browser.
Root Cause & Code Flow
1. OAuthIdentityProvider exposes internal :externalId in CredentialsSupport:
com.adobe.granite.auth.oauth.impl.OAuthIdentityProvider implements Oak's CredentialsSupport interface. When getAttributes(Credentials credentials) is called, it returns:
// com.adobe.granite.auth.oauth.impl.OAuthIdentityProvider.java
Map<String, Object> map = new HashMap<>();
map.put(".token", "");
map.put("oauth.provider.id", credentials.getAttribute("oauth.provider.id"));
map.put(":externalId", credentials.getAttribute(":externalId"));
return map;
2. Oak attempts to persist all attributes as JCR node properties:
In Oak 1.22.25, TokenProviderImpl.createTokenNode() iterates over every attribute in the map and calls setProperty() on the token node:
// org.apache.jackrabbit.oak.security.authentication.token.TokenProviderImpl.java
attributes.forEach((name, value) -> {
tokenNode.setProperty(name, value); // <-- Unconditionally attempts to save ":externalId"
});
3. Oak tree validation fails on reserved prefix ::
org.apache.jackrabbit.oak.plugins.tree.impl.AbstractMutableTree.setProperty() strictly enforces standard JCR property naming and disallows property names starting with a colon (:)
// org.apache.jackrabbit.oak.plugins.tree.impl.AbstractMutableTree.java
Preconditions.checkArgument(!name.startsWith(":"));
If :externalId has a string value: Oak throws java.lang.IllegalArgumentException.
If :externalId is null: Oak throws java.lang.NullPointerException.
4. Failure to issue cookie:
The exception aborts token node creation. In AbstractOAuthAuthenticationHandler.updateCookie(), oauthCredentials.getAttribute(".token") is null, resulting in no login-token cookie being sent to the client:
// com.adobe.granite.auth.oauth.impl.AbstractOAuthAuthenticationHandler.java
Object token = oauthCredentials.getAttribute(".token");
if (token != null) {
TokenCookie.update(request, response, ...);
}
// Token is null, so update() is skipped.
Regards
Brijesh Yadav