SecurityExceptionMapper.java

  1. package org.oxerr.commons.ws.rs.exceptionmapper;

  2. import javax.inject.Singleton;
  3. import javax.ws.rs.core.Response;
  4. import javax.ws.rs.ext.ExceptionMapper;
  5. import javax.ws.rs.ext.Provider;

  6. /**
  7.  * Maps {@link SecurityException} to {@link Response}.
  8.  */
  9. @Provider
  10. @Singleton
  11. public class SecurityExceptionMapper
  12.     implements ExceptionMapper<SecurityException> {

  13.     /**
  14.      * {@inheritDoc}
  15.      */
  16.     @Override
  17.     public Response toResponse(SecurityException exception) {
  18.         return Response.status(Response.Status.UNAUTHORIZED)
  19.             .entity(new ErrorEntity(null, exception.getMessage()))
  20.             .build();
  21.     }

  22. }