Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
2.21.1
-
None
-
Unknown
-
Description
Steps to reproduce
- Let a user get two OAuth2 tokens (XWiki.OAuth2.TokenClass objects) for two client configurations.
- Delete the first one with OAuth2TokenStore#deleteToken (e.g. an extension disconnecting the user from a service).
- Log in as that user, with the login form or with basic authentication (e.g. a REST call).
Expected
No error, and the remaining tokens of the user are renewed.
Actual
Each login logs the following error, and the remaining tokens of the user are not renewed on login:
ERROR .o.i.DefaultObservationManager - Failed to send event [org.xwiki.security.authentication.UserAuthenticatedEvent@318a1358] to listener [org.xwiki.contrib.oidc.internal.TokenRenewalOnAuthenticationEventListener@f2485d6] java.lang.NullPointerException: Cannot invoke "com.xpn.xwiki.objects.BaseObject.getStringValue(String)" because "object" is null at org.xwiki.contrib.oidc.internal.AbstractNimbusOAuth2TokenStore.getTokens(AbstractNimbusOAuth2TokenStore.java:240) at org.xwiki.contrib.oidc.internal.TokenRenewalOnAuthenticationEventListener.onEvent(TokenRenewalOnAuthenticationEventListener.java:86) at org.xwiki.observation.internal.DefaultObservationManager.notify(DefaultObservationManager.java:343) ... at com.xpn.xwiki.user.impl.xwiki.MyBasicAuthenticator.checkLogin(MyBasicAuthenticator.java:139)
Cause
deleteToken removes the token object with XWikiDocument#removeXObject, which leaves a null entry in the list returned by getXObjects. AbstractNimbusOAuth2TokenStore#getTokens iterates over that list without skipping the null entries. The code is unchanged in 2.30.0.
Found with the OpenProject integration of XWiki SAS, which deletes the token of a user who disconnects from an OpenProject connection, on XWiki 18.8.0.