Unwanted Stacktrace in bad credentials (400) error response by spring-security oauth2 REST server Unwanted Stacktrace in bad credentials (400) error response by spring-security oauth2 REST server spring spring

Unwanted Stacktrace in bad credentials (400) error response by spring-security oauth2 REST server


You could write a ExceptionMapper for that specific Exception and do whatever you want with the request. The ExceptionMapper handles the Response whenever the defined exception is thrown from your endpoint methods.

import javax.ws.rs.core.Response;import javax.ws.rs.ext.ExceptionMapper;import javax.ws.rs.ext.Provider;@Providerpublic class MyExceptionMapper implements ExceptionMapper<InvalidGrantException>{    @Override    public Response toResponse(InvalidGrantException exception)    {        return Response.status(Response.Status.BAD_REQUEST).build();     }}

EDIT 18.11.2013:

I guess you could always you override the EntryPoint class (as seen in this StackOverflow Question).

An customized OAuth2ExceptionRenderer (see SO: Customize SpringSecurity OAuth2 Error Output would work too.