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

(-)a/bin/jmeter.properties (-1 / +5 lines)
Lines 392-397 remote_hosts=127.0.0.1 Link Here
392
# for SPNEGO authentication
392
# for SPNEGO authentication
393
#kerberos.spnego.strip_port=true
393
#kerberos.spnego.strip_port=true
394
394
395
# Should credentials be delegated to webservers when using
396
# SPNEGO authentication
397
#kerberos.spnego.delegate_cred=false
398
395
#---------------------------------------------------------------------------
399
#---------------------------------------------------------------------------
396
# Apache HttpComponents HTTPClient configuration (HTTPClient4)
400
# Apache HttpComponents HTTPClient configuration (HTTPClient4)
397
#---------------------------------------------------------------------------
401
#---------------------------------------------------------------------------
Lines 1294-1297 jmeter.reportgenerator.apdex_tolerated_threshold=1500 Link Here
1294
1298
1295
# Switch that allows using Local documentation opened in JMeter GUI
1299
# Switch that allows using Local documentation opened in JMeter GUI
1296
# By default we use Online documentation opened in Browser
1300
# By default we use Online documentation opened in Browser
1297
#help.local=false
1301
#help.local=false
(-)a/src/protocol/http/org/apache/jmeter/protocol/http/control/DelegatingKerberosScheme.java (+66 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.protocol.http.control;
20
21
import org.apache.http.auth.Credentials;
22
import org.apache.http.auth.KerberosCredentials;
23
import org.apache.http.impl.auth.KerberosScheme;
24
import org.ietf.jgss.GSSContext;
25
import org.ietf.jgss.GSSCredential;
26
import org.ietf.jgss.GSSException;
27
import org.ietf.jgss.GSSManager;
28
import org.ietf.jgss.GSSName;
29
import org.ietf.jgss.Oid;
30
31
public class DelegatingKerberosScheme extends KerberosScheme {
32
    public DelegatingKerberosScheme(final boolean stripPort, final boolean useCanonicalHostName) {
33
        super(stripPort, useCanonicalHostName);
34
    }
35
36
    @Override
37
    protected byte[] generateGSSToken(
38
            final byte[] input, final Oid oid, final String authServer,
39
            final Credentials credentials) throws GSSException {
40
        final GSSManager manager = getManager();
41
        final GSSName serverName = manager.createName("HTTP@" + authServer, GSSName.NT_HOSTBASED_SERVICE);
42
43
        final GSSCredential gssCredential;
44
        if (credentials instanceof KerberosCredentials) {
45
            gssCredential = ((KerberosCredentials) credentials).getGSSCredential();
46
        } else {
47
            gssCredential = null;
48
        }
49
50
        final GSSContext gssContext = createDelegatingGSSContext(manager, oid, serverName, gssCredential);
51
        if (input != null) {
52
            return gssContext.initSecContext(input, 0, input.length);
53
        } else {
54
            return gssContext.initSecContext(new byte[] {}, 0, 0);
55
        }
56
    }
57
58
    GSSContext createDelegatingGSSContext(final GSSManager manager, final Oid oid, final GSSName serverName,
59
            final GSSCredential gssCredential) throws GSSException {
60
        final GSSContext gssContext = manager.createContext(serverName.canonicalize(oid), oid, gssCredential,
61
                GSSContext.DEFAULT_LIFETIME);
62
        gssContext.requestMutualAuth(true);
63
        gssContext.requestCredDeleg(true);
64
        return gssContext;
65
    }
66
}
(-)a/src/protocol/http/org/apache/jmeter/protocol/http/control/DelegatingSPNegoScheme.java (+66 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.protocol.http.control;
20
21
import org.apache.http.auth.Credentials;
22
import org.apache.http.auth.KerberosCredentials;
23
import org.apache.http.impl.auth.SPNegoScheme;
24
import org.ietf.jgss.GSSContext;
25
import org.ietf.jgss.GSSCredential;
26
import org.ietf.jgss.GSSException;
27
import org.ietf.jgss.GSSManager;
28
import org.ietf.jgss.GSSName;
29
import org.ietf.jgss.Oid;
30
31
public class DelegatingSPNegoScheme extends SPNegoScheme {
32
    public DelegatingSPNegoScheme(final boolean stripPort, final boolean useCanonicalHostName) {
33
        super(stripPort, useCanonicalHostName);
34
    }
35
36
    @Override
37
    protected byte[] generateGSSToken(
38
            final byte[] input, final Oid oid, final String authServer,
39
            final Credentials credentials) throws GSSException {
40
        final GSSManager manager = getManager();
41
        final GSSName serverName = manager.createName("HTTP@" + authServer, GSSName.NT_HOSTBASED_SERVICE);
42
43
        final GSSCredential gssCredential;
44
        if (credentials instanceof KerberosCredentials) {
45
            gssCredential = ((KerberosCredentials) credentials).getGSSCredential();
46
        } else {
47
            gssCredential = null;
48
        }
49
50
        final GSSContext gssContext = createDelegatingGSSContext(manager, oid, serverName, gssCredential);
51
        if (input != null) {
52
            return gssContext.initSecContext(input, 0, input.length);
53
        } else {
54
            return gssContext.initSecContext(new byte[] {}, 0, 0);
55
        }
56
    }
57
58
    GSSContext createDelegatingGSSContext(final GSSManager manager, final Oid oid, final GSSName serverName,
59
            final GSSCredential gssCredential) throws GSSException {
60
        final GSSContext gssContext = manager.createContext(serverName.canonicalize(oid), oid, gssCredential,
61
                GSSContext.DEFAULT_LIFETIME);
62
        gssContext.requestMutualAuth(true);
63
        gssContext.requestCredDeleg(true);
64
        return gssContext;
65
    }
66
}
(-)a/src/protocol/http/org/apache/jmeter/protocol/http/control/DynamicKerberosSchemeFactory.java (-2 / +20 lines)
Lines 22-27 import org.apache.http.auth.AuthScheme; Link Here
22
import org.apache.http.impl.auth.KerberosScheme;
22
import org.apache.http.impl.auth.KerberosScheme;
23
import org.apache.http.impl.auth.KerberosSchemeFactory;
23
import org.apache.http.impl.auth.KerberosSchemeFactory;
24
import org.apache.http.protocol.HttpContext;
24
import org.apache.http.protocol.HttpContext;
25
import org.apache.jmeter.util.JMeterUtils;
26
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
25
29
26
/**
30
/**
27
 * Extends {@link KerberosSchemeFactory} to provide ability to customize stripPort
31
 * Extends {@link KerberosSchemeFactory} to provide ability to customize stripPort
Lines 30-35 import org.apache.http.protocol.HttpContext; Link Here
30
 */
34
 */
31
public class DynamicKerberosSchemeFactory extends KerberosSchemeFactory {
35
public class DynamicKerberosSchemeFactory extends KerberosSchemeFactory {
32
    static final String CONTEXT_ATTRIBUTE_STRIP_PORT = "__jmeter.K_SP__";
36
    static final String CONTEXT_ATTRIBUTE_STRIP_PORT = "__jmeter.K_SP__";
37
    static final String CONTEXT_ATTRIBUTE_DELEGATE_CRED = "__jmeter.K_DT__";
38
    static final boolean DELEGATE_CRED = JMeterUtils.getPropDefault("kerberos.spnego.delegate_cred", false);
39
    private static final Logger log = LoggerFactory.getLogger(DynamicKerberosSchemeFactory.class);
33
40
34
    /**
41
    /**
35
     * Constructor for DynamicKerberosSchemeFactory
42
     * Constructor for DynamicKerberosSchemeFactory
Lines 43-50 public class DynamicKerberosSchemeFactory extends KerberosSchemeFactory { Link Here
43
50
44
    @Override
51
    @Override
45
    public AuthScheme create(final HttpContext context) {
52
    public AuthScheme create(final HttpContext context) {
46
        Boolean localStripPort = (Boolean) context.getAttribute(CONTEXT_ATTRIBUTE_STRIP_PORT);
53
        boolean stripPort = isEnabled(context.getAttribute(CONTEXT_ATTRIBUTE_STRIP_PORT), isStripPort());
47
        Boolean stripPort = localStripPort != null ? localStripPort : isStripPort();
54
        if (isEnabled(context.getAttribute(CONTEXT_ATTRIBUTE_DELEGATE_CRED), DELEGATE_CRED)) {
55
            log.debug("Use DelegatingKerberosScheme");
56
            return new DelegatingKerberosScheme(stripPort, isStripPort());
57
        }
58
        log.debug("Use KerberosScheme");
48
        return new KerberosScheme(stripPort, isUseCanonicalHostname());
59
        return new KerberosScheme(stripPort, isUseCanonicalHostname());
49
    }
60
    }
61
62
    private boolean isEnabled(Object contextAttribute, boolean defaultValue) {
63
        if (contextAttribute instanceof Boolean) {
64
            return ((Boolean) contextAttribute).booleanValue();
65
        }
66
        return defaultValue;
67
    }
50
}
68
}
(-)a/src/protocol/http/org/apache/jmeter/protocol/http/control/DynamicSPNegoSchemeFactory.java (+68 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.protocol.http.control;
20
21
import org.apache.http.auth.AuthScheme;
22
import org.apache.http.impl.auth.SPNegoScheme;
23
import org.apache.http.impl.auth.SPNegoSchemeFactory;
24
import org.apache.http.protocol.HttpContext;
25
import org.apache.jmeter.util.JMeterUtils;
26
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29
30
/**
31
 * Extends {@link SPNegoSchemeFactory} to provide ability to customize stripPort
32
 * setting in {@link SPNegoScheme} based on {@link HttpContext}
33
 * @since 4.1
34
 */
35
public class DynamicSPNegoSchemeFactory extends SPNegoSchemeFactory {
36
    static final String CONTEXT_ATTRIBUTE_STRIP_PORT = "__jmeter.K_SP__";
37
    static final String CONTEXT_ATTRIBUTE_DELEGATE_CRED = "__jmeter.K_DT__";
38
    static final boolean DELEGATE_CRED = JMeterUtils.getPropDefault("kerberos.spnego.delegate_cred", false);
39
    private static final Logger log = LoggerFactory.getLogger(DynamicSPNegoSchemeFactory.class);
40
41
    /**
42
     * Constructor for DynamicSPNegoSchemeFactory
43
     * @param stripPort flag, whether port should be stripped from SPN
44
     * @param useCanonicalHostname flag, whether SPN should use the canonical hostname
45
     * @since 4.0
46
     */
47
    public DynamicSPNegoSchemeFactory(final boolean stripPort, final boolean useCanonicalHostname) {
48
        super(stripPort, useCanonicalHostname);
49
    }
50
51
    @Override
52
    public AuthScheme create(final HttpContext context) {
53
        boolean stripPort = isEnabled(context.getAttribute(CONTEXT_ATTRIBUTE_STRIP_PORT), isStripPort());
54
        if (isEnabled(context.getAttribute(CONTEXT_ATTRIBUTE_DELEGATE_CRED), DELEGATE_CRED)) {
55
            log.debug("Use DelegatingSPNegoScheme");
56
            return new DelegatingSPNegoScheme(stripPort, isStripPort());
57
        }
58
        log.debug("Use SPNegoScheme");
59
        return new SPNegoScheme(stripPort, isUseCanonicalHostname());
60
    }
61
62
    private boolean isEnabled(Object contextAttribute, boolean defaultValue) {
63
        if (contextAttribute instanceof Boolean) {
64
            return ((Boolean) contextAttribute).booleanValue();
65
        }
66
        return defaultValue;
67
    }
68
}
(-)a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (-2 / +3 lines)
Lines 110-116 import org.apache.http.impl.auth.DigestScheme; Link Here
110
import org.apache.http.impl.auth.DigestSchemeFactory;
110
import org.apache.http.impl.auth.DigestSchemeFactory;
111
import org.apache.http.impl.auth.KerberosScheme;
111
import org.apache.http.impl.auth.KerberosScheme;
112
import org.apache.http.impl.auth.NTLMSchemeFactory;
112
import org.apache.http.impl.auth.NTLMSchemeFactory;
113
import org.apache.http.impl.auth.SPNegoSchemeFactory;
114
import org.apache.http.impl.client.BasicAuthCache;
113
import org.apache.http.impl.client.BasicAuthCache;
115
import org.apache.http.impl.client.BasicCredentialsProvider;
114
import org.apache.http.impl.client.BasicCredentialsProvider;
116
import org.apache.http.impl.client.CloseableHttpClient;
115
import org.apache.http.impl.client.CloseableHttpClient;
Lines 142-147 import org.apache.jmeter.protocol.http.control.Authorization; Link Here
142
import org.apache.jmeter.protocol.http.control.CacheManager;
141
import org.apache.jmeter.protocol.http.control.CacheManager;
143
import org.apache.jmeter.protocol.http.control.CookieManager;
142
import org.apache.jmeter.protocol.http.control.CookieManager;
144
import org.apache.jmeter.protocol.http.control.DynamicKerberosSchemeFactory;
143
import org.apache.jmeter.protocol.http.control.DynamicKerberosSchemeFactory;
144
import org.apache.jmeter.protocol.http.control.DynamicSPNegoSchemeFactory;
145
import org.apache.jmeter.protocol.http.control.HeaderManager;
145
import org.apache.jmeter.protocol.http.control.HeaderManager;
146
import org.apache.jmeter.protocol.http.sampler.hc.LaxDeflateInputStream;
146
import org.apache.jmeter.protocol.http.sampler.hc.LaxDeflateInputStream;
147
import org.apache.jmeter.protocol.http.sampler.hc.LazyLayeredConnectionSocketFactory;
147
import org.apache.jmeter.protocol.http.sampler.hc.LazyLayeredConnectionSocketFactory;
Lines 1030-1036 public class HTTPHC4Impl extends HTTPHCAbstractImpl { Link Here
1030
                        .register(AuthSchemes.BASIC, new BasicSchemeFactory())
1030
                        .register(AuthSchemes.BASIC, new BasicSchemeFactory())
1031
                        .register(AuthSchemes.DIGEST, new DigestSchemeFactory())
1031
                        .register(AuthSchemes.DIGEST, new DigestSchemeFactory())
1032
                        .register(AuthSchemes.NTLM, new NTLMSchemeFactory())
1032
                        .register(AuthSchemes.NTLM, new NTLMSchemeFactory())
1033
                        .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory())
1033
                        .register(AuthSchemes.SPNEGO, new DynamicSPNegoSchemeFactory(
1034
                                AuthManager.STRIP_PORT, AuthManager.USE_CANONICAL_HOST_NAME))
1034
                        .register(AuthSchemes.KERBEROS, new DynamicKerberosSchemeFactory(
1035
                        .register(AuthSchemes.KERBEROS, new DynamicKerberosSchemeFactory(
1035
                                AuthManager.STRIP_PORT, AuthManager.USE_CANONICAL_HOST_NAME))
1036
                                AuthManager.STRIP_PORT, AuthManager.USE_CANONICAL_HOST_NAME))
1036
                        .build();
1037
                        .build();
(-)a/xdocs/usermanual/component_reference.xml (+3 lines)
Lines 3644-3649 Look at the two sample configuration files (<code>krb5.conf</code> and <code>jaa Link Here
3644
for references to more documentation, and tweak them to match your Kerberos configuration.
3644
for references to more documentation, and tweak them to match your Kerberos configuration.
3645
</p>
3645
</p>
3646
<p>
3646
<p>
3647
Delegation of credentials is disabled by default for SPNEGO. If you want to enable it, you can do so by setting the property <code>kerberos.spnego.delegate_cred</code> to <code>true</code>.
3648
</p>
3649
<p>
3647
When generating a SPN for Kerberos SPNEGO authentication IE and Firefox will omit the port number
3650
When generating a SPN for Kerberos SPNEGO authentication IE and Firefox will omit the port number
3648
from the URL. Chrome has an option (<code>--enable-auth-negotiate-port</code>) to include the port
3651
from the URL. Chrome has an option (<code>--enable-auth-negotiate-port</code>) to include the port
3649
number if it differs from the standard ones (<code>80</code> and <code>443</code>). That behavior
3652
number if it differs from the standard ones (<code>80</code> and <code>443</code>). That behavior
(-)a/xdocs/usermanual/properties_reference.xml (+4 lines)
Lines 463-468 JMETER-SERVER</source> Link Here
463
    Should port be stripped from urls before constructing SPNs for SPNEGO authentication.
463
    Should port be stripped from urls before constructing SPNs for SPNEGO authentication.
464
    Defaults to: <code>true</code>
464
    Defaults to: <code>true</code>
465
</property>
465
</property>
466
<property name="kerberos.spnego.delegate_cred">
467
    Should SPNEGO authentication should use delegation of credentials.
468
    Defaults to: <code>false</code>
469
</property>
466
</properties>
470
</properties>
467
</section>
471
</section>
468
<section name="&sect-num;.12 Apache HttpClient logging examples" anchor="httpclient_logging_examples">
472
<section name="&sect-num;.12 Apache HttpClient logging examples" anchor="httpclient_logging_examples">

Return to bug 62462