feat(audit): bridge identity login events onto the audit log#26
Merged
Conversation
Integration verification surfaced that /admin/api/v1/audit-logs was always empty even after dozens of logins — the audit infrastructure existed (publisher, async executor, query API, admin endpoint) but nothing fed it. Login events were published by identity-core but only consumed by the Micrometer metrics listener, never turned into audit rows. The admin UI's Audit Logs page therefore rendered an empty table no matter what happened. New LoginAuditBridge (autoconfigure): - @eventlistener for LoginSucceededEvent and LoginFailedEvent. - Re-publishes each as an AuditEvent via AuditEventPublisher, so it lands in platform_audit_log through the existing async pipeline. - Lives in autoconfigure because that's the only module that depends on both identity-api (the event types) and audit-api (the publisher) — identity-core deliberately doesn't know about audit. Mapping: - Both events → action code "identity.login"; SUCCESS vs FAILURE is carried by AuditOutcome (the column the Audit Logs page filters on), keeping the action filter clean. - Success: actor = (userId, tenantId, loginId), target = USER/<userId>. - Failure: userId is unknown (bad id / wrong password / locked), so actor = (null, tenantId, loginId), target = USER/<loginId>, and the failure reason rides in metadata {"reason": "..."}. - IP / user-agent left null — the identity events don't carry HTTP request context; a servlet-aware enrichment can fill them later without changing this bridge. Registered as a @bean in AuditAutoConfiguration (@ConditionalOnMissingBean), so it only activates when auditing is enabled and a publisher exists. Verified end-to-end against the running sample-app: 1 good login + wrong-password + unknown-user → audit-logs returns: identity.login SUCCESS actor=admin target=USER/<uuid> identity.login FAILURE actor=admin payload={"reason":"BAD_CREDENTIALS"} identity.login FAILURE actor=ghost payload={"reason":"UNKNOWN_USER"}
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Integration verification surfaced that
/admin/api/v1/audit-logswas always empty even after dozens of logins. The audit infrastructure all existed (publisher, async executor, query API, admin endpoint) but nothing fed it — login events were published byidentity-coreand consumed only by the Micrometer metrics listener, never turned into audit rows. The admin UI's Audit Logs page rendered an empty table no matter what happened.New
LoginAuditBridge(autoconfigure)@EventListenerforLoginSucceededEventandLoginFailedEvent.AuditEventviaAuditEventPublisher, so it lands inplatform_audit_logthrough the existing async pipeline.autoconfigurebecause that's the only module depending on bothidentity-api(the event types) andaudit-api(the publisher) —identity-coredeliberately doesn't know about audit.Mapping
identity.login; SUCCESS vs FAILURE carried byAuditOutcome(the column the Audit Logs page filters on), keeping the action filter clean.(userId, tenantId, loginId), target =USER/<userId>.(null, tenantId, loginId), target =USER/<loginId>, failure reason in metadata{"reason": "..."}.Registered as a
@BeaninAuditAutoConfiguration(@ConditionalOnMissingBean) — activates only when auditing is enabled and a publisher exists.Verified end-to-end against the running sample-app
1 good login + wrong-password + unknown-user →
Test plan
./gradlew :devslab-kit-sample-app:testgreen (full context boots with the bridge wired)Context
4th item from integration verification. Backend #25 fixed login-roles + tenant-id; admin-ui #11 fixed the menu id contract; this fills the empty audit log. Together they make the full stack actually exercisable end-to-end.