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 28-33 import org.apache.jmeter.protocol.http.control.AuthManager; Link Here
28
import org.apache.jmeter.protocol.http.control.CacheManager;
28
import org.apache.jmeter.protocol.http.control.CacheManager;
29
import org.apache.jmeter.protocol.http.control.CookieManager;
29
import org.apache.jmeter.protocol.http.control.CookieManager;
30
import org.apache.jmeter.protocol.http.control.HeaderManager;
30
import org.apache.jmeter.protocol.http.control.HeaderManager;
31
import org.apache.jmeter.protocol.http.control.KerberosManager;
31
import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
32
import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
32
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
33
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
33
import org.apache.jmeter.samplers.Interruptible;
34
import org.apache.jmeter.samplers.Interruptible;
Lines 117-122 public abstract class HTTPAbstractImpl implements Interruptible, HTTPConstantsIn Link Here
117
    }
118
    }
118
119
119
    /**
120
    /**
121
     * Incokes {@link HTTPSamplerBase#getKerberosManager()}
122
     */
123
    protected KerberosManager getKerberosManager() {
124
        return testElement.getKerberosManager();
125
    }
126
127
    /**
120
     * Invokes {@link HTTPSamplerBase#getHTTPFiles()}
128
     * Invokes {@link HTTPSamplerBase#getHTTPFiles()}
121
     */
129
     */
122
    protected HTTPFileArg[] getHTTPFiles() {
130
    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 99-104 import org.apache.jmeter.protocol.http.control.Authorization; Link Here
99
import org.apache.jmeter.protocol.http.control.CacheManager;
107
import org.apache.jmeter.protocol.http.control.CacheManager;
100
import org.apache.jmeter.protocol.http.control.CookieManager;
108
import org.apache.jmeter.protocol.http.control.CookieManager;
101
import org.apache.jmeter.protocol.http.control.HeaderManager;
109
import org.apache.jmeter.protocol.http.control.HeaderManager;
110
import org.apache.jmeter.protocol.http.control.KerberosManager;
102
import org.apache.jmeter.protocol.http.util.EncoderCache;
111
import org.apache.jmeter.protocol.http.util.EncoderCache;
103
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
112
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
104
import org.apache.jmeter.protocol.http.util.HTTPArgument;
113
import org.apache.jmeter.protocol.http.util.HTTPArgument;
Lines 164-170 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
164
     * This allows the defaults to be overridden if necessary from the properties file.
173
     * This allows the defaults to be overridden if necessary from the properties file.
165
     */
174
     */
166
    private static final HttpParams DEFAULT_HTTP_PARAMS;
175
    private static final HttpParams DEFAULT_HTTP_PARAMS;
167
    
176
177
    private static final Credentials USE_JAAS_CREDENTIALS = new NullCredentials();
178
168
    static {
179
    static {
169
        log.info("HTTP request retry count = "+RETRY_COUNT);
180
        log.info("HTTP request retry count = "+RETRY_COUNT);
170
        
181
        
Lines 282-288 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
282
                String entityBody = sendEntityData(( HttpEntityEnclosingRequestBase)httpRequest);
293
                String entityBody = sendEntityData(( HttpEntityEnclosingRequestBase)httpRequest);
283
                res.setQueryString(entityBody);
294
                res.setQueryString(entityBody);
284
            }
295
            }
285
            HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample
296
            HttpResponse httpResponse = executeRequest(httpClient, httpRequest, localContext, url);
286
297
287
            // Needs to be done after execute to pick up all the headers
298
            // Needs to be done after execute to pick up all the headers
288
            res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST)));
299
            res.setRequestHeaders(getConnectionHeaders((HttpRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST)));
Lines 372-377 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
372
        return res;
383
        return res;
373
    }
384
    }
374
385
386
    private HttpResponse executeRequest(final HttpClient httpClient,
387
            final HttpRequestBase httpRequest, final HttpContext localContext, final URL url)
388
            throws IOException, ClientProtocolException {
389
        AuthManager authManager = getAuthManager();
390
        if (authManager != null) {
391
            Authorization authorization = authManager.getAuthForURL(url);
392
            if (authorization != null) {
393
                if (authorization.getKerberos()) {
394
                    KerberosManager kerberosManager = getKerberosManager();
395
                    if (kerberosManager == null) {
396
                        log.error("no kerberos manager configured");
397
                        return null;
398
                    }
399
                    Subject subject = kerberosManager.getSubjectForUser(
400
                            authorization.getUser(), authorization.getPass());
401
                    try {
402
                        return Subject.doAs(subject,
403
                                new PrivilegedExceptionAction<HttpResponse>() {
404
405
                                    @Override
406
                                    public HttpResponse run() throws Exception {
407
                                        return httpClient.execute(httpRequest,
408
                                                localContext);
409
                                    }
410
                                });
411
                    } catch (PrivilegedActionException e) {
412
                        log.warn(
413
                                "Can't execute httpRequest with kerberos-subject",
414
                                e);
415
                        return null;
416
                    }
417
                }
418
            }
419
        }
420
        // perform the non-kerberos sample
421
        return httpClient.execute(httpRequest, localContext);
422
    }
423
424
    private static final class NullCredentials implements Credentials {
425
        @Override
426
        public String getPassword() {
427
            return null;
428
        }
429
430
        @Override
431
        public Principal getUserPrincipal() {
432
            return null;
433
        }
434
    }
435
375
    /**
436
    /**
376
     * Holder class for all fields that define an HttpClient instance;
437
     * Holder class for all fields that define an HttpClient instance;
377
     * used as the key to the ThreadLocal map of HttpClient instances.
438
     * used as the key to the ThreadLocal map of HttpClient instances.
Lines 733-743 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
733
                    String realm = auth.getRealm();
794
                    String realm = auth.getRealm();
734
                    String domain = auth.getDomain();
795
                    String domain = auth.getDomain();
735
                    if (log.isDebugEnabled()){
796
                    if (log.isDebugEnabled()){
736
                        log.debug(username + " > D="+domain+" R="+realm);
797
                        log.debug(username + " > D="+domain+" R="+realm + " K="+auth.getKerberos());
798
                    }
799
                    if (auth.getKerberos()) {
800
                        ((AbstractHttpClient) client).getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
801
                        credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS);
802
                    } else {
803
                        credentialsProvider.setCredentials(
804
                                new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
805
                                new NTCredentials(username, auth.getPass(), localHost, domain));
737
                    }
806
                    }
738
                    credentialsProvider.setCredentials(
739
                            new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
740
                            new NTCredentials(username, auth.getPass(), localHost, domain));
741
            } else {
807
            } else {
742
                credentialsProvider.clear();
808
                credentialsProvider.clear();
743
            }
809
            }
(-)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 96-102 import org.apache.oro.text.regex.Perl5Matcher; Link Here
96
public abstract class HTTPSamplerBase extends AbstractSampler
97
public abstract class HTTPSamplerBase extends AbstractSampler
97
    implements TestStateListener, TestIterationListener, ThreadListener, HTTPConstantsInterface {
98
    implements TestStateListener, TestIterationListener, ThreadListener, HTTPConstantsInterface {
98
99
99
    private static final long serialVersionUID = 240L;
100
    private static final long serialVersionUID = 241L;
100
101
101
    private static final Logger log = LoggingManager.getLoggerForClass();
102
    private static final Logger log = LoggingManager.getLoggerForClass();
102
103
Lines 108-115 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
108
                    "org.apache.jmeter.protocol.http.gui.HeaderPanel",
109
                    "org.apache.jmeter.protocol.http.gui.HeaderPanel",
109
                    "org.apache.jmeter.protocol.http.gui.AuthPanel",
110
                    "org.apache.jmeter.protocol.http.gui.AuthPanel",
110
                    "org.apache.jmeter.protocol.http.gui.CacheManagerGui",
111
                    "org.apache.jmeter.protocol.http.gui.CacheManagerGui",
111
                    "org.apache.jmeter.protocol.http.gui.CookiePanel"}));
112
                    "org.apache.jmeter.protocol.http.gui.CookiePanel",
112
    
113
                    "org.apache.jmeter.protocol.http.control.KerberosManager",}));
114
113
    //+ JMX names - do not change
115
    //+ JMX names - do not change
114
    public static final String ARGUMENTS = "HTTPsampler.Arguments"; // $NON-NLS-1$
116
    public static final String ARGUMENTS = "HTTPsampler.Arguments"; // $NON-NLS-1$
115
117
Lines 121-126 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
121
123
122
    public static final String HEADER_MANAGER = "HTTPSampler.header_manager"; // $NON-NLS-1$
124
    public static final String HEADER_MANAGER = "HTTPSampler.header_manager"; // $NON-NLS-1$
123
125
126
    public static final String KERBEROS_MANAGER = "HTTPSampler.kerberos_manager"; // $NON-NLS-1$
127
124
    public static final String DOMAIN = "HTTPSampler.domain"; // $NON-NLS-1$
128
    public static final String DOMAIN = "HTTPSampler.domain"; // $NON-NLS-1$
125
129
126
    public static final String PORT = "HTTPSampler.port"; // $NON-NLS-1$
130
    public static final String PORT = "HTTPSampler.port"; // $NON-NLS-1$
Lines 604-609 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
604
            setHeaderManager((HeaderManager) el);
608
            setHeaderManager((HeaderManager) el);
605
        } else if (el instanceof AuthManager) {
609
        } else if (el instanceof AuthManager) {
606
            setAuthManager((AuthManager) el);
610
            setAuthManager((AuthManager) el);
611
        } else if (el instanceof KerberosManager) {
612
            setKerberosManager((KerberosManager) el);
607
        } else {
613
        } else {
608
            super.addTestElement(el);
614
            super.addTestElement(el);
609
        }
615
        }
Lines 817-822 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
817
        return (CacheManager) getProperty(CACHE_MANAGER).getObjectValue();
823
        return (CacheManager) getProperty(CACHE_MANAGER).getObjectValue();
818
    }
824
    }
819
825
826
    public void setKerberosManager(KerberosManager value) {
827
        KerberosManager mgr = getKerberosManager();
828
        if (mgr != null) {
829
            log.warn("Existing KerberosManager " + mgr.getName() + " superseded by " + value.getName());
830
        }
831
        setProperty(new TestElementProperty(KERBEROS_MANAGER, value));
832
    }
833
834
    public KerberosManager getKerberosManager() {
835
        return (KerberosManager) getProperty(KERBEROS_MANAGER).getObjectValue();
836
    }
837
820
    public boolean isImageParser() {
838
    public boolean isImageParser() {
821
        return getPropertyAsBoolean(IMAGE_PARSER, false);
839
        return getPropertyAsBoolean(IMAGE_PARSER, false);
822
    }
840
    }
Lines 1878-1883 public abstract class HTTPSamplerBase extends AbstractSampler Link Here
1878
    @Override
1896
    @Override
1879
    public boolean applies(ConfigTestElement configElement) {
1897
    public boolean applies(ConfigTestElement configElement) {
1880
        String guiClass = configElement.getProperty(TestElement.GUI_CLASS).getStringValue();
1898
        String guiClass = configElement.getProperty(TestElement.GUI_CLASS).getStringValue();
1881
        return APPLIABLE_CONFIG_CLASSES.contains(guiClass);
1899
        String testClass = configElement.getPropertyAsString(TestElement.TEST_CLASS);
1900
        return APPLIABLE_CONFIG_CLASSES.contains(guiClass) || APPLIABLE_CONFIG_CLASSES.contains(testClass);
1882
    }
1901
    }
1883
}
1902
}

Return to bug 53480