advancedAuthorization: Roles, Authorities (RBAC) & Custom Filters
Why doesn't an @EventListener for AuthorizationDeniedEvent fire even though the code compiles fine?
Unlike authentication events, which are published automatically, authorization event publishing must be explicitly opted into by exposing an AuthorizationEventPublisher bean (typically a SpringAuthorizationEventPublisher wrapping the ApplicationEventPublisher). Without this bean, authorization checks still work correctly, but no event is ever published, so any listener silently never fires — with no error to indicate why.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response