|
19 | 19 |
|
20 | 20 | import java.io.IOException;
|
21 | 21 | import java.io.UnsupportedEncodingException;
|
| 22 | +import java.net.InetAddress; |
| 23 | +import java.net.UnknownHostException; |
22 | 24 | import java.security.cert.X509Certificate;
|
23 | 25 | import java.util.ArrayList;
|
24 | 26 | import java.util.Date;
|
25 | 27 | import java.util.List;
|
26 | 28 |
|
27 | 29 | import javax.net.ssl.SSLContext;
|
28 | 30 |
|
| 31 | +import edu.uci.ics.crawler4j.crawler.authentication.NtAuthInfo; |
29 | 32 | import org.apache.http.Header;
|
30 | 33 | import org.apache.http.HttpHost;
|
31 | 34 | import org.apache.http.HttpResponse;
|
32 | 35 | import org.apache.http.HttpStatus;
|
33 | 36 | import org.apache.http.NameValuePair;
|
34 | 37 | import org.apache.http.auth.AuthScope;
|
| 38 | +import org.apache.http.auth.NTCredentials; |
35 | 39 | import org.apache.http.auth.UsernamePasswordCredentials;
|
36 | 40 | import org.apache.http.client.ClientProtocolException;
|
37 | 41 | import org.apache.http.client.CredentialsProvider;
|
@@ -145,12 +149,27 @@ private void doAuthetication(List<AuthInfo> authInfos) {
|
145 | 149 | for (AuthInfo authInfo : authInfos) {
|
146 | 150 | if (authInfo.getAuthenticationType() == AuthInfo.AuthenticationType.BASIC_AUTHENTICATION) {
|
147 | 151 | doBasicLogin((BasicAuthInfo) authInfo);
|
148 |
| - } else { |
| 152 | + } else if (authInfo.getAuthenticationType() == AuthInfo.AuthenticationType.NT_AUTHENTICATION) { |
| 153 | + doNtLogin((NtAuthInfo)authInfo); |
| 154 | + }else { |
149 | 155 | doFormLogin((FormAuthInfo) authInfo);
|
150 | 156 | }
|
151 | 157 | }
|
152 | 158 | }
|
153 | 159 |
|
| 160 | + private void doNtLogin(NtAuthInfo authInfo) { |
| 161 | + logger.info("NT authentication for: " + authInfo.getLoginTarget()); |
| 162 | + HttpHost targetHost = new HttpHost(authInfo.getHost(), authInfo.getPort(), authInfo.getProtocol()); |
| 163 | + CredentialsProvider credsProvider = new BasicCredentialsProvider(); |
| 164 | + try { |
| 165 | + credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), |
| 166 | + new NTCredentials(authInfo.getUsername(), authInfo.getPassword(), InetAddress.getLocalHost().getHostName(), authInfo.getDomain())); |
| 167 | + } catch (UnknownHostException e) { |
| 168 | + logger.error("Error creating NT credentials", e); |
| 169 | + } |
| 170 | + httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); |
| 171 | + } |
| 172 | + |
154 | 173 | /**
|
155 | 174 | * BASIC authentication<br/>
|
156 | 175 | * Official Example: https://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples
|
|
0 commit comments