|
3 | 3 | import java.util.HashMap; |
4 | 4 | import java.util.Map; |
5 | 5 |
|
| 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; |
6 | 11 | import org.glassfish.jersey.client.ClientProperties; |
7 | 12 |
|
8 | 13 | /** |
@@ -45,4 +50,28 @@ public static Map<String, Object> createProxyClientConfig(String proxyUri, Strin |
45 | 50 |
|
46 | 51 | return (clientConfig); |
47 | 52 | } |
| 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\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 | + } |
48 | 77 | } |
0 commit comments