View | Details | Raw Unified | Return to bug 53480
Collapse All | Expand All

(-)src/core/org/apache/jmeter/resources/messages.properties (+1 lines)
Lines 597-602 md5hex_assertion_failure=Error asserting MD5 sum : got {0} but should have been Link Here
597
md5hex_assertion_label=MD5Hex
597
md5hex_assertion_label=MD5Hex
598
md5hex_assertion_md5hex_test=MD5Hex to Assert
598
md5hex_assertion_md5hex_test=MD5Hex to Assert
599
md5hex_assertion_title=MD5Hex Assertion
599
md5hex_assertion_title=MD5Hex Assertion
600
mechanism=Mechanism
600
memory_cache=Memory Cache
601
memory_cache=Memory Cache
601
menu_assertions=Assertions
602
menu_assertions=Assertions
602
menu_close=Close
603
menu_close=Close
(-)src/core/org/apache/jmeter/resources/messages_de.properties (+1 lines)
Lines 309-314 maximum_param=Der maximale Wert welcher f\u00FCr einen Wertebereich erlaubt ist Link Here
309
md5hex_assertion_failure=Fehler beim \u00FCberpr\u00FCfen der MD5 Summe\: {0} erhalten, sollte {1} sein
309
md5hex_assertion_failure=Fehler beim \u00FCberpr\u00FCfen der MD5 Summe\: {0} erhalten, sollte {1} sein
310
md5hex_assertion_md5hex_test=Zu pr\u00FCfender MD5 Hex String
310
md5hex_assertion_md5hex_test=Zu pr\u00FCfender MD5 Hex String
311
md5hex_assertion_title=MD5 Hex \u00DCberpr\u00FCfung
311
md5hex_assertion_title=MD5 Hex \u00DCberpr\u00FCfung
312
mechanism=Mechanismus
312
menu_assertions=\u00DCberpr\u00FCfung
313
menu_assertions=\u00DCberpr\u00FCfung
313
menu_close=Schlie\u00DFen
314
menu_close=Schlie\u00DFen
314
menu_collapse_all=Alle schlie\u00DFen
315
menu_collapse_all=Alle schlie\u00DFen
(-)src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java (-4 / +14 lines)
Lines 52-58 import org.apache.log.Logger; Link Here
52
 *
52
 *
53
 */
53
 */
54
public class AuthManager extends ConfigTestElement implements Serializable {
54
public class AuthManager extends ConfigTestElement implements Serializable {
55
    private static final long serialVersionUID = 233L;
55
    private static final long serialVersionUID = 234L;
56
56
57
    private static final Logger log = LoggingManager.getLoggerForClass();
57
    private static final Logger log = LoggingManager.getLoggerForClass();
58
58
Lines 64-69 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
64
        "password",      //$NON-NLS-1$
64
        "password",      //$NON-NLS-1$
65
        "domain",        //$NON-NLS-1$
65
        "domain",        //$NON-NLS-1$
66
        "realm",         //$NON-NLS-1$
66
        "realm",         //$NON-NLS-1$
67
        "mechanism",     //$NON-NLS-1$
67
        };
68
        };
68
69
69
    // Column numbers - must agree with order above
70
    // Column numbers - must agree with order above
Lines 72-79 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
72
    public static final int COL_PASSWORD = 2;
73
    public static final int COL_PASSWORD = 2;
73
    public static final int COL_DOMAIN = 3;
74
    public static final int COL_DOMAIN = 3;
74
    public static final int COL_REALM = 4;
75
    public static final int COL_REALM = 4;
76
    public static final int COL_MECHANISM = 5;
75
77
76
    private static final int COLUMN_COUNT = COLUMN_RESOURCE_NAMES.length;
78
    private static final int COLUMN_COUNT = COLUMN_RESOURCE_NAMES.length;
79
    
80
    public enum Mechanism {
81
        BASIC, KERBEROS;
82
    }
77
83
78
    /**
84
    /**
79
     * Default Constructor.
85
     * Default Constructor.
Lines 92-99 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
92
    /**
98
    /**
93
     * Update an authentication record.
99
     * Update an authentication record.
94
     */
100
     */
