You can add a custom filter and add the Authorization header to the request.
The Authorization header is simply base64 encoded "username:password" string.
public class AuthenticatedFilter extends ZuulFilter {
@Override
public String filterType() {
return "pre";
}
@Override
public int filterOrder() {
return 10;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
String auth = "username" + ":" + "password";
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("ISO-8859-1")));
String authValue = "Basic " + new String(encodedAuth);
ctx.addZuulRequestHeader(HttpHeaders.AUTHORIZATION, authValue);
return null;
}
}
EDIT: You'll also need to create the bean for this filter for Zuul to pick it up. So in your Configuration class/Main application class, add:
@Bean
public AuthenticatedFilter getAuthenticatedFilter () {
return new AuthenticatedFilter();
}