I'm trying to customise the response for authentication failures in Quarkus. I need to set a custom header, a custom response code and a custom response body. I developed my custom (Kotlin) HttpAuthenticationMechanism because I need a custom authentication logic. In it, I tried returning a failure Uni.
return Uni.createFrom().failure(AuthenticationFailedException())
And then implement my own ExceptionMapper
@Provider
@Priority(Priorities.AUTHENTICATION)
class AuthenticationFailedExceptionMapper : ExceptionMapper<AuthenticationFailedException> {
override fun toResponse(exception: AuthenticationFailedException): Response {
logger.info("====== custom auth error")
It doesn't get triggered. I have proactive authentication disabled:
quarkus.http.auth.proactive=false
Instead, I noticed that the getChallenge method in my custom HttpAuthenticationMechanism gets triggered, which can be used to overwrite the response, but it doesn't allow to set the body, just the result code and one header.
I also tried returning and mapping a different, custom exception, but then I only see some errors in the log and the client gets a 500 response code - the exception mapper is still not triggered. Why?