95
    public void set(int index, String url, String user, String pass, String domain, String realm) {
101
    public void set(int index, String url, String user, String pass, String domain, String realm, Mechanism mechanism) {
96
        Authorization auth = new Authorization(url, user, pass, domain, realm);
102
        Authorization auth = new Authorization(url, user, pass, domain, realm, mechanism);
97
        if (index >= 0) {
103
        if (index >= 0) {
98
            getAuthObjects().set(index, new TestElementProperty(auth.getName(), auth));
104
            getAuthObjects().set(index, new TestElementProperty(auth.getName(), auth));
99
        } else {
105
        } else {
Lines 258-264 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
258
                        domain = st.nextToken();
264
                        domain = st.nextToken();
259
                        realm = st.nextToken();
265
                        realm = st.nextToken();
260
                    }
266
                    }
261
                    Authorization auth = new Authorization(url, user, pass,domain,realm);
267
                    Mechanism mechanism = Mechanism.BASIC;
268
                    if (st.hasMoreTokens()){// Allow for old format file without mechanism support
269
                        mechanism = Mechanism.valueOf(st.nextToken());
270
                    }
271
                    Authorization auth = new Authorization(url, user, pass, domain, realm, mechanism);
262
                    getAuthObjects().addItem(auth);
272
                    getAuthObjects().addItem(auth);
263
                } catch (NoSuchElementException e) {
273
                } catch (NoSuchElementException e) {
264
                    log.error("Error parsing auth line: '" + line + "'");
274
                    log.error("Error parsing auth line: '" + line + "'");
(-)src/protocol/http/org/apache/jmeter/protocol/http/control/Authorization.java (-4 / +16 lines)
Lines 21-26 package org.apache.jmeter.protocol.http.control; Link Here
21
import java.io.Serializable;
21
import java.io.Serializable;
22
22
23
import org.apache.jmeter.config.ConfigElement;
23
import org.apache.jmeter.config.ConfigElement;
24
import org.apache.jmeter.protocol.http.control.AuthManager.Mechanism;
24
import org.apache.jmeter.protocol.http.util.Base64Encoder;
25
import org.apache.jmeter.protocol.http.util.Base64Encoder;
25
import org.apache.jmeter.testelement.AbstractTestElement;
26
import org.apache.jmeter.testelement.AbstractTestElement;
26
27
Lines 30-36 import org.apache.jmeter.testelement.AbstractTestElement; Link Here
30
 */
31
 */
31
public class Authorization extends AbstractTestElement implements Serializable {
32
public class Authorization extends AbstractTestElement implements Serializable {
32
33
33
    private static final long serialVersionUID = 240L;
34
    private static final long serialVersionUID = 241L;
34
35
35
    private static final String URL = "Authorization.url"; // $NON-NLS-1$
36
    private static final String URL = "Authorization.url"; // $NON-NLS-1$
36
37
Lines 42-58 public class Authorization extends AbstractTestElement implements Serializable { Link Here
42
43
43
    private static final String REALM = "Authorization.realm"; // $NON-NLS-1$
44
    private static final String REALM = "Authorization.realm"; // $NON-NLS-1$
44
45
46
    private static final String MECHANISM = "Authorization.mechanism"; // $NON-NLS-1$
47
45
    private static final String TAB = "\t"; // $NON-NLS-1$
48
    private static final String TAB = "\t"; // $NON-NLS-1$
46
49
47
    /**
50
    /**
48
     * create the authorization
51
     * create the authorization
49
     */
52
     */
50
    Authorization(String url, String user, String pass, String domain, String realm) {
53
    Authorization(String url, String user, String pass, String domain, String realm, Mechanism mechanism) {
51
        setURL(url);
54
        setURL(url);
52
        setUser(user);
55
        setUser(user);
53
        setPass(pass);
56
        setPass(pass);
54
        setDomain(domain);
57
        setDomain(domain);
55
        setRealm(realm);
58
        setRealm(realm);
59
        setMechanism(mechanism);
56
    }
60
    }
57
61
58
    public boolean expectsModification() {
62
    public boolean expectsModification() {
Lines 60-66 public class Authorization extends AbstractTestElement implements Serializable { Link Here
60
    }
64
    }
61
65
62
    public Authorization() {
66
    public Authorization() {
63
        this("","","","","");
67
        this("","","","","", Mechanism.BASIC);
64
    }
68
    }
65
69
66
    public void addConfigElement(ConfigElement config) {
70
    public void addConfigElement(ConfigElement config) {
Lines 106-115 public class Authorization extends AbstractTestElement implements Serializable { Link Here
106
        setProperty(REALM, realm);
110
        setProperty(REALM, realm);
107
    }
111
    }
108
112
113
    public Mechanism getMechanism() {
114
        return Mechanism.valueOf(getPropertyAsString(MECHANISM));
115
    }
116
117
    public void setMechanism(Mechanism mechanism) {
118
        setProperty(MECHANISM, mechanism.toString());
119
    }
120
109
    // Used for saving entries to a file
121
    // Used for saving entries to a file
110
    @Override
122
    @Override
111
    public String toString() {
123
    public String toString() {
112
        return getURL() + TAB + getUser() + TAB + getPass() + TAB + getDomain() + TAB + getRealm();
124
        return getURL() + TAB + getUser() + TAB + getPass() + TAB + getDomain() + TAB + getRealm() + TAB + getMechanism();
113
    }
125
    }
114
126
115
    public String toBasicHeader(){
127
    public String toBasicHeader(){
(-)src/protocol/http/org/apache/jmeter/protocol/http/control/KerberosManager.java (+165 lines)
Line 0 Link Here
1
package org.apache.jmeter.protocol.http.control;
2
3
import java.io.IOException;
4
import java.io.Serializable;
5
import java.util.concurrent.Callable;
6
import java.util.concurrent.ConcurrentHashMap;
7
import java.util.concurrent.ConcurrentMap;
8
import java.util.concurrent.ExecutionException;
9
import java.util.concurrent.Future;
10
import java.util.concurrent.FutureTask;
11
12
import javax.security.auth.Subject;
13
import javax.security.auth.callback.Callback;
14
import javax.security.auth.callback.CallbackHandler;
15
import javax.security.auth.callback.NameCallback;
16
import javax.security.auth.callback.PasswordCallback;
17
import javax.security.auth.callback.UnsupportedCallbackException;
18
import javax.security.auth.login.LoginContext;
19
import javax.security.auth.login.LoginException;
20
21
import org.apache.jmeter.config.ConfigTestElement;
22
import org.apache.jmeter.engine.event.LoopIterationEvent;
23
import org.apache.jmeter.testbeans.TestBean;
24
import org.apache.jmeter.testelement.TestIterationListener;
25
import org.apache.jmeter.testelement.TestStateListener;
26
import org.apache.jorphan.logging.LoggingManager;
27
import org.apache.log.Logger;
28
29
public class KerberosManager extends ConfigTestElement implements Serializable,
30
        TestIterationListener, TestStateListener, TestBean {
31
32
    private static final long serialVersionUID = 2L;
33
34
    private static final Logger log = LoggingManager.getLoggerForClass();
35
36
    private ConcurrentMap<String, Future<Subject>> subjects;
37
38
    public KerberosManager() {
39
        clearSubjects();
40
    }
41
42
    @Override
43
    public void clear() {
44
        super.clear();
45
        clearSubjects();
46
    }
47
48
    private void clearSubjects() {
49
        subjects = new ConcurrentHashMap<String, Future<Subject>>();
50
    }
51
52
    public Subject getSubjectForUser(final String username,
53
            final String password) {
54
        Callable<Subject> callable = new Callable<Subject>() {
55
56
            @Override
57
            public Subject call() throws Exception {
58
                LoginContext loginCtx;
59
                try {
60
                    loginCtx = new LoginContext("Client",
61
                            new LoginCallbackHandler(username, password));
62
                    loginCtx.login();
63
                    return loginCtx.getSubject();
64
                } catch (LoginException e) {
65
                    log.warn("Could not log in user " + username, e);
66
                }
67
                return null;
68
            }
69
        };
70
71
        FutureTask<Subject> task = new FutureTask<Subject>(callable);
72
        Future<Subject> subjectFuture = subjects.putIfAbsent(username, task);
73
        if (subjectFuture == null) {
74
            subjectFuture = task;
75
            task.run();
76
        }
77
        try {
78
            return subjectFuture.get();
79
        } catch (InterruptedException e1) {
80
            log.warn("Interrupted while getting subject for " + username, e1);
81
        } catch (ExecutionException e1) {
82
            log.warn(
83
                    "Execution of getting subject for " + username + " failed",
84
                    e1);
85
        }
86
        return null;
87
    }
88
89
    @Override
90
    public void testIterationStart(LoopIterationEvent event) {
91
        // TODO Auto-generated method stub
92
    }
93
94
    static private class LoginCallbackHandler implements CallbackHandler {
95
        private String password;
96
        private String username;
97
98
        public LoginCallbackHandler(final String username, final String password) {
99
            super();
100
            this.username = username;
101
            this.password = password;
102
        }
103
104
        @Override
105
        public void handle(Callback[] callbacks) throws IOException,
106
                UnsupportedCallbackException {
107
            for (Callback callback : callbacks) {
108
                if (callback instanceof NameCallback && username != null) {
109
                    NameCallback nc = (NameCallback) callback;
110
                    nc.setName(username);
111
                } else if (callback instanceof PasswordCallback) {
112
                    PasswordCallback pc = (PasswordCallback) callback;
113
                    pc.setPassword(password.toCharArray());
114
                } else {
115
                    /*
116
                     * throw new UnsupportedCallbackException( callback,
117
                     * "Unrecognized Callback");
118
                     */
119
                }
120
            }
121
        }
122
    }
123
    
124
    public String getKrb5Conf() {
125
        return System.getProperty("java.security.krb5.conf");
126
    }
127
128
    public void setKrb5Conf(String krb5Conf) {
129
        System.setProperty("java.security.krb5.conf", krb5Conf);
130
    }
131
132
    public boolean getKrb5Debug() {
133
        return Boolean.valueOf(System.getProperty("java.security.krb5.debug", "False"));
134
    }
135
136
    public void setKrb5Debug(boolean krb5Debug) {
137
        System.setProperty("sun.security.krb5.debug",
138
                Boolean.toString(krb5Debug));
139
    }
140
141
    public String getJaasConf() {
142
        return System.getProperty("java.security.auth.login.config");
143
    }
144
145
    public void setJaasConf(String jaasLocation) {
146
        System.setProperty("java.security.auth.login.config", jaasLocation);
147
    }
148
149
    @Override
150
    public void testStarted() {
151
    }
152
153
    @Override
154
    public void testStarted(String host) {
155
    }
156
157
    @Override
158
    public void testEnded() {
159
    }
160
161
    @Override
162
    public void testEnded(String host) {
163
    }
164
165
}
(-)src/protocol/http/org/apache/jmeter/protocol/http/control/KerberosManagerBeanInfo.java (+33 lines)
Line 0 Link Here
1
package org.apache.jmeter.protocol.http.control;
2
3
import java.beans.PropertyDescriptor;
4
5
import org.apache.jmeter.testbeans.BeanInfoSupport;
6
7
public class KerberosManagerBeanInfo extends BeanInfoSupport {
8
9
    private static final String JAAS_CONF = "jaasConf"; // $NON-NLS-1$
10
    private static final String KRB5_CONF = "krb5Conf"; // $NON-NLS-1$
11
    private static final String KRB5_DEBUG = "krb5Debug"; // $NON-NLS-1$
12
    
13
    public KerberosManagerBeanInfo() {
14
        super(KerberosManager.class);
15
        
16
        createPropertyGroup("settings", new String[] {KRB5_CONF, JAAS_CONF, KRB5_DEBUG});
17
        
18
        PropertyDescriptor krb5Conf = property(KRB5_CONF);
19
        krb5Conf.setValue(NOT_UNDEFINED, Boolean.TRUE);
20
        krb5Conf.setValue(DEFAULT, "/etc/krb5.conf");
21
        
22
        PropertyDescriptor jaasConf = property(JAAS_CONF);
23
        jaasConf.setValue(NOT_UNDEFINED, Boolean.TRUE);
24
        jaasConf.setValue(DEFAULT, "/etc/login.conf");
25
        
26
        PropertyDescriptor krb5Debug = property(KRB5_DEBUG);
27
        krb5Debug.setValue(DEFAULT, Boolean.FALSE);
28
        krb5Debug.setValue(NOT_UNDEFINED, Boolean.TRUE);
29
        krb5Debug.setValue(NOT_EXPRESSION, Boolean.TRUE);
30
        krb5Debug.setValue(NOT_OTHER, Boolean.TRUE);
31
    }
32
33
}
(-)src/protocol/http/org/apache/jmeter/protocol/http/control/KerberosManagerResources.properties (+8 lines)
Line 0 Link Here
1
displayName=Kerberos Configuration
2
settings=Kerberos Settings
3
jaasConf.displayName=jaas file
4
jaasConf.shortDescription=Location of jaas login.conf file
5
krb5Conf.displayName=krb5.conf file
6
krb5Conf.shortDescription=Location of krb5.conf file
7
krb5Debug.displayName=Enable debug infos
8
krb5Debug.shortDescription=Enable debug informations
(-)src/protocol/http/org/apache/jmeter/protocol/http/gui/AuthPanel.java (-1 / +23 lines)
Lines 26-32 import java.awt.event.ActionListener; Link Here
26
import java.io.IOException;
26
import java.io.IOException;
27
27
28
import javax.swing.BorderFactory;
28
import javax.swing.BorderFactory;
29
import javax.swing.DefaultCellEditor;
29
import javax.swing.JButton;
30
import javax.swing.JButton;
31
import javax.swing.JComboBox;
30
import javax.swing.JFileChooser;
32
import javax.swing.JFileChooser;
31
import javax.swing.JPanel;
33
import javax.swing.JPanel;
32
import javax.swing.JPasswordField;
34
import javax.swing.JPasswordField;
Lines 44-49 import org.apache.jmeter.config.gui.AbstractConfigGui; Link Here
44
import org.apache.jmeter.gui.util.FileDialoger;
46
import org.apache.jmeter.gui.util.FileDialoger;
45
import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
47
import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
46
import org.apache.jmeter.protocol.http.control.AuthManager;
48
import org.apache.jmeter.protocol.http.control.AuthManager;
49
import org.apache.jmeter.protocol.http.control.AuthManager.Mechanism;
47
import org.apache.jmeter.protocol.http.control.Authorization;
50
import org.apache.jmeter.protocol.http.control.Authorization;
48
import org.apache.jmeter.testelement.TestElement;
51
import org.apache.jmeter.testelement.TestElement;
49
import org.apache.jmeter.util.JMeterUtils;
52
import org.apache.jmeter.util.JMeterUtils;
Lines 57-63 import org.apache.log.Logger; Link Here
57
 * user selects.
60
 * user selects.
58
 */
61
 */
59
public class AuthPanel extends AbstractConfigGui implements ActionListener {
62
public class AuthPanel extends AbstractConfigGui implements ActionListener {
60
    private static final long serialVersionUID = -9214884465261470761L;
63
64
    private static final long serialVersionUID = -378312656300713636L;
61
65
62
    private static final Logger log = LoggingManager.getLoggerForClass();
66
    private static final Logger log = LoggingManager.getLoggerForClass();
63
67
Lines 248-253 public class AuthPanel extends AbstractConfigGui implements ActionListener { Link Here
248
252
249
        TableColumn passwordColumn = authTable.getColumnModel().getColumn(AuthManager.COL_PASSWORD);
253
        TableColumn passwordColumn = authTable.getColumnModel().getColumn(AuthManager.COL_PASSWORD);
250
        passwordColumn.setCellRenderer(new PasswordCellRenderer());
254
        passwordColumn.setCellRenderer(new PasswordCellRenderer());
255
        
256
        TableColumn mechanismColumn = authTable.getColumnModel().getColumn(AuthManager.COL_MECHANISM);
257
        mechanismColumn.setCellEditor(new MechanismCellEditor());
251
258
252
        JPanel panel = new JPanel(new BorderLayout(0, 5));
259
        JPanel panel = new JPanel(new BorderLayout(0, 5));
253
        panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
260
        panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
Lines 357-362 public class AuthPanel extends AbstractConfigGui implements ActionListener { Link Here
357
                    return auth.getDomain();
364
                    return auth.getDomain();
358
                case AuthManager.COL_REALM:
365
                case AuthManager.COL_REALM:
359
                    return auth.getRealm();
366
                    return auth.getRealm();
367
                case AuthManager.COL_MECHANISM:
368
                	return auth.getMechanism();
360
                default:
369
                default:
361
                    return null;
370
                    return null;
362
            }
371
            }
Lines 382-392 public class AuthPanel extends AbstractConfigGui implements ActionListener { Link Here
382
                case AuthManager.COL_REALM:
391
                case AuthManager.COL_REALM:
383
                    auth.setRealm((String) value);
392
                    auth.setRealm((String) value);
384
                    break;
393
                    break;
394
                case AuthManager.COL_MECHANISM:
395
                    auth.setMechanism((Mechanism) value);
396
                    break;
385
                default:
397
                default:
386
                    break;
398
                    break;
387
            }
399
            }
388
        }
400
        }
389
    }
401
    }
402
    
403
    private static class MechanismCellEditor extends DefaultCellEditor {
404
405
        private static final long serialVersionUID = 6085773573067229265L;
406
        
407
        public MechanismCellEditor() {
408
            super(new JComboBox(Mechanism.values()));
409
        }
410
411
    }
390
412
391
    private static class PasswordCellRenderer extends JPasswordField implements TableCellRenderer {
413
    private static class PasswordCellRenderer extends JPasswordField implements TableCellRenderer {
392
        private static final long serialVersionUID = 5169856333827579927L;
414
        private static final long serialVersionUID = 5169856333827579927L;
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java (+8 lines)
Lines 29-34 import org.apache.jmeter.protocol.http.control.AuthManager; Link Here
29
import org.apache.jmeter.protocol.http.control.CacheManager;
29
import org.apache.jmeter.protocol.http.control.CacheManager;
30
import org.apache.jmeter.protocol.http.control.CookieManager;
30
import org.apache.jmeter.protocol.http.control.CookieManager;
31
import org.apache.jmeter.protocol.http.control.HeaderManager;
31
import org.apache.jmeter.protocol.http.control.HeaderManager;
32
import org.apache.jmeter.protocol.http.control.KerberosManager;
32
import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
33
import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
33
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
34
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
34
import org.apache.jmeter.samplers.Interruptible;
35
import org.apache.jmeter.samplers.Interruptible;
Lines 122-127 public abstract class HTTPAbstractImpl implements Interruptible, HTTPConstantsIn Link Here
122
    }
123
    }
123
124
124
    /**
125
    /**
126
     * Incokes {@link HTTPSamplerBase#getKerberosManager()}
127
     */
128
    protected KerberosManager getKerberosManager() {
129
        return testElement.getKerberosManager();
130
    }
131
132
    /**
125
     * Invokes {@link HTTPSamplerBase#getHTTPFiles()}
133
     * Invokes {@link HTTPSamplerBase#getHTTPFiles()}
126
     */
134
     */
127
    protected HTTPFileArg[] getHTTPFiles() {
135
    protected HTTPFileArg[] getHTTPFiles() {
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (-6 / +73 lines)
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-105 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;
102
import org.apache.jmeter.protocol.http.control.HeaderManager;
111
import org.apache.jmeter.protocol.http.control.HeaderManager;
112
import org.apache.jmeter.protocol.http.control.KerberosManager;
103
import org.apache.jmeter.protocol.http.util.EncoderCache;
113
import org.apache.jmeter.protocol.http.util.EncoderCache;
104
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
114
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
105
import org.apache.jmeter.protocol.http.util.HTTPArgument;
115
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.
177
     * This allows the defaults to be overridden if necessary from the properties file.
168
     */
178
     */
169
    private static final HttpParams DEFAULT_HTTP_PARAMS;
179
    private static final HttpParams DEFAULT_HTTP_PARAMS;
170
    
180
181
    private static final Credentials USE_JAAS_CREDENTIALS = new NullCredentials();
182
171
    static {
183
    static {
172
        log.info("HTTP request retry count = "+RETRY_COUNT);
184
        log.info("HTTP request retry count = "+RETRY_COUNT);
173
        
185
        
Lines 287-293 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
287
                String entityBody = sendEntityData(( HttpEntityEnclosingRequestBase)httpRequest);
299
                String entityBody = sendEntityData(( HttpEntityEnclosingRequestBase)httpRequest);
288
                res.setQueryString(entityBody);
300
                res.setQueryString(entityBody);
289
            }
301
            }
290
            HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample
302
            HttpResponse httpResponse = executeRequest(httpClient, httpRequest, localContext, url);
291
303
292
            // Needs to be done after execute to pick up all the headers
304
            // Needs to be done after execute to pick up all the headers
293
            res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST)));
305
            res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST)));
Lines 377-382 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
377
        return res;
389
        return res;
378
    }
390
    }
379
391
392
    private HttpResponse executeRequest(final HttpClient httpClient,
393
            final HttpRequestBase httpRequest, final HttpContext localContext, final URL url)
394
            throws IOException, ClientProtocolException {
395
        AuthManager authManager = getAuthManager();
396
        if (authManager != null) {
397
            Authorization authorization = authManager.getAuthForURL(url);
398
            if (authorization != null) {
399
                if (Mechanism.KERBEROS.equals(authorization.getMechanism())) {
400
                    KerberosManager kerberosManager = getKerberosManager();
401
                    if (kerberosManager == null) {
402
                        log.error("no kerberos manager configured");
403
                        return null;
404
                    }
405
                    Subject subject = kerberosManager.getSubjectForUser(
406
                            authorization.getUser(), authorization.getPass());
407
                    try {
408
                        return Subject.doAs(subject,
409
                                new PrivilegedExceptionAction<HttpResponse>() {
410
411
                                    @Override
412
                                    public HttpResponse run() throws Exception {
413
                                        return httpClient.execute(httpRequest,
414
                                                localContext);
415
                                    }
416
                                });
417
                    } catch (PrivilegedActionException e) {
418
                        log.warn(
419
                                "Can't execute httpRequest with kerberos-subject",
420
                                e);
421
                        return null;
422
                    }
423
                }
424
            }
425
        }
426
        // perform the non-kerberos sample
427
        return httpClient.execute(httpRequest, localContext);
428
    }
