001package org.hl7.fhir.utilities.http.okhttpimpl; 002 003import okhttp3.*; 004 005import java.io.IOException; 006 007public class ProxyAuthenticator implements Authenticator { 008 protected static final String HTTP_PROXY_USER = "http.proxyUser"; 009 protected static final String HTTP_PROXY_PASS = "http.proxyPassword"; 010 protected static final String HEADER_PROXY_AUTH = "Proxy-Authorization"; 011 012 @Override 013 public Request authenticate(Route route, Response response) throws IOException { 014 final String httpProxyUser = System.getProperty(HTTP_PROXY_USER); 015 final String httpProxyPass = System.getProperty(HTTP_PROXY_PASS); 016 if (httpProxyUser != null && httpProxyPass != null) { 017 String credential = Credentials.basic(httpProxyUser, httpProxyPass); 018 return response.request().newBuilder() 019 .header(HEADER_PROXY_AUTH, credential) 020 .build(); 021 } 022 return response.request().newBuilder().build(); 023 } 024}