I did some additional checks and I think I've found a solution:
Before setting a header for the response, the
HttpActionHelper.buildUnauthenticatedAction() method checks whether the header is already set by invoking
val hasHeader = context.getResponseHeader(HttpConstants.AUTHENTICATE_HEADER).isPresent();However,
context.getResponseHeader() returns the value of the current response header but does not take into account the fact that
savedAuthenticateHeader contains a value.
So I adapted the
JEEContext.getResponseHeader() method as follows, and that fixed my problem:
@Override
public Optional<String> getResponseHeader(final String name) {
if (HttpConstants.AUTHENTICATE_HEADER.equals(name)) {
return Optional.ofNullable(savedAuthenticateHeader);
}
return Optional.ofNullable(this.response.getHeader(name));
}