429
430
    private static final class NullCredentials implements Credentials {
431
        @Override
432
        public String getPassword() {
433
            return null;
434
        }
435
436
        @Override
437
        public Principal getUserPrincipal() {
438
            return null;
439
        }
440
    }
441
380
    /**
442
    /**
381
     * Holder class for all fields that define an HttpClient instance;
443
     * Holder class for all fields that define an HttpClient instance;
382
     * used as the key to the ThreadLocal map of HttpClient instances.
444
     * 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();
810
                    String realm = auth.getRealm();
749
                    String domain = auth.getDomain();
811
                    String domain = auth.getDomain();
750
                    if (log.isDebugEnabled()){
812
                    if (log.isDebugEnabled()){
751
                        log.debug(username + " > D="+domain+" R="+realm);
813
                        log.debug(username + " > D="+domain+" R="+realm + " K="+auth.getMechanism());
814
                    }
815
                    if (Mechanism.KERBEROS.equals(auth.getMechanism())) {
816
                        ((AbstractHttpClient) client).getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
817
                        credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS);
818
                    } else {
819
                        credentialsProvider.setCredentials(
820
                                new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
821
                                new NTCredentials(username, auth.getPass(), localHost, domain));
752
                    }
822
                    }
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 {
823
            } else {
757
                credentialsProvider.clear();
824
                credentialsProvider.clear();
758
            }
825
            }
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (-5 / +24 lines)
Lines 54-59 import org.apache.jmeter.protocol.http.control.CacheManager; Link Here
54
import org.apache.jmeter.protocol.http.control.Cookie;
54
import org.apache.jmeter.protocol.http.control.Cookie;
55
import org.apache.jmeter.protocol.http.control.CookieManager;
55
import org.apache.jmeter.protocol.http.control.CookieManager;
56
import org.apache.jmeter.protocol.http.control.HeaderManager;
56
import org.apache.jmeter.protocol.http.control.HeaderManager;
57
import org.apache.jmeter.protocol.http.control.KerberosManager;
57
import org.apache.jmeter.protocol.http.parser.HTMLParseException;
58
import org.apache.jmeter.protocol.http.parser.HTMLParseException;
58
import org.apache.jmeter.protocol.http.parser.HTMLParser;
59
import org.apache.jmeter.protocol.http.parser.HTMLParser;
59
import org.apache.jmeter.protocol.http.util.ConversionUtils;
60
import org.apache.jmeter.protocol.http.util.ConversionUtils;
Lines 94-100 import org.apache.oro.text.regex.Perl5Matcher; Link Here
94
public abstract class HTTPSamplerBase extends AbstractSampler
95
public abstract class HTTPSamplerBase extends AbstractSampler
95
    implements TestStateListener, TestIterationListener, ThreadListener, HTTPConstantsInterface {
96
    implements TestStateListener, TestIterationListener, ThreadListener, HTTPConstantsInterface {
96
97
97
    private static final long serialVersionUID = 240L;
98
    private static final long serialVersionUID = 241L;
98
99
99
    private static final Logger log = LoggingManager.getLoggerForClass();
100
    private static final Logger log = LoggingManager.getLoggerForClass();
100
101
Lines 106-113 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
106
                    "org.apache.jmeter.protocol.http.gui.HeaderPanel",
107
                    "org.apache.jmeter.protocol.http.gui.HeaderPanel",
107
                    "org.apache.jmeter.protocol.http.gui.AuthPanel",
108
                    "org.apache.jmeter.protocol.http.gui.AuthPanel",
108
                    "org.apache.jmeter.protocol.http.gui.CacheManagerGui",
109
                    "org.apache.jmeter.protocol.http.gui.CacheManagerGui",
109
                    "org.apache.jmeter.protocol.http.gui.CookiePanel"}));
110
                    "org.apache.jmeter.protocol.http.gui.CookiePanel",
110
    
111
                    "org.apache.jmeter.protocol.http.control.KerberosManager",}));
112
111
    //+ JMX names - do not change
113
    //+ JMX names - do not change
112
    public static final String ARGUMENTS = "HTTPsampler.Arguments"; // $NON-NLS-1$
114
    public static final String ARGUMENTS = "HTTPsampler.Arguments"; // $NON-NLS-1$
113
115
Lines 119-124 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
119
121
120
    public static final String HEADER_MANAGER = "HTTPSampler.header_manager"; // $NON-NLS-1$
122
    public static final String HEADER_MANAGER = "HTTPSampler.header_manager"; // $NON-NLS-1$
121
123
124
    public static final String KERBEROS_MANAGER = "HTTPSampler.kerberos_manager"; // $NON-NLS-1$
125
122
    public static final String DOMAIN = "HTTPSampler.domain"; // $NON-NLS-1$
126
    public static final String DOMAIN = "HTTPSampler.domain"; // $NON-NLS-1$
123
127
124
    public static final String PORT = "HTTPSampler.port"; // $NON-NLS-1$
128
    public static final String PORT = "HTTPSampler.port"; // $NON-NLS-1$
Lines 596-601 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
596
            setHeaderManager((HeaderManager) el);
600
            setHeaderManager((HeaderManager) el);
597
        } else if (el instanceof AuthManager) {
601
        } else if (el instanceof AuthManager) {
598
            setAuthManager((AuthManager) el);
602
            setAuthManager((AuthManager) el);
603
        } else if (el instanceof KerberosManager) {
604
            setKerberosManager((KerberosManager) el);
599
        } else {
605
        } else {
600
            super.addTestElement(el);
606
            super.addTestElement(el);
601
        }
607
        }
Lines 809-814 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
809
        return (CacheManager) getProperty(CACHE_MANAGER).getObjectValue();
815
        return (CacheManager) getProperty(CACHE_MANAGER).getObjectValue();
810
    }
816
    }
811
817
818
    public void setKerberosManager(KerberosManager value) {
819
        KerberosManager mgr = getKerberosManager();
820
        if (mgr != null) {
821
            log.warn("Existing KerberosManager " + mgr.getName() + " superseded by " + value.getName());
822
        }
823
        setProperty(new TestElementProperty(KERBEROS_MANAGER, value));
824
    }
825
826
    public KerberosManager getKerberosManager() {
827
        return (KerberosManager) getProperty(KERBEROS_MANAGER).getObjectValue();
828
    }
829
812
    public boolean isImageParser() {
830
    public boolean isImageParser() {
813
        return getPropertyAsBoolean(IMAGE_PARSER, false);
831
        return getPropertyAsBoolean(IMAGE_PARSER, false);
814
    }
832
    }
Lines 1854-1859 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
1854
    @Override
1872
    @Override
1855
    public boolean applies(ConfigTestElement configElement) {
1873
    public boolean applies(ConfigTestElement configElement) {
1856
        String guiClass = configElement.getProperty(TestElement.GUI_CLASS).getStringValue();
1874
        String guiClass = configElement.getProperty(TestElement.GUI_CLASS).getStringValue();
1857
        return APPLIABLE_CONFIG_CLASSES.contains(guiClass);
1875
        String testClass = configElement.getPropertyAsString(TestElement.TEST_CLASS);
1876
        return APPLIABLE_CONFIG_CLASSES.contains(guiClass) || APPLIABLE_CONFIG_CLASSES.contains(testClass);
1858
    }
1877
    }
1859
}
1878
}

Return to bug 53480