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

(-)a/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java (-4 / +10 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
        "kerberos",      //$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-77 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_KERBEROS = 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;
77
79
Lines 92-99 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
92
    /**
94
    /**
93
     * Update an authentication record.
95
     * Update an authentication record.
94
     */
96
     */
95
    public void set(int index, String url, String user, String pass, String domain, String realm) {
97
    public void set(int index, String url, String user, String pass, String domain, String realm, boolean kerberos) {
96
        Authorization auth = new Authorization(url, user, pass, domain, realm);
98
        Authorization auth = new Authorization(url, user, pass, domain, realm, kerberos);
97
        if (index >= 0) {
99
        if (index >= 0) {
98
            getAuthObjects().set(index, new TestElementProperty(auth.getName(), auth));
100
            getAuthObjects().set(index, new TestElementProperty(auth.getName(), auth));
99
        } else {
101
        } else {
Lines 254-264 public class AuthManager extends ConfigTestElement implements Serializable { Link Here
254
                    String pass = st.nextToken();
256
                    String pass = st.nextToken();
255
                    String domain = "";
257
                    String domain = "";
256
                    String realm = "";
258
                    String realm = "";
259
                    boolean kerberos = false;
257
                    if (st.hasMoreTokens()){// Allow for old format file without the extra columnns
260
                    if (st.hasMoreTokens()){// Allow for old format file without the extra columnns
258
                        domain = st.nextToken();
261
                        domain = st.nextToken();
259
                        realm = st.nextToken();
262
                        realm = st.nextToken();
260
                    }
263
                    }
261
                    Authorization auth = new Authorization(url, user, pass,domain,realm);
264
                    if (st.hasMoreTokens()){// Allow for old format file without kerberos support
265
                        kerberos = Boolean.valueOf(st.nextToken());
266
                    }
267
                    Authorization auth = new Authorization(url, user, pass,domain,realm,kerberos);
262
                    getAuthObjects().addItem(auth);
268
                    getAuthObjects().addItem(auth);
263
                } catch (NoSuchElementException e) {
269
                } catch (NoSuchElementException e) {
264
                    log.error("Error parsing auth line: '" + line + "'");
270
                    log.error("Error parsing auth line: '" + line + "'");
(-)a/src/protocol/http/org/apache/jmeter/protocol/http/control/Authorization.java (-4 / +15 lines)
Lines 30-36 import org.apache.jmeter.testelement.AbstractTestElement; Link Here
30
 */
30
 */
31
public class Authorization extends AbstractTestElement implements Serializable {
31
public class Authorization extends AbstractTestElement implements Serializable {
32
32
33
    private static final long serialVersionUID = 240L;
33
    private static final long serialVersionUID = 241L;
34
34
35
    private static final String URL = "Authorization.url"; // $NON-NLS-1$
35
    private static final String URL = "Authorization.url"; // $NON-NLS-1$
36
36
Lines 42-58 public class Authorization extends AbstractTestElement implements Serializable { Link Here
42
42
43
    private static final String REALM = "Authorization.realm"; // $NON-NLS-1$
43
    private static final String REALM = "Authorization.realm"; // $NON-NLS-1$
44
44
45
    private static final String KERBEROS = "Authorization.kerberos"; // $NON-NLS-1$
46
45
    private static final String TAB = "\t"; // $NON-NLS-1$
47
    private static final String TAB = "\t"; // $NON-NLS-1$
46
48
47
    /**
49
    /**
48
     * create the authorization
50
     * create the authorization
49
     */
51
     */
50
    Authorization(String url, String user, String pass, String domain, String realm) {
52
    Authorization(String url, String user, String pass, String domain, String realm, boolean kerberos) {
51
        setURL(url);
53
        setURL(url);
52
        setUser(user);
54
        setUser(user);
53
        setPass(pass);
55
        setPass(pass);
54
        setDomain(domain);
56
        setDomain(domain);
55
        setRealm(realm);
57
        setRealm(realm);
58
        setKerberos(kerberos);
56
    }
59
    }
57
60
58
    public boolean expectsModification() {
61
    public boolean expectsModification() {
Lines 60-66 public class Authorization extends AbstractTestElement implements Serializable { Link Here
60
    }
63
    }
61
64
62
    public Authorization() {
65
    public Authorization() {
63
        this("","","","","");
66
        this("","","","","", false);
64
    }
67
    }
65
68
66
    public void addConfigElement(ConfigElement config) {
69
    public void addConfigElement(ConfigElement config) {
Lines 106-115 public class Authorization extends AbstractTestElement implements Serializable { Link Here
106
        setProperty(REALM, realm);
109
        setProperty(REALM, realm);
107
    }
110
    }
108
111
112
    public boolean getKerberos() {
113
        return getPropertyAsBoolean(KERBEROS);
114
    }
115
116
    public void setKerberos(boolean kerberos) {
117
        setProperty(KERBEROS, kerberos);
118
    }
119
109
    // Used for saving entries to a file
120
    // Used for saving entries to a file
110
    @Override
121
    @Override
111
    public String toString() {
122
    public String toString() {
112
        return getURL() + TAB + getUser() + TAB + getPass() + TAB + getDomain() + TAB + getRealm();
123
        return getURL() + TAB + getUser() + TAB + getPass() + TAB + getDomain() + TAB + getRealm() + TAB + getKerberos();
113
    }
124
    }
114
125
115
    public String toBasicHeader(){
126
    public String toBasicHeader(){
(-)a/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
}
(-)a/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
}
(-)a/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
(-)a/src/protocol/http/org/apache/jmeter/protocol/http/gui/AuthPanel.java (-1 / +7 lines)
Lines 57-63 import org.apache.log.Logger; Link Here
57
 * user selects.
57
 * user selects.
58
 */
58
 */
59
public class AuthPanel extends AbstractConfigGui implements ActionListener {
59
public class AuthPanel extends AbstractConfigGui implements ActionListener {
60
    private static final long serialVersionUID = -9214884465261470761L;
60
61
    private static final long serialVersionUID = -378312656300713636L;
61
62
62
    private static final Logger log = LoggingManager.getLoggerForClass();
63
    private static final Logger log = LoggingManager.getLoggerForClass();
63
64
Lines 357-362 public class AuthPanel extends AbstractConfigGui implements ActionListener { Link Here
357
                    return auth.getDomain();
358
                    return auth.getDomain();
358
                case AuthManager.COL_REALM:
359
                case AuthManager.COL_REALM:
359
                    return auth.getRealm();
360
                    return auth.getRealm();
361
                case AuthManager.COL_KERBEROS:
362
                	return auth.getKerberos();
360
                default:
363
                default:
361
                    return null;
364
                    return null;
362
            }
365
            }
Lines 382-387 public class AuthPanel extends AbstractConfigGui implements ActionListener { Link Here
382
                case AuthManager.COL_REALM:
385
                case AuthManager.COL_REALM:
383
                    auth.setRealm((String) value);
386
                    auth.setRealm((String) value);
384
                    break;
387
                    break;
388
                case AuthManager.COL_KERBEROS:
389
                    auth.setKerberos((Boolean) value);
390
                    break;
385
                default:
391
                default:
386
                    break;
392
                    break;
387
            }
393
            }
(-)a/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() {
(-)a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (-6 / +72 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 100-105 import org.apache.jmeter.protocol.http.control.Authorization; Link Here
100
import org.apache.jmeter.protocol.http.control.CacheManager;
108
import org.apache.jmeter.protocol.http.control.CacheManager;
101
import org.apache.jmeter.protocol.http.control.CookieManager;
109
import org.apache.jmeter.protocol.http.control.CookieManager;
102
import org.apache.jmeter.protocol.http.control.HeaderManager;
110
import org.apache.jmeter.protocol.http.control.HeaderManager;
111
import org.apache.jmeter.protocol.http.control.KerberosManager;
103
import org.apache.jmeter.protocol.http.util.EncoderCache;
112
import org.apache.jmeter.protocol.http.util.EncoderCache;
104
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
113
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
105
import org.apache.jmeter.protocol.http.util.HTTPArgument;
114
import org.apache.jmeter.protocol.http.util.HTTPArgument;
Lines 167-173 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
167
     * This allows the defaults to be overridden if necessary from the properties file.
176
     * This allows the defaults to be overridden if necessary from the properties file.
168
     */
177
     */
169
    private static final HttpParams DEFAULT_HTTP_PARAMS;
178
    private static final HttpParams DEFAULT_HTTP_PARAMS;
170
    
179
180
    private static final Credentials USE_JAAS_CREDENTIALS = new NullCredentials();
181
171
    static {
182
    static {
172
        log.info("HTTP request retry count = "+RETRY_COUNT);
183
        log.info("HTTP request retry count = "+RETRY_COUNT);
173
        
184
        
Lines 275-281 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
275
        try {
286
        try {
276
            currentRequest = httpRequest;
287
            currentRequest = httpRequest;
277
            handleMethod(method, res, httpRequest, localContext);
288
            handleMethod(method, res, httpRequest, localContext);
278
            HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample
289
            HttpResponse httpResponse = executeRequest(httpClient, httpRequest, localContext, url);
279
290
280
            // Needs to be done after execute to pick up all the headers
291
            // Needs to be done after execute to pick up all the headers
281
            res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST)));
292
            res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST)));
Lines 365-370 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
365
        return res;
376
        return res;
366
    }
377
    }
367
378
379
    private HttpResponse executeRequest(final HttpClient httpClient,
380
            final HttpRequestBase httpRequest, final HttpContext localContext, final URL url)
381
            throws IOException, ClientProtocolException {
382
        AuthManager authManager = getAuthManager();
383
        if (authManager != null) {
384
            Authorization authorization = authManager.getAuthForURL(url);
385
            if (authorization != null) {
386
                if (authorization.getKerberos()) {
387
                    KerberosManager kerberosManager = getKerberosManager();
388
                    if (kerberosManager == null) {
389
                        log.error("no kerberos manager configured");
390
                        return null;
391
                    }
392
                    Subject subject = kerberosManager.getSubjectForUser(
393
                            authorization.getUser(), authorization.getPass());
394
                    try {
395
                        return Subject.doAs(subject,
396
                                new PrivilegedExceptionAction<HttpResponse>() {
397
398
                                    @Override
399
                                    public HttpResponse run() throws Exception {
400
                                        return httpClient.execute(httpRequest,
401
                                                localContext);
402
                                    }
403
                                });
404
                    } catch (PrivilegedActionException e) {
405
                        log.warn(
406
                                "Can't execute httpRequest with kerberos-subject",
407
                                e);
408
                        return null;
409
                    }
410
                }
411
            }
412
        }
413
        // perform the non-kerberos sample
414
        return httpClient.execute(httpRequest, localContext);
415
    }
416
417
    private static final class NullCredentials implements Credentials {
418
        @Override
419
        public String getPassword() {
420
            return null;
421
        }
422
423
        @Override
424
        public Principal getUserPrincipal() {
425
            return null;
426
        }
427
    }
428
368
    /**
429
    /**
369
     * Calls sendPostData if method is POST and sendEntityData if method is PUT or PATCH
430
     * Calls sendPostData if method is POST and sendEntityData if method is PUT or PATCH
370
     * Field HTTPSampleResult#queryString of result is modified in the 2 cases
431
     * Field HTTPSampleResult#queryString of result is modified in the 2 cases
Lines 790-800 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
790
                    String realm = auth.getRealm();
851
                    String realm = auth.getRealm();
791
                    String domain = auth.getDomain();
852
                    String domain = auth.getDomain();
792
                    if (log.isDebugEnabled()){
853
                    if (log.isDebugEnabled()){
793
                        log.debug(username + " > D="+domain+" R="+realm);
854
                        log.debug(username + " > D="+domain+" R="+realm + " K="+auth.getKerberos());
855
                    }
856
                    if (auth.getKerberos()) {
857
                        ((AbstractHttpClient) client).getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
858
                        credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS);
859
                    } else {
860
                        credentialsProvider.setCredentials(
861
                                new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
862
                                new NTCredentials(username, auth.getPass(), localHost, domain));
794
                    }
863
                    }
795
                    credentialsProvider.setCredentials(
796
                            new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
797
                            new NTCredentials(username, auth.getPass(), localHost, domain));
798
            } else {
864
            } else {
799
                credentialsProvider.clear();
865
                credentialsProvider.clear();
800
            }
866
            }
(-)a/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