This issue has been created
 
 
OpenId Connect / cid:jira-generated-image-avatar-7dde74f0-9cbd-42aa-86eb-31075c7ee6be OIDC-332 Open

Each login logs a NullPointerException from TokenRenewalOnAuthenticationEventListener after one of the user's OAuth2 tokens was deleted

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-52b500fa-fc99-4955-9550-25a4e79b4bda Vincent Massol created this issue on 09/Nov/26 19:54
 
Summary: Each login logs a NullPointerException from TokenRenewalOnAuthenticationEventListener after one of the user's OAuth2 tokens was deleted
Issue Type: cid:jira-generated-image-avatar-7dde74f0-9cbd-42aa-86eb-31075c7ee6be Bug
Affects Versions: 2.21.1
Assignee: Unassigned
Components: OAuth2
Created: 09/Nov/26 19:54
Priority: cid:jira-generated-image-static-major-6f1cdfe3-b1a2-47b9-8142-aa00e53d4959 Major
Reporter: Vincent Massol
Description:

Steps to reproduce

  1. Let a user get two OAuth2 tokens (XWiki.OAuth2.TokenClass objects) for two client configurations.
  2. Delete the first one with OAuth2TokenStore#deleteToken (e.g. an extension disconnecting the user from a service).
  3. 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.