Repository navigation
Emit RISC account-purged SSF events on user deletion #51870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pedroigor
merged 24 commits into
keycloak:main
from
ssilvert:issue-48899-RiscAccountPurged
Sep 23, 2026
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4060403
Emit RISC account-purged SSF events on user deletion
ssilvert f676a5c
Resolve organizations live for purged users instead of copying their …
ssilvert 834922b
Gate purge snapshots on an active request instead of capping retention
ssilvert bf6202c
Bound purge snapshot retention for bulk deletions inside a request
ssilvert ae7816b
Publish UserPreRemovedEvent before federated pre-removal
ssilvert f79cd87
Preserve group and role memberships in the purge snapshot
ssilvert 54f811c
Resolve purge subjects from the snapshot rather than live-first
ssilvert 9d4d886
Scope purge snapshot session keys by realm
ssilvert 196c85c
Make purge snapshot cleanup best-effort
ssilvert f7d01cf
Set the duplicate-email policy at realm creation in the purge tests
ssilvert 4de20a9
Hold purge snapshots in one session-scoped set
ssilvert ddfe990
Match a purge snapshot only for subjects this transmitter issued
ssilvert b6460a4
Read organization membership as the system on the SSF emission path
ssilvert a3a873d
Suppress account-purged when the account outlives its local record
ssilvert 8afa3b6
Cover the self-service purge path through the event listener
ssilvert d931734
Treat an unknown federated deletion as not a purge
ssilvert 5dec229
Tidy the purge path: one membership query, blank emails, drop-path lo…
ssilvert 17db223
Resolve a purged user's organizations once per request
ssilvert cc56a5a
Resolve the purge realm the same way on both sides of the emission path
ssilvert 69fc364
Ask the organization question instead of handing out the list
ssilvert 90074c3
Fix import order and drop an unused test import
ssilvert 6371d57
Keep the purge snapshot indexes in step on replace
ssilvert be494ee
Refuse to emit account-purged without a pre-removal snapshot
ssilvert 51b3a12
Rename purgeRealm to resolveRealm
ssilvert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
ssf/core/src/main/java/org/keycloak/ssf/event/risc/RiscAccountPurged.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package org.keycloak.ssf.event.risc; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.keycloak.ssf.event.InitiatingEntity; | ||
| import org.keycloak.ssf.event.InitiatingEntityAware; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| /** | ||
| * The Account Purged event indicates that an account has been permanently deleted. | ||
| * | ||
| * <p>Unlike {@link RiscAccountDisabled}, RISC defines no {@code reason} claim for this | ||
| * event — a purge is terminal and carries no rationale enumeration. | ||
| * | ||
| * <p>Receivers use this to drive their own data-retention cleanup, so it is emitted only | ||
| * for a genuine purge. Keycloak has several code paths that delete a user row without the | ||
| * account ceasing to exist — most notably a partial import under the OVERWRITE policy, | ||
| * which deletes and immediately recreates the user — and those deliberately do not emit. | ||
| * | ||
| * <p><b>Known gap.</b> Emission is driven by the admin / user event that follows a | ||
| * deletion, so deletion paths that fire neither produce no event. The significant one is | ||
| * the workflow delete step ({@code DeleteUserStepProvider}): the workflow engine raises no | ||
| * Keycloak events at all, so scheduled data-retention deletions are currently silent — | ||
| * exactly the case receivers would most expect to hear about. Deleting an organization's | ||
| * managed members is silent for the same reason. Both are tracked separately from the | ||
| * initial account-purged support. | ||
| * | ||
| * See: https://openid.net/specs/openid-risc-1_0-final.html | ||
| */ | ||
| public class RiscAccountPurged extends RiscEvent implements InitiatingEntityAware { | ||
|
|
||
| public static final String TYPE = "https://schemas.openid.net/secevent/risc/event-type/account-purged"; | ||
|
|
||
| /** | ||
| * The time of the event (UNIX timestamp). RISC 1.0 lists no attributes for | ||
| * account-purged, so this is a CAEP-defined claim carried as an extension — | ||
| * declared here rather than on {@link RiscEvent} because RISC does not define | ||
| * it profile-wide. Nullable so an absent timestamp is omitted from the wire | ||
| * JSON rather than serialized as {@code "event_timestamp": 0}. | ||
| */ | ||
| @JsonProperty("event_timestamp") | ||
| protected Long eventTimestamp; | ||
|
|
||
| /** | ||
| * The entity that initiated the deletion — {@link InitiatingEntity#ADMIN} for a | ||
| * deletion through the admin API, {@link InitiatingEntity#USER} for self-service | ||
| * deletion from the account console. Unlike account-disabled, there is no policy | ||
| * -driven trigger to account for: Keycloak never purges an account on its own. | ||
| */ | ||
| @JsonProperty("initiating_entity") | ||
| protected InitiatingEntity initiatingEntity; | ||
|
|
||
| public RiscAccountPurged() { | ||
| super(TYPE); | ||
| } | ||
|
|
||
| public Long getEventTimestamp() { | ||
| return eventTimestamp; | ||
| } | ||
|
|
||
| public void setEventTimestamp(long eventTimestamp) { | ||
| this.eventTimestamp = eventTimestamp; | ||
| } | ||
|
|
||
| @Override | ||
| public InitiatingEntity getInitiatingEntity() { | ||
| return initiatingEntity; | ||
| } | ||
|
|
||
| @Override | ||
| public void setInitiatingEntity(InitiatingEntity initiatingEntity) { | ||
| this.initiatingEntity = initiatingEntity; | ||
| } | ||
|
|
||
| @Override | ||
| protected void appendFields(Map<String, Object> fields) { | ||
| super.appendFields(fields); | ||
| fields.put("eventTimestamp", eventTimestamp); | ||
| fields.put("initiatingEntity", initiatingEntity); | ||
|
ssilvert marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.