Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy-Authorization header solves Proxy 407 #631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions quickfixj-core/src/main/java/quickfix/mina/ProtocolFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,17 +154,29 @@ private static ProxyRequest createHttpProxyRequest(InetSocketAddress address,
String proxyPassword,
String proxyDomain,
String proxyWorkstation) {
HttpProxyRequest req = new HttpProxyRequest(address);
HashMap<String, String> props = new HashMap<>();
props.put(HttpProxyConstants.USER_PROPERTY, proxyUser);
props.put(HttpProxyConstants.PWD_PROPERTY, proxyPassword);
Map<String, List<String>> 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);
Expand Down