I'm using Crowd's Java integration into Spring Security which involves configuring Crowds SimpleAuthenticationManager as an authentication provider. The SimpleAuthenticationManager throws several exceptions when a user fails to be authenticated based on why they could not be authenticated. I was wondering within Spring Security how I can capture that exception and return a JSON response to the client?
I've tried adding an AccessDeniedHandler however this receives a new exception which does not have the original exception as a cause.
You can extends
ResponseEntityExceptionHandlerwith the@ControllerAdviceannotation. This will capture exception and you can handle and send a custom response. Example: