Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,6 @@ public void invalidateAndCreateNewAccessToken(String oldAccessTokenId, String to
+ Arrays.toString(accessTokenDO.getScope()));
}
}
boolean tokenUpdateSuccessful;
Connection connection = IdentityDatabaseUtil.getDBConnection(true);
try {
if (OAuth2ServiceComponentHolder.isConsentedTokenColumnEnabled() && !accessTokenDO.isConsentedToken()) {
Expand All @@ -2149,15 +2148,14 @@ public void invalidateAndCreateNewAccessToken(String oldAccessTokenId, String to
oldTokenCleanupObject.cleanupTokenByTokenId(oldAccessTokenId, connection);
}
IdentityDatabaseUtil.commitTransaction(connection);
tokenUpdateSuccessful = true;
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
String errorMsg = "Error while regenerating access token";
throw new IdentityOAuth2Exception(errorMsg, e);
} finally {
IdentityDatabaseUtil.closeConnection(connection);
}
if (tokenUpdateSuccessful) {
if (isTokenCleanupFeatureEnabled) {
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition has changed from checking if the token update was successful to checking if cleanup is enabled. This could cause post-refresh events to fire even when the database transaction failed and was rolled back, leading to inconsistent state.

Copilot uses AI. Check for mistakes.

// Post refresh access token event
if (StringUtils.equals(grantType, OAuthConstants.GrantTypes.CLIENT_CREDENTIALS) ||
StringUtils.equals(grantType, OAuthConstants.GrantTypes.PASSWORD)) {
Expand Down