Commit d971f9aa authored by Greg Messner's avatar Greg Messner
Browse files

Added support for NTLM proxies (#395).

parent 522234a7
...@@ -3,6 +3,11 @@ package org.gitlab4j.api; ...@@ -3,6 +3,11 @@ package org.gitlab4j.api;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.glassfish.jersey.apache.connector.ApacheClientProperties;
import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.client.ClientProperties;
/** /**
...@@ -45,4 +50,28 @@ public class ProxyClientConfig { ...@@ -45,4 +50,28 @@ public class ProxyClientConfig {
return (clientConfig); return (clientConfig);
} }
/**
* Create a Map instance set up to use an NTLM proxy server that can be passed to the GitLabAPi constructors
* and login methods to configure the GitLabApi instance to use an NTLM proxy server.
*
* @param proxyUri the URI of the proxy server
* @param username the user name. This should not include the domain to authenticate with.
* For example: "user" is correct whereas "DOMAIN\user" is not.
* @param password the password
* @param workstation the workstation the authentication request is originating from. Essentially, the computer name for this machine.
* @param domain the domain to authenticate within
* @return a Map set up to allow GitLabApi to use an NTLM proxy server
*/
public static Map<String, Object> createNtlmProxyClientConfig(String proxyUri, String username, String password, String workstation, String domain) {
Map<String, Object> clientConfig = new HashMap<>();
clientConfig.put(ClientProperties.PROXY_URI, proxyUri);
CredentialsProvider credentials = new BasicCredentialsProvider();
credentials.setCredentials(AuthScope.ANY, new NTCredentials(username, password, workstation, domain));
clientConfig.put(ApacheClientProperties.CREDENTIALS_PROVIDER, credentials);
return (clientConfig);
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment