Logging of the Authentication mechanism in PAYARA

Hi everyone,
im using Payara Server 5.2020.4 and i want to log the Authentication mecanisme from Payara.
im Using JWT and REST. i want to log the user and his Role when the Authentication failed.
how can i do this?

From top of my head (and copying from more general handler), I suppose you could add an ExceptionMapper for ForbiddenException:

public class AuthFailedHandler implements ExceptionMapper<ForbiddenException> {

    @Context
    HttpServletRequest request;

    @Override
    public Response toResponse(ForbiddenException exception) {
       // check request principal here
      return exception.getResponse();
    }
}

You can check the caller principal and check his roles from the request. Don’t forget to include it in your application by including it in Set of Application's classes or annoating it @Provider.