Skip to content

[BACK-4441] Add 2FA cleanup event listeners (recovery codes + trusted devices)#50

Open
toddkazakov wants to merge 2 commits into
tk-stack-3-aia-authenticatorfrom
tk-stack-4-2fa-cleanup-listeners
Open

[BACK-4441] Add 2FA cleanup event listeners (recovery codes + trusted devices)#50
toddkazakov wants to merge 2 commits into
tk-stack-3-aia-authenticatorfrom
tk-stack-4-2fa-cleanup-listeners

Conversation

@toddkazakov

Copy link
Copy Markdown
Collaborator

Two event listeners with unit tests: delete recovery codes when the last OTP is removed, and remove trusted devices when the password changes.


📚 Stacked PR 4 of 8. Base branch: tk-stack-3-aia-authenticator — review/merge it first.

Stack — review & merge bottom-up:

  1. tk-stack-1-trusted-device-spimaster
  2. tk-stack-2-attempted-username-fixtk-stack-1-trusted-device-spi
  3. tk-stack-3-aia-authenticatortk-stack-2-attempted-username-fix
  4. tk-stack-4-2fa-cleanup-listenerstk-stack-3-aia-authenticator
  5. tk-stack-5-login-activity-outboxtk-stack-4-2fa-cleanup-listeners
  6. tk-stack-6-email-changed-notificationtk-stack-5-login-activity-outbox
  7. tk-stack-7-cancelable-email-changetk-stack-6-email-changed-notification
  8. tk-stack-8-theme-redesigntk-stack-7-cancelable-email-change

Builds green on JDK 21 (./mvnw clean compile package); on the stack tip 42 admin + 35 home-idp tests pass.

When a user removes their final OTP device via self-service, Keycloak
fires REMOVE_TOTP after the credential is already deleted. This global
event listener reacts by removing the user's recovery (authn) codes,
which Tidepool issues only as an OTP backup, so they are not left as an
unusable standalone second factor.

Runs for all realms (isGlobal); no per-realm eventsListeners config
needed. Adds JUnit5/Mockito/AssertJ test setup to the admin module.

(cherry picked from commit d840eb8)
When a user sets a new password via self-service or completes a
forgot-password reset, Keycloak fires UPDATE_PASSWORD. This global event
listener reacts by deleting every 'trusted-device' credential for the
user, so trust established under the old password cannot be reused.

Admin-initiated password resets emit only an admin event and are out of
scope, matching the recovery-codes cleanup listener.

(cherry picked from commit e7124ea)
@toddkazakov toddkazakov changed the title Add 2FA cleanup event listeners (recovery codes + trusted devices) [BACK-4441] Add 2FA cleanup event listeners (recovery codes + trusted devices) Jul 22, 2026
@toddkazakov
toddkazakov requested a review from lostlevels July 22, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant