diff --git a/quickfixj-core/src/main/java/quickfix/mina/ProtocolFactory.java b/quickfixj-core/src/main/java/quickfix/mina/ProtocolFactory.java index 13b88f0eec..cb3f69be58 100644 --- a/quickfixj-core/src/main/java/quickfix/mina/ProtocolFactory.java +++ b/quickfixj-core/src/main/java/quickfix/mina/ProtocolFactory.java @@ -21,7 +21,11 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.Base64; +import java.util.Collections; import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.mina.core.service.IoAcceptor; @@ -150,17 +154,29 @@ private static ProxyRequest createHttpProxyRequest(InetSocketAddress address, String proxyPassword, String proxyDomain, String proxyWorkstation) { + HttpProxyRequest req = new HttpProxyRequest(address); HashMap props = new HashMap<>(); - props.put(HttpProxyConstants.USER_PROPERTY, proxyUser); - props.put(HttpProxyConstants.PWD_PROPERTY, proxyPassword); + Map> headers = new HashMap<>(); + boolean authenticationNTLM = false; + if (proxyDomain != null && proxyWorkstation != null) { props.put(HttpProxyConstants.DOMAIN_PROPERTY, proxyDomain); props.put(HttpProxyConstants.WORKSTATION_PROPERTY, proxyWorkstation); + authenticationNTLM = true; + } + if (proxyUser != null && proxyPassword != null) { + props.put(HttpProxyConstants.USER_PROPERTY, proxyUser); + props.put(HttpProxyConstants.PWD_PROPERTY, proxyPassword); + String proxyCredentials = proxyUser + ":" + proxyPassword; + String proxyCredentialsEncoded = Base64.getEncoder().encodeToString(proxyCredentials.getBytes()); + String proxyAuthorization = (authenticationNTLM ? "NTLM " : "Basic ") + proxyCredentialsEncoded; + headers.put("Proxy-Authorization", Collections.singletonList(proxyAuthorization)); } - HttpProxyRequest req = new HttpProxyRequest(address); req.setProperties(props); - if (proxyVersion != null && proxyVersion.equalsIgnoreCase("1.1")) { + req.setHeaders(headers); + + if (proxyVersion != null && "1.1".equalsIgnoreCase(proxyVersion)) { req.setHttpVersion(HttpProxyConstants.HTTP_1_1); } else { req.setHttpVersion(HttpProxyConstants.HTTP_1_0);