Skip to content

Commit d971f9a

Browse files
committed
Added support for NTLM proxies (#395).
1 parent 522234a commit d971f9a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/main/java/org/gitlab4j/api/ProxyClientConfig.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6+
import org.apache.http.auth.AuthScope;
7+
import org.apache.http.auth.NTCredentials;
8+
import org.apache.http.client.CredentialsProvider;
9+
import org.apache.http.impl.client.BasicCredentialsProvider;
10+
import org.glassfish.jersey.apache.connector.ApacheClientProperties;
611
import org.glassfish.jersey.client.ClientProperties;
712

813
/**
@@ -45,4 +50,28 @@ public static Map<String, Object> createProxyClientConfig(String proxyUri, Strin
4550

4651
return (clientConfig);
4752
}
53+
54+
/**
55+
* Create a Map instance set up to use an NTLM proxy server that can be passed to the GitLabAPi constructors
56+
* and login methods to configure the GitLabApi instance to use an NTLM proxy server.
57+
*
58+
* @param proxyUri the URI of the proxy server
59+
* @param username the user name. This should not include the domain to authenticate with.
60+
* For example: "user" is correct whereas "DOMAIN&#92;user" is not.
61+
* @param password the password
62+
* @param workstation the workstation the authentication request is originating from. Essentially, the computer name for this machine.
63+
* @param domain the domain to authenticate within
64+
* @return a Map set up to allow GitLabApi to use an NTLM proxy server
65+
*/
66+
public static Map<String, Object> createNtlmProxyClientConfig(String proxyUri, String username, String password, String workstation, String domain) {
67+
68+
Map<String, Object> clientConfig = new HashMap<>();
69+
clientConfig.put(ClientProperties.PROXY_URI, proxyUri);
70+
71+
CredentialsProvider credentials = new BasicCredentialsProvider();
72+
credentials.setCredentials(AuthScope.ANY, new NTCredentials(username, password, workstation, domain));
73+
clientConfig.put(ApacheClientProperties.CREDENTIALS_PROVIDER, credentials);
74+
75+
return (clientConfig);
76+
}
4877
}

0 commit comments

Comments
 (0)