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 96-101
import org.apache.http.protocol.HTTP;
Link Here
|
96 |
import org.apache.http.protocol.HttpContext; |
104 |
import org.apache.http.protocol.HttpContext; |
97 |
import org.apache.jmeter.engine.event.LoopIterationEvent; |
105 |
import org.apache.jmeter.engine.event.LoopIterationEvent; |
98 |
import org.apache.jmeter.protocol.http.control.AuthManager; |
106 |
import org.apache.jmeter.protocol.http.control.AuthManager; |
|
|
107 |
import org.apache.jmeter.protocol.http.control.AuthManager.Mechanism; |
99 |
import org.apache.jmeter.protocol.http.control.Authorization; |
108 |
import org.apache.jmeter.protocol.http.control.Authorization; |
100 |
import org.apache.jmeter.protocol.http.control.CacheManager; |
109 |
import org.apache.jmeter.protocol.http.control.CacheManager; |
101 |
import org.apache.jmeter.protocol.http.control.CookieManager; |
110 |
import org.apache.jmeter.protocol.http.control.CookieManager; |
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 287-293
public class HTTPHC4Impl extends HTTPHCAbstractImpl {
Link Here
|
287 |
String entityBody = sendEntityData(( HttpEntityEnclosingRequestBase)httpRequest); |
298 |
String entityBody = sendEntityData(( HttpEntityEnclosingRequestBase)httpRequest); |
288 |
res.setQueryString(entityBody); |
299 |
res.setQueryString(entityBody); |
289 |
} |
300 |
} |
290 |
HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample |
301 |
HttpResponse httpResponse = executeRequest(httpClient, httpRequest, localContext, url); |
291 |
|
302 |
|
292 |
// Needs to be done after execute to pick up all the headers |
303 |
// Needs to be done after execute to pick up all the headers |
293 |
res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST))); |
304 |
res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST))); |
Lines 377-382
public class HTTPHC4Impl extends HTTPHCAbstractImpl {
Link Here
|
377 |
return res; |
388 |
return res; |
378 |
} |
389 |
} |
379 |
|
390 |
|
|
|
391 |
private HttpResponse executeRequest(final HttpClient httpClient, |
392 |
final HttpRequestBase httpRequest, final HttpContext localContext, final URL url) |
393 |
throws IOException, ClientProtocolException { |
394 |
AuthManager authManager = getAuthManager(); |
395 |
if (authManager != null && authManager.hasSubjectForUrl(url)) { |
396 |
Subject subject = authManager.getSubjectForUrl(url); |
397 |
try { |
398 |
return Subject.doAs(subject, |
399 |
new PrivilegedExceptionAction<HttpResponse>() { |
400 |
|
401 |
@Override |
402 |
public HttpResponse run() throws Exception { |
403 |
return httpClient.execute(httpRequest, |
404 |
localContext); |
405 |
} |
406 |
}); |
407 |
} catch (PrivilegedActionException e) { |
408 |
log.warn( |
409 |
"Can't execute httpRequest with kerberos-subject", |
410 |
e); |
411 |
return null; |
412 |
} |
413 |
} |
414 |
// perform the non-kerberos sample |
415 |
return httpClient.execute(httpRequest, localContext); |
416 |
} |
417 |
|
418 |
private static final class NullCredentials implements Credentials { |
419 |
@Override |
420 |
public String getPassword() { |
421 |
return null; |
422 |
} |
423 |
|
424 |
@Override |
425 |
public Principal getUserPrincipal() { |
426 |
return null; |
427 |
} |
428 |
} |
429 |
|
380 |
/** |
430 |
/** |
381 |
* Holder class for all fields that define an HttpClient instance; |
431 |
* Holder class for all fields that define an HttpClient instance; |
382 |
* used as the key to the ThreadLocal map of HttpClient instances. |
432 |
* used as the key to the ThreadLocal map of HttpClient instances. |
Lines 748-758
public class HTTPHC4Impl extends HTTPHCAbstractImpl {
Link Here
|
748 |
String realm = auth.getRealm(); |
798 |
String realm = auth.getRealm(); |
749 |
String domain = auth.getDomain(); |
799 |
String domain = auth.getDomain(); |
750 |
if (log.isDebugEnabled()){ |
800 |
if (log.isDebugEnabled()){ |
751 |
log.debug(username + " > D="+domain+" R="+realm); |
801 |
log.debug(username + " > D="+domain+" R="+realm + " K="+auth.getMechanism()); |
|
|
802 |
} |
803 |
if (Mechanism.KERBEROS.equals(auth.getMechanism())) { |
804 |
((AbstractHttpClient) client).getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true)); |
805 |
credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS); |
806 |
} else { |
807 |
credentialsProvider.setCredentials( |
808 |
new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm), |
809 |
new NTCredentials(username, auth.getPass(), localHost, domain)); |
752 |
} |
810 |
} |
753 |
credentialsProvider.setCredentials( |
|
|
754 |
new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm), |
755 |
new NTCredentials(username, auth.getPass(), localHost, domain)); |
756 |
} else { |
811 |
} else { |
757 |
credentialsProvider.clear(); |
812 |
credentialsProvider.clear(); |
758 |
} |
813 |
} |