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 / +41 lines)
Lines 31-36 import java.util.ArrayList; Link Here
31
import java.util.NoSuchElementException;
31
import java.util.NoSuchElementException;
32
import java.util.StringTokenizer;
32
import java.util.StringTokenizer;
33
33
34
import javax.security.auth.Subject;
35
34
import org.apache.commons.io.IOUtils;
36
import org.apache.commons.io.IOUtils;
35
import org.apache.jmeter.config.ConfigElement;
37
import org.apache.jmeter.config.ConfigElement;
36
import org.apache.jmeter.config.ConfigTestElement;
38
import org.apache.jmeter.config.ConfigTestElement;
Lines 52-58 import org.apache.log.Logger; Link Here
52
 *
54
 *
53
 */
55
 */
54
public class AuthManager extends ConfigTestElement implements Serializable {
56
public class AuthManager extends ConfigTestElement implements Serializable {
55
    private static final long serialVersionUID = 233L;
57
    private static final long serialVersionUID = 234L;
56
58
57
    private static final Logger log = LoggingManager.getLoggerForClass();
59
    private static final Logger log = LoggingManager.getLoggerForClass();
58
60
Lines 64-69 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
64
        "password",      //$NON-NLS-1$
66
        "password",      //$NON-NLS-1$
65
        "domain",        //$NON-NLS-1$
67
        "domain",        //$NON-NLS-1$
66
        "realm",         //$NON-NLS-1$
68
        "realm",         //$NON-NLS-1$
69
        "mechanism",     //$NON-NLS-1$
67
        };
70
        };
68
71
69
    // Column numbers - must agree with order above
72
    // Column numbers - must agree with order above
Lines 72-80 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
72
    public static final int COL_PASSWORD = 2;
75
    public static final int COL_PASSWORD = 2;
73
    public static final int COL_DOMAIN = 3;
76
    public static final int COL_DOMAIN = 3;
74
    public static final int COL_REALM = 4;
77
    public static final int COL_REALM = 4;
78
    public static final int COL_MECHANISM = 5;
75
79
76
    private static final int COLUMN_COUNT = COLUMN_RESOURCE_NAMES.length;
80
    private static final int COLUMN_COUNT = COLUMN_RESOURCE_NAMES.length;
77
81
82
    public enum Mechanism {
83
        BASIC, KERBEROS;
84
    }
85
86
    private KerberosManager kerberosManager = new KerberosManager();
87
78
    /**
88
    /**
79
     * Default Constructor.
89
     * Default Constructor.
80
     */
90
     */
Lines 92-99 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
92
    /**
102
    /**
93
     * Update an authentication record.
103
     * Update an authentication record.
94
     */
104
     */
95
    public void set(int index, String url, String user, String pass, String domain, String realm) {
105
    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);
106
        Authorization auth = new Authorization(url, user, pass, domain, realm, mechanism);
97
        if (index >= 0) {
107
        if (index >= 0) {
98
            getAuthObjects().set(index, new TestElementProperty(auth.getName(), auth));
108
            getAuthObjects().set(index, new TestElementProperty(auth.getName(), auth));
99
        } else {
109
        } else {
Lines 188-193 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
188
        }
198
        }
189
        return null;
199
        return null;
190
    }
200
    }
201
    
202
    public boolean hasSubjectForUrl(URL url) {
203
        Authorization authorization = getAuthForURL(url);
204
        return authorization != null
205
                && authorization.getMechanism() == Mechanism.KERBEROS;
206
    }
207
    
208
    public Subject getSubjectForUrl(URL url) {
209
        Authorization authorization = getAuthForURL(url);
210
        if (authorization == null || getKerberosManager() == null) {
211
            log.warn("No kerberos manager found.");
212
            return null;
213
        }
214
        return getKerberosManager().getSubjectForUser(
215
                authorization.getUser(), authorization.getPass());
216
217
    }
191
218
192
    /** {@inheritDoc} */
219
    /** {@inheritDoc} */
193
    @Override
220
    @Override
Lines 258-264 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
258
                        domain = st.nextToken();
285
                        domain = st.nextToken();
259
                        realm = st.nextToken();
286
                        realm = st.nextToken();
260
                    }
287
                    }
261
                    Authorization auth = new Authorization(url, user, pass,domain,realm);
288
                    Mechanism mechanism = Mechanism.BASIC;
289
                    if (st.hasMoreTokens()){// Allow for old format file without mechanism support
290
                        mechanism = Mechanism.valueOf(st.nextToken());
291
                    }
292
                    Authorization auth = new Authorization(url, user, pass, domain, realm, mechanism);
262
                    getAuthObjects().addItem(auth);
293
                    getAuthObjects().addItem(auth);
263
                } catch (NoSuchElementException e) {
294
                } catch (NoSuchElementException e) {
264
                    log.error("Error parsing auth line: '" + line + "'");
295
                    log.error("Error parsing auth line: '" + line + "'");
Lines 292-295 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
292
        String protocol = url.getProtocol().toLowerCase(java.util.Locale.ENGLISH);
323
        String protocol = url.getProtocol().toLowerCase(java.util.Locale.ENGLISH);
293
        return protocol.equals(HTTPConstants.PROTOCOL_HTTP) || protocol.equals(HTTPConstants.PROTOCOL_HTTPS);
324
        return protocol.equals(HTTPConstants.PROTOCOL_HTTP) || protocol.equals(HTTPConstants.PROTOCOL_HTTPS);
294
    }
325
    }
326
327
    public KerberosManager getKerberosManager() {
328
        log.info("KerberosManager: " + kerberosManager);
329
        return kerberosManager;
330
    }
331
295
}
332
}
(-)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 (+146 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.testbeans.TestBean;
23
import org.apache.jorphan.logging.LoggingManager;
24
import org.apache.log.Logger;
25
26
public class KerberosManager extends ConfigTestElement implements Serializable,
27
        TestBean {
28
29
    private static final long serialVersionUID = 2L;
30
31
    private static final Logger log = LoggingManager.getLoggerForClass();
32
33
    private ConcurrentMap<String, Future<Subject>> subjects;
34
35
    public KerberosManager() {
36
        clearSubjects();
37
    }
38
39
    @Override
40
    public void clear() {
41
        super.clear();
42
        clearSubjects();
43
    }
44
45
    private void clearSubjects() {
46
        subjects = new ConcurrentHashMap<String, Future<Subject>>();
47
    }
48
49
    public Subject getSubjectForUser(final String username,
50
            final String password) {
51
        Callable<Subject> callable = new Callable<Subject>() {
52
53
            @Override
54
            public Subject call() throws Exception {
55
                LoginContext loginCtx;
56
                try {
57
                    loginCtx = new LoginContext("Client",
58
                            new LoginCallbackHandler(username, password));
59
                    loginCtx.login();
60
                    return loginCtx.getSubject();
61
                } catch (LoginException e) {
62
                    log.warn("Could not log in user " + username, e);
63
                }
64
                return null;
65
            }
66
        };
67
68
        FutureTask<Subject> task = new FutureTask<Subject>(callable);
69
        Future<Subject> subjectFuture = subjects.putIfAbsent(username, task);
70
        if (subjectFuture == null) {
71
            subjectFuture = task;
72
            task.run();
73
        }
74
        try {
75
            return subjectFuture.get();
76
        } catch (InterruptedException e1) {
77
            log.warn("Interrupted while getting subject for " + username, e1);
78
        } catch (ExecutionException e1) {
79
            log.warn(
80
                    "Execution of getting subject for " + username + " failed",
81
                    e1);
82
        }
83
        return null;
84
    }
85
86
    static private class LoginCallbackHandler implements CallbackHandler {
87
        private String password;
88
        private String username;
89
90
        public LoginCallbackHandler(final String username, final String password) {
91
            super();
92
            this.username = username;
93
            this.password = password;
94
        }
95
96
        @Override
97
        public void handle(Callback[] callbacks) throws IOException,
98
                UnsupportedCallbackException {
99
            for (Callback callback : callbacks) {
100
                if (callback instanceof NameCallback && username != null) {
101
                    NameCallback nc = (NameCallback) callback;
102
                    nc.setName(username);
103
                } else if (callback instanceof PasswordCallback) {
104
                    PasswordCallback pc = (PasswordCallback) callback;
105
                    pc.setPassword(password.toCharArray());
106
                } else {
107
                    /*
108
                     * throw new UnsupportedCallbackException( callback,
109
                     * "Unrecognized Callback");
110
                     */
111
                }
112
            }
113
        }
114
    }
115
    
116
    public String getKrb5Conf() {
117
        return System.getProperty("java.security.krb5.conf");
118
    }
119
120
    public void setKrb5Conf(String krb5Conf) {
121
        System.setProperty("java.security.krb5.conf", krb5Conf);
122
    }
123
124
    public boolean getKrb5Debug() {
125
        return Boolean.valueOf(System.getProperty("java.security.krb5.debug", "False"));
126
    }
127
128
    public void setKrb5Debug(boolean krb5Debug) {
129
        System.setProperty("sun.security.krb5.debug",
130
                Boolean.toString(krb5Debug));
131
    }
132
133
    public String getJaasConf() {
134
        return System.getProperty("java.security.auth.login.config");
135
    }
136
137
    public void setJaasConf(String jaasLocation) {
138
        System.setProperty("java.security.auth.login.config", jaasLocation);
139
    }
140
    
141
    @Override
142
    public String toString() {
143
        return "KerberosManager[jaas: " + getJaasConf() + ", krb5: " + getKrb5Conf() + ", debug: " + getKrb5Debug() +"]";
144
    }
145
146
}
(-)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/HTTPHC4Impl.java (-6 / +61 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-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
            }
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (-5 / +6 lines)
Lines 94-100 import org.apache.oro.text.regex.Perl5Matcher; Link Here
94
public abstract class HTTPSamplerBase extends AbstractSampler
94
public abstract class HTTPSamplerBase extends AbstractSampler
95
    implements TestStateListener, TestIterationListener, ThreadListener, HTTPConstantsInterface {
95
    implements TestStateListener, TestIterationListener, ThreadListener, HTTPConstantsInterface {
96
96
97
    private static final long serialVersionUID = 240L;
97
    private static final long serialVersionUID = 241L;
98
98
99
    private static final Logger log = LoggingManager.getLoggerForClass();
99
    private static final Logger log = LoggingManager.getLoggerForClass();
100
100
Lines 106-113 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
106
                    "org.apache.jmeter.protocol.http.gui.HeaderPanel",
106
                    "org.apache.jmeter.protocol.http.gui.HeaderPanel",
107
                    "org.apache.jmeter.protocol.http.gui.AuthPanel",
107
                    "org.apache.jmeter.protocol.http.gui.AuthPanel",
108
                    "org.apache.jmeter.protocol.http.gui.CacheManagerGui",
108
                    "org.apache.jmeter.protocol.http.gui.CacheManagerGui",
109
                    "org.apache.jmeter.protocol.http.gui.CookiePanel"}));
109
                    "org.apache.jmeter.protocol.http.gui.CookiePanel",}));
110
    
110
111
    //+ JMX names - do not change
111
    //+ JMX names - do not change
112
    public static final String ARGUMENTS = "HTTPsampler.Arguments"; // $NON-NLS-1$
112
    public static final String ARGUMENTS = "HTTPsampler.Arguments"; // $NON-NLS-1$
113
113
Lines 1854-1859 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
1854
    @Override
1854
    @Override
1855
    public boolean applies(ConfigTestElement configElement) {
1855
    public boolean applies(ConfigTestElement configElement) {
1856
        String guiClass = configElement.getProperty(TestElement.GUI_CLASS).getStringValue();
1856
        String guiClass = configElement.getProperty(TestElement.GUI_CLASS).getStringValue();
1857
        return APPLIABLE_CONFIG_CLASSES.contains(guiClass);
1857
        String testClass = configElement.getPropertyAsString(TestElement.TEST_CLASS);
1858
        return APPLIABLE_CONFIG_CLASSES.contains(guiClass) || APPLIABLE_CONFIG_CLASSES.contains(testClass);
1858
    }
1859
    }
1859
}
1860
}

Return to bug 53480