Lines 30-40
import java.net.URL;
Link Here
|
30 |
import java.net.URLDecoder; |
30 |
import java.net.URLDecoder; |
31 |
import java.nio.charset.Charset; |
31 |
import java.nio.charset.Charset; |
32 |
import java.security.GeneralSecurityException; |
32 |
import java.security.GeneralSecurityException; |
|
|
33 |
import java.security.Principal; |
34 |
import java.security.PrivilegedActionException; |
35 |
import java.security.PrivilegedExceptionAction; |
33 |
import java.util.ArrayList; |
36 |
import java.util.ArrayList; |
34 |
import java.util.HashMap; |
37 |
import java.util.HashMap; |
35 |
import java.util.List; |
38 |
import java.util.List; |
36 |
import java.util.Map; |
39 |
import java.util.Map; |
37 |
|
40 |
|
|
|
41 |
import javax.security.auth.Subject; |
42 |
|
38 |
import org.apache.commons.lang3.StringUtils; |
43 |
import org.apache.commons.lang3.StringUtils; |
39 |
import org.apache.http.Header; |
44 |
import org.apache.http.Header; |
40 |
import org.apache.http.HttpConnection; |
45 |
import org.apache.http.HttpConnection; |
Lines 51-56
import org.apache.http.StatusLine;
Link Here
|
51 |
import org.apache.http.auth.AuthScope; |
56 |
import org.apache.http.auth.AuthScope; |
52 |
import org.apache.http.auth.Credentials; |
57 |
import org.apache.http.auth.Credentials; |
53 |
import org.apache.http.auth.NTCredentials; |
58 |
import org.apache.http.auth.NTCredentials; |
|
|
59 |
import org.apache.http.client.ClientProtocolException; |
54 |
import org.apache.http.client.CredentialsProvider; |
60 |
import org.apache.http.client.CredentialsProvider; |
55 |
import org.apache.http.client.HttpClient; |
61 |
import org.apache.http.client.HttpClient; |
56 |
import org.apache.http.client.HttpRequestRetryHandler; |
62 |
import org.apache.http.client.HttpRequestRetryHandler; |
Lines 66-71
import org.apache.http.client.methods.HttpPut;
Link Here
|
66 |
import org.apache.http.client.methods.HttpRequestBase; |
72 |
import org.apache.http.client.methods.HttpRequestBase; |
67 |
import org.apache.http.client.methods.HttpTrace; |
73 |
import org.apache.http.client.methods.HttpTrace; |
68 |
import org.apache.http.client.methods.HttpUriRequest; |
74 |
import org.apache.http.client.methods.HttpUriRequest; |
|
|
75 |
import org.apache.http.client.params.AuthPolicy; |
69 |
import org.apache.http.client.params.ClientPNames; |
76 |
import org.apache.http.client.params.ClientPNames; |
70 |
import org.apache.http.client.params.CookiePolicy; |
77 |
import org.apache.http.client.params.CookiePolicy; |
71 |
import org.apache.http.client.protocol.ResponseContentEncoding; |
78 |
import org.apache.http.client.protocol.ResponseContentEncoding; |
Lines 80-85
import org.apache.http.entity.mime.HttpMultipartMode;
Link Here
|
80 |
import org.apache.http.entity.mime.MultipartEntity; |
87 |
import org.apache.http.entity.mime.MultipartEntity; |
81 |
import org.apache.http.entity.mime.content.FileBody; |
88 |
import org.apache.http.entity.mime.content.FileBody; |
82 |
import org.apache.http.entity.mime.content.StringBody; |
89 |
import org.apache.http.entity.mime.content.StringBody; |
|
|
90 |
import org.apache.http.impl.auth.SPNegoSchemeFactory; |
83 |
import org.apache.http.impl.client.AbstractHttpClient; |
91 |
import org.apache.http.impl.client.AbstractHttpClient; |
84 |
import org.apache.http.impl.client.DefaultHttpClient; |
92 |
import org.apache.http.impl.client.DefaultHttpClient; |
85 |
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; |
93 |
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; |
Lines 100-105
import org.apache.jmeter.protocol.http.control.Authorization;
Link Here
|
100 |
import org.apache.jmeter.protocol.http.control.CacheManager; |
108 |
import org.apache.jmeter.protocol.http.control.CacheManager; |
101 |
import org.apache.jmeter.protocol.http.control.CookieManager; |
109 |
import org.apache.jmeter.protocol.http.control.CookieManager; |
102 |
import org.apache.jmeter.protocol.http.control.HeaderManager; |
110 |
import org.apache.jmeter.protocol.http.control.HeaderManager; |
|
|
111 |
import org.apache.jmeter.protocol.http.control.KerberosManager; |
103 |
import org.apache.jmeter.protocol.http.util.EncoderCache; |
112 |
import org.apache.jmeter.protocol.http.util.EncoderCache; |
104 |
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory; |
113 |
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory; |
105 |
import org.apache.jmeter.protocol.http.util.HTTPArgument; |
114 |
import org.apache.jmeter.protocol.http.util.HTTPArgument; |
Lines 167-173
public class HTTPHC4Impl extends HTTPHCAbstractImpl {
Link Here
|
167 |
* This allows the defaults to be overridden if necessary from the properties file. |
176 |
* This allows the defaults to be overridden if necessary from the properties file. |
168 |
*/ |
177 |
*/ |
169 |
private static final HttpParams DEFAULT_HTTP_PARAMS; |
178 |
private static final HttpParams DEFAULT_HTTP_PARAMS; |
170 |
|
179 |
|
|
|
180 |
private static final Credentials USE_JAAS_CREDENTIALS = new NullCredentials(); |
181 |
|
171 |
static { |
182 |
static { |
172 |
log.info("HTTP request retry count = "+RETRY_COUNT); |
183 |
log.info("HTTP request retry count = "+RETRY_COUNT); |
173 |
|
184 |
|
Lines 275-281
public class HTTPHC4Impl extends HTTPHCAbstractImpl {
Link Here
|
275 |
try { |
286 |
try { |
276 |
currentRequest = httpRequest; |
287 |
currentRequest = httpRequest; |
277 |
handleMethod(method, res, httpRequest, localContext); |
288 |
handleMethod(method, res, httpRequest, localContext); |
278 |
HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample |
289 |
HttpResponse httpResponse = executeRequest(httpClient, httpRequest, localContext, url); |
279 |
|
290 |
|
280 |
// Needs to be done after execute to pick up all the headers |
291 |
// Needs to be done after execute to pick up all the headers |
281 |
res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST))); |
292 |
res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST))); |
Lines 365-370
public class HTTPHC4Impl extends HTTPHCAbstractImpl {
Link Here
|
365 |
return res; |
376 |
return res; |
366 |
} |
377 |
} |
367 |
|
378 |
|
|
|
379 |
private HttpResponse executeRequest(final HttpClient httpClient, |
380 |
final HttpRequestBase httpRequest, final HttpContext localContext, final URL url) |
381 |
throws IOException, ClientProtocolException { |
382 |
AuthManager authManager = getAuthManager(); |
383 |
if (authManager != null) { |
384 |
Authorization authorization = authManager.getAuthForURL(url); |
385 |
if (authorization != null) { |
386 |
if (authorization.getKerberos()) { |
387 |
KerberosManager kerberosManager = getKerberosManager(); |
388 |
if (kerberosManager == null) { |
389 |
log.error("no kerberos manager configured"); |
390 |
return null; |
391 |
} |
392 |
Subject subject = kerberosManager.getSubjectForUser( |
393 |
authorization.getUser(), authorization.getPass()); |
394 |
try { |
395 |
return Subject.doAs(subject, |
396 |
new PrivilegedExceptionAction<HttpResponse>() { |
397 |
|
398 |
@Override |
399 |
public HttpResponse run() throws Exception { |
400 |
return httpClient.execute(httpRequest, |
401 |
localContext); |
402 |
} |
403 |
}); |
404 |
} catch (PrivilegedActionException e) { |
405 |
log.warn( |
406 |
"Can't execute httpRequest with kerberos-subject", |
407 |
e); |
408 |
return null; |
409 |
} |
410 |
} |
411 |
} |
412 |
} |
413 |
// perform the non-kerberos sample |
414 |
return httpClient.execute(httpRequest, localContext); |
415 |
} |
416 |
|
417 |
private static final class NullCredentials implements Credentials { |
418 |
@Override |
419 |
public String getPassword() { |
420 |
return null; |
421 |
} |
422 |
|
423 |
@Override |
424 |
public Principal getUserPrincipal() { |
425 |
return null; |
426 |
} |
427 |
} |
428 |
|
368 |
/** |
429 |
/** |
369 |
* Calls sendPostData if method is POST and sendEntityData if method is PUT or PATCH |
430 |
* Calls sendPostData if method is POST and sendEntityData if method is PUT or PATCH |
370 |
* Field HTTPSampleResult#queryString of result is modified in the 2 cases |
431 |
* Field HTTPSampleResult#queryString of result is modified in the 2 cases |
Lines 790-800
public class HTTPHC4Impl extends HTTPHCAbstractImpl {
Link Here
|
790 |
String realm = auth.getRealm(); |
851 |
String realm = auth.getRealm(); |
791 |
String domain = auth.getDomain(); |
852 |
String domain = auth.getDomain(); |
792 |
if (log.isDebugEnabled()){ |
853 |
if (log.isDebugEnabled()){ |
793 |
log.debug(username + " > D="+domain+" R="+realm); |
854 |
log.debug(username + " > D="+domain+" R="+realm + " K="+auth.getKerberos()); |
|
|
855 |
} |
856 |
if (auth.getKerberos()) { |
857 |
((AbstractHttpClient) client).getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true)); |
858 |
credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS); |
859 |
} else { |
860 |
credentialsProvider.setCredentials( |
861 |
new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm), |
862 |
new NTCredentials(username, auth.getPass(), localHost, domain)); |
794 |
} |
863 |
} |
795 |
credentialsProvider.setCredentials( |
|
|
796 |
new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm), |
797 |
new NTCredentials(username, auth.getPass(), localHost, domain)); |
798 |
} else { |
864 |
} else { |
799 |
credentialsProvider.clear(); |
865 |
credentialsProvider.clear(); |
800 |
} |
866 |
} |