You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2013/07/30 23:16:35 UTC
svn commit: r1508633 - in /jmeter/trunk:
src/core/org/apache/jmeter/resources/
src/protocol/http/org/apache/jmeter/protocol/http/control/
src/protocol/http/org/apache/jmeter/protocol/http/gui/
src/protocol/http/org/apache/jmeter/protocol/http/sampler/ ...
Author: pmouawad
Date: Tue Jul 30 21:16:35 2013
New Revision: 1508633
URL: http://svn.apache.org/r1508633
Log:
Bug 53480 - Add Kerberos support to Http Sampler (HttpClient4)
Bugzilla Id: 53480
Added:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/KerberosManager.java (with props)
Modified:
jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
jmeter/trunk/src/core/org/apache/jmeter/resources/messages_de.properties
jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Authorization.java
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/AuthPanel.java
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1508633&r1=1508632&r2=1508633&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Tue Jul 30 21:16:35 2013
@@ -598,6 +598,7 @@ md5hex_assertion_failure=Error asserting
md5hex_assertion_label=MD5Hex
md5hex_assertion_md5hex_test=MD5Hex to Assert
md5hex_assertion_title=MD5Hex Assertion
+mechanism=Mechanism
memory_cache=Memory Cache
menu_assertions=Assertions
menu_close=Close
Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_de.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_de.properties?rev=1508633&r1=1508632&r2=1508633&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_de.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_de.properties Tue Jul 30 21:16:35 2013
@@ -309,6 +309,7 @@ maximum_param=Der maximale Wert welcher
md5hex_assertion_failure=Fehler beim \u00FCberpr\u00FCfen der MD5 Summe\: {0} erhalten, sollte {1} sein
md5hex_assertion_md5hex_test=Zu pr\u00FCfender MD5 Hex String
md5hex_assertion_title=MD5 Hex \u00DCberpr\u00FCfung
+mechanism=Mechanismus
menu_assertions=\u00DCberpr\u00FCfung
menu_close=Schlie\u00DFen
menu_collapse_all=Alle schlie\u00DFen
Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1508633&r1=1508632&r2=1508633&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Tue Jul 30 21:16:35 2013
@@ -592,6 +592,7 @@ md5hex_assertion_failure=Erreur de v\u00
md5hex_assertion_label=MD5Hex
md5hex_assertion_md5hex_test=MD5Hex \u00E0 v\u00E9rifier
md5hex_assertion_title=Assertion MD5Hex
+mechanism=M\u00E9chanisme
memory_cache=Cache de m\u00E9moire
menu_assertions=Assertions
menu_close=Fermer
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java?rev=1508633&r1=1508632&r2=1508633&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java Tue Jul 30 21:16:35 2013
@@ -27,11 +27,21 @@ import java.io.PrintWriter;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
+import java.security.Principal;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
-import org.apache.commons.io.IOUtils;
+import javax.security.auth.Subject;
+
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.NTCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.params.AuthPolicy;
+import org.apache.http.impl.auth.SPNegoSchemeFactory;
+import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.jmeter.config.ConfigElement;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
@@ -52,7 +62,7 @@ import org.apache.log.Logger;
*
*/
public class AuthManager extends ConfigTestElement implements Serializable {
- private static final long serialVersionUID = 233L;
+ private static final long serialVersionUID = 234L;
private static final Logger log = LoggingManager.getLoggerForClass();
@@ -64,6 +74,7 @@ public class AuthManager extends ConfigT
"password", //$NON-NLS-1$
"domain", //$NON-NLS-1$
"realm", //$NON-NLS-1$
+ "mechanism", //$NON-NLS-1$
};
// Column numbers - must agree with order above
@@ -72,9 +83,30 @@ public class AuthManager extends ConfigT
public static final int COL_PASSWORD = 2;
public static final int COL_DOMAIN = 3;
public static final int COL_REALM = 4;
+ public static final int COL_MECHANISM = 5;
private static final int COLUMN_COUNT = COLUMN_RESOURCE_NAMES.length;
+ private static final Credentials USE_JAAS_CREDENTIALS = new NullCredentials();
+
+ public enum Mechanism {
+ BASIC_DIGEST, KERBEROS;
+ }
+
+ private static final class NullCredentials implements Credentials {
+ @Override
+ public String getPassword() {
+ return null;
+ }
+
+ @Override
+ public Principal getUserPrincipal() {
+ return null;
+ }
+ }
+
+ private KerberosManager kerberosManager = new KerberosManager();
+
/**
* Default Constructor.
*/
@@ -86,14 +118,15 @@ public class AuthManager extends ConfigT
@Override
public void clear() {
super.clear();
+ kerberosManager.clearSubjects();
setProperty(new CollectionProperty(AUTH_LIST, new ArrayList<Object>()));
}
/**
* Update an authentication record.
*/
- public void set(int index, String url, String user, String pass, String domain, String realm) {
- Authorization auth = new Authorization(url, user, pass, domain, realm);
+ public void set(int index, String url, String user, String pass, String domain, String realm, Mechanism mechanism) {
+ Authorization auth = new Authorization(url, user, pass, domain, realm, mechanism);
if (index >= 0) {
getAuthObjects().set(index, new TestElementProperty(auth.getName(), auth));
} else {
@@ -189,6 +222,25 @@ public class AuthManager extends ConfigT
return null;
}
+ /**
+ * @return boolean true if an authorization is setup for url
+ */
+ public boolean hasAuthForURL(URL url) {
+ return getAuthForURL(url) != null;
+ }
+
+ /**
+ * @return Subject if Auth Scheme uses Subject and an authorization is setup for url
+ */
+ public Subject getSubjectForUrl(URL url) {
+ Authorization authorization = getAuthForURL(url);
+ if (authorization != null && Mechanism.KERBEROS.equals(authorization.getMechanism())) {
+ return kerberosManager.getSubjectForUser(
+ authorization.getUser(), authorization.getPass());
+ }
+ return null;
+ }
+
/** {@inheritDoc} */
@Override
public void addConfigElement(ConfigElement config) {
@@ -216,14 +268,19 @@ public class AuthManager extends ConfigT
if (!file.isAbsolute()) {
file = new File(System.getProperty("user.dir"),authFile);
}
- PrintWriter writer = new PrintWriter(new FileWriter(file));
- writer.println("# JMeter generated Authorization file");
- for (int i = 0; i < getAuthObjects().size(); i++) {
- Authorization auth = (Authorization) getAuthObjects().get(i).getObjectValue();
- writer.println(auth.toString());
+ PrintWriter writer = null;
+ try {
+ writer = new PrintWriter(new FileWriter(file));
+ writer.println("# JMeter generated Authorization file");
+ for (int i = 0; i < getAuthObjects().size(); i++) {
+ Authorization auth = (Authorization) getAuthObjects().get(i).getObjectValue();
+ writer.println(auth.toString());
+ }
+ writer.flush();
+ writer.close();
+ } finally {
+ JOrphanUtils.closeQuietly(writer);
}
- writer.flush();
- writer.close();
}
/**
@@ -258,7 +315,11 @@ public class AuthManager extends ConfigT
domain = st.nextToken();
realm = st.nextToken();
}
- Authorization auth = new Authorization(url, user, pass,domain,realm);
+ Mechanism mechanism = Mechanism.BASIC_DIGEST;
+ if (st.hasMoreTokens()){// Allow for old format file without mechanism support
+ mechanism = Mechanism.valueOf(st.nextToken());
+ }
+ Authorization auth = new Authorization(url, user, pass, domain, realm, mechanism);
getAuthObjects().addItem(auth);
} catch (NoSuchElementException e) {
log.error("Error parsing auth line: '" + line + "'");
@@ -266,7 +327,7 @@ public class AuthManager extends ConfigT
}
}
} finally {
- IOUtils.closeQuietly(reader);
+ JOrphanUtils.closeQuietly(reader);
}
if (!ok){
JMeterUtils.reportErrorToUser("One or more errors found when reading the Auth file - see the log file");
@@ -291,5 +352,34 @@ public class AuthManager extends ConfigT
static boolean isSupportedProtocol(URL url) {
String protocol = url.getProtocol().toLowerCase(java.util.Locale.ENGLISH);
return protocol.equals(HTTPConstants.PROTOCOL_HTTP) || protocol.equals(HTTPConstants.PROTOCOL_HTTPS);
+ }
+
+ /**
+ * Configure credentials and auth scheme on client if an authorization is
+ * available for url
+ * @param client {@link HttpClient}
+ * @param url URL to test
+ * @param credentialsProvider {@link CredentialsProvider}
+ * @param localHost host running JMeter
+ */
+ public void setupCredentials(HttpClient client, URL url,
+ CredentialsProvider credentialsProvider, String localHost) {
+ Authorization auth = getAuthForURL(url);
+ if (auth != null) {
+ String username = auth.getUser();
+ String realm = auth.getRealm();
+ String domain = auth.getDomain();
+ if (log.isDebugEnabled()){
+ log.debug(username + " > D="+domain+" R="+realm + " M="+auth.getMechanism());
+ }
+ if (Mechanism.KERBEROS.equals(auth.getMechanism())) {
+ ((AbstractHttpClient) client).getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
+ credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS);
+ } else {
+ credentialsProvider.setCredentials(
+ new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
+ new NTCredentials(username, auth.getPass(), localHost, domain));
+ }
+ }
}
}
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Authorization.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Authorization.java?rev=1508633&r1=1508632&r2=1508633&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Authorization.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/Authorization.java Tue Jul 30 21:16:35 2013
@@ -21,6 +21,7 @@ package org.apache.jmeter.protocol.http.
import java.io.Serializable;
import org.apache.jmeter.config.ConfigElement;
+import org.apache.jmeter.protocol.http.control.AuthManager.Mechanism;
import org.apache.jmeter.protocol.http.util.Base64Encoder;
import org.apache.jmeter.testelement.AbstractTestElement;
@@ -30,7 +31,7 @@ import org.apache.jmeter.testelement.Abs
*/
public class Authorization extends AbstractTestElement implements Serializable {
- private static final long serialVersionUID = 240L;
+ private static final long serialVersionUID = 241L;
private static final String URL = "Authorization.url"; // $NON-NLS-1$
@@ -42,17 +43,20 @@ public class Authorization extends Abstr
private static final String REALM = "Authorization.realm"; // $NON-NLS-1$
+ private static final String MECHANISM = "Authorization.mechanism"; // $NON-NLS-1$
+
private static final String TAB = "\t"; // $NON-NLS-1$
/**
* create the authorization
*/
- Authorization(String url, String user, String pass, String domain, String realm) {
+ Authorization(String url, String user, String pass, String domain, String realm, Mechanism mechanism) {
setURL(url);
setUser(user);
setPass(pass);
setDomain(domain);
setRealm(realm);
+ setMechanism(mechanism);
}
public boolean expectsModification() {
@@ -60,7 +64,7 @@ public class Authorization extends Abstr
}
public Authorization() {
- this("","","","","");
+ this("","","","","", Mechanism.BASIC_DIGEST);
}
public void addConfigElement(ConfigElement config) {
@@ -106,10 +110,18 @@ public class Authorization extends Abstr
setProperty(REALM, realm);
}
+ public Mechanism getMechanism() {
+ return Mechanism.valueOf(getPropertyAsString(MECHANISM, Mechanism.BASIC_DIGEST.name()));
+ }
+
+ public void setMechanism(Mechanism mechanism) {
+ setProperty(MECHANISM, mechanism.toString());
+ }
+
// Used for saving entries to a file
@Override
public String toString() {
- return getURL() + TAB + getUser() + TAB + getPass() + TAB + getDomain() + TAB + getRealm();
+ return getURL() + TAB + getUser() + TAB + getPass() + TAB + getDomain() + TAB + getRealm() + TAB + getMechanism();
}
public String toBasicHeader(){
Added: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/KerberosManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/KerberosManager.java?rev=1508633&view=auto
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/KerberosManager.java (added)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/KerberosManager.java Tue Jul 30 21:16:35 2013
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.protocol.http.control;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+
+/**
+ * Takes in charge Kerberos auth mechanism
+ *
+ */
+class KerberosManager implements Serializable {
+
+ private static final long serialVersionUID = 2L;
+
+ private static final Logger log = LoggingManager.getLoggerForClass();
+
+ private ConcurrentMap<String, Future<Subject>> subjects
+ = new ConcurrentHashMap<String, Future<Subject>>();
+
+ public KerberosManager() {
+ }
+
+ void clearSubjects() {
+ subjects.clear();
+ }
+
+ public Subject getSubjectForUser(final String username,
+ final String password) {
+ Callable<Subject> callable = new Callable<Subject>() {
+
+ @Override
+ public Subject call() throws Exception {
+ LoginContext loginCtx;
+ try {
+ loginCtx = new LoginContext("Client",
+ new LoginCallbackHandler(username, password));
+ loginCtx.login();
+ return loginCtx.getSubject();
+ } catch (LoginException e) {
+ log.warn("Could not log in user " + username, e);
+ }
+ return null;
+ }
+ };
+
+ FutureTask<Subject> task = new FutureTask<Subject>(callable);
+ Future<Subject> subjectFuture = subjects.putIfAbsent(username, task);
+ if (subjectFuture == null) {
+ subjectFuture = task;
+ task.run();
+ }
+ try {
+ return subjectFuture.get();
+ } catch (InterruptedException e1) {
+ log.warn("Interrupted while getting subject for " + username, e1);
+ } catch (ExecutionException e1) {
+ log.warn(
+ "Execution of getting subject for " + username + " failed",
+ e1);
+ }
+ return null;
+ }
+
+ static private class LoginCallbackHandler implements CallbackHandler {
+ private String password;
+ private String username;
+
+ public LoginCallbackHandler(final String username, final String password) {
+ super();
+ this.username = username;
+ this.password = password;
+ }
+
+ @Override
+ public void handle(Callback[] callbacks) throws IOException,
+ UnsupportedCallbackException {
+ for (Callback callback : callbacks) {
+ if (callback instanceof NameCallback && username != null) {
+ NameCallback nc = (NameCallback) callback;
+ nc.setName(username);
+ } else if (callback instanceof PasswordCallback) {
+ PasswordCallback pc = (PasswordCallback) callback;
+ pc.setPassword(password.toCharArray());
+ } else {
+ throw new UnsupportedCallbackException( callback,
+ "Unrecognized Callback");
+ }
+ }
+ }
+ }
+
+ public String getKrb5Conf() {
+ return System.getProperty("java.security.krb5.conf");
+ }
+
+ public boolean getKrb5Debug() {
+ return Boolean.valueOf(System.getProperty("java.security.krb5.debug", "False"));
+ }
+
+ public String getJaasConf() {
+ return System.getProperty("java.security.auth.login.config");
+ }
+
+ @Override
+ public String toString() {
+ return "KerberosManager[jaas: " + getJaasConf() + ", krb5: " + getKrb5Conf() + ", debug: " + getKrb5Debug() +"]";
+ }
+}
Propchange: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/KerberosManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/AuthPanel.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/AuthPanel.java?rev=1508633&r1=1508632&r2=1508633&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/AuthPanel.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/gui/AuthPanel.java Tue Jul 30 21:16:35 2013
@@ -26,7 +26,9 @@ import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.BorderFactory;
+import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
+import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
@@ -44,6 +46,7 @@ import org.apache.jmeter.config.gui.Abst
import org.apache.jmeter.gui.util.FileDialoger;
import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
import org.apache.jmeter.protocol.http.control.AuthManager;
+import org.apache.jmeter.protocol.http.control.AuthManager.Mechanism;
import org.apache.jmeter.protocol.http.control.Authorization;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
@@ -57,7 +60,7 @@ import org.apache.log.Logger;
* user selects.
*/
public class AuthPanel extends AbstractConfigGui implements ActionListener {
- private static final long serialVersionUID = -9214884465261470761L;
+ private static final long serialVersionUID = -378312656300713636L;
private static final Logger log = LoggingManager.getLoggerForClass();
@@ -248,6 +251,9 @@ public class AuthPanel extends AbstractC
TableColumn passwordColumn = authTable.getColumnModel().getColumn(AuthManager.COL_PASSWORD);
passwordColumn.setCellRenderer(new PasswordCellRenderer());
+
+ TableColumn mechanismColumn = authTable.getColumnModel().getColumn(AuthManager.COL_MECHANISM);
+ mechanismColumn.setCellEditor(new MechanismCellEditor());
JPanel panel = new JPanel(new BorderLayout(0, 5));
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
@@ -357,6 +363,8 @@ public class AuthPanel extends AbstractC
return auth.getDomain();
case AuthManager.COL_REALM:
return auth.getRealm();
+ case AuthManager.COL_MECHANISM:
+ return auth.getMechanism();
default:
return null;
}
@@ -382,11 +390,23 @@ public class AuthPanel extends AbstractC
case AuthManager.COL_REALM:
auth.setRealm((String) value);
break;
+ case AuthManager.COL_MECHANISM:
+ auth.setMechanism((Mechanism) value);
+ break;
default:
break;
}
}
}
+
+ private static class MechanismCellEditor extends DefaultCellEditor {
+
+ private static final long serialVersionUID = 6085773573067229265L;
+
+ public MechanismCellEditor() {
+ super(new JComboBox(Mechanism.values()));
+ }
+ }
private static class PasswordCellRenderer extends JPasswordField implements TableCellRenderer {
private static final long serialVersionUID = 5169856333827579927L;
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1508633&r1=1508632&r2=1508633&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java Tue Jul 30 21:16:35 2013
@@ -30,11 +30,15 @@ import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.security.auth.Subject;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpConnection;
@@ -51,6 +55,7 @@ import org.apache.http.StatusLine;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.NTCredentials;
+import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler;
@@ -94,7 +99,6 @@ import org.apache.http.protocol.Executio
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.jmeter.protocol.http.control.AuthManager;
-import org.apache.jmeter.protocol.http.control.Authorization;
import org.apache.jmeter.protocol.http.control.CacheManager;
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.HeaderManager;
@@ -165,7 +169,7 @@ public class HTTPHC4Impl extends HTTPHCA
* This allows the defaults to be overridden if necessary from the properties file.
*/
private static final HttpParams DEFAULT_HTTP_PARAMS;
-
+
static {
log.info("HTTP request retry count = "+RETRY_COUNT);
@@ -286,7 +290,9 @@ public class HTTPHC4Impl extends HTTPHCA
try {
currentRequest = httpRequest;
handleMethod(method, res, httpRequest, localContext);
- HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample
+ // perform the sample
+ HttpResponse httpResponse =
+ executeRequest(httpClient, httpRequest, localContext, url);
// Needs to be done after execute to pick up all the headers
res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST)));
@@ -417,6 +423,45 @@ public class HTTPHC4Impl extends HTTPHCA
}
/**
+ * Execute request either as is or under PrivilegedAction
+ * if a Subject is available for url
+ * @param httpClient
+ * @param httpRequest
+ * @param localContext
+ * @param url
+ * @return
+ * @throws IOException
+ * @throws ClientProtocolException
+ */
+ private HttpResponse executeRequest(final HttpClient httpClient,
+ final HttpRequestBase httpRequest, final HttpContext localContext, final URL url)
+ throws IOException, ClientProtocolException {
+ AuthManager authManager = getAuthManager();
+ if (authManager != null) {
+ Subject subject = authManager.getSubjectForUrl(url);
+ if(subject != null) {
+ try {
+ return Subject.doAs(subject,
+ new PrivilegedExceptionAction<HttpResponse>() {
+
+ @Override
+ public HttpResponse run() throws Exception {
+ return httpClient.execute(httpRequest,
+ localContext);
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ log.error(
+ "Can't execute httpRequest with subject:"+subject,
+ e);
+ throw new RuntimeException("Can't execute httpRequest with subject:"+subject, e);
+ }
+ }
+ }
+ return httpClient.execute(httpRequest, localContext);
+ }
+
+ /**
* Holder class for all fields that define an HttpClient instance;
* used as the key to the ThreadLocal map of HttpClient instances.
*/
@@ -796,17 +841,8 @@ public class HTTPHC4Impl extends HTTPHCA
CredentialsProvider credentialsProvider =
((AbstractHttpClient) client).getCredentialsProvider();
if (authManager != null) {
- Authorization auth = authManager.getAuthForURL(url);
- if (auth != null) {
- String username = auth.getUser();
- String realm = auth.getRealm();
- String domain = auth.getDomain();
- if (log.isDebugEnabled()){
- log.debug(username + " > D="+domain+" R="+realm);
- }
- credentialsProvider.setCredentials(
- new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
- new NTCredentials(username, auth.getPass(), localHost, domain));
+ if(authManager.hasAuthForURL(url)) {
+ authManager.setupCredentials(client, url, credentialsProvider, localHost);
} else {
credentialsProvider.clear();
}
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1508633&r1=1508632&r2=1508633&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Tue Jul 30 21:16:35 2013
@@ -290,6 +290,7 @@ Previously the default was 1, which coul
<ul>
<li>HTTP Request: Small user interaction improvements in Row parameter Detail Box</li>
<li><bugzilla>55255</bugzilla> - Allow Body in HTTP DELETE method to support API that use it (like ElasticSearch)</li>
+<li><bugzilla>53480</bugzilla> - Add Kerberos support to Http Sampler (HttpClient4)</li>
</ul>
<h3>Other samplers</h3>