I want to customize the 401/403 status code when access token is invalid in headers. I have create an exception mapper given below :
import io.quarkus.security.AuthenticationFailedException;
import org.jose4j.json.internal.json_simple.JSONObject;
import javax.annotation.Priority;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@Provider//register as JAXRS provider
@Priority(1)
public class UnAuthorizedExceptionMapper implements ExceptionMapper<AuthenticationFailedException> {
@Override
public Response toResponse(AuthenticationFailedException exception) {
System.out.println("I m here:"+exception);
JSONObject ob=new JSONObject();
ob.put("errorCode",401);
ob.put("msg","Invalid access token");
return Response.status(Response.Status.UNAUTHORIZED)
.entity(ob.toJSONString())
.build();
}
}
But when I execute my code then above exception mapper is not executed instead following log is appearing in the console :
io.qua.oid.run.OidcProvider
: (vert.x-eventloop-thread-1) Token verification has failed: The JWT is no longer valid - claim value.
How can I customize 401/403 status code msg in quarkus oidc.