Search in sources :

Example 26 with TestSecurityConfig

use of org.apache.kafka.common.security.TestSecurityConfig in project kafka by apache.

the class AbstractConfigTest method testValuesWithPrefixAllOrNothing.

@Test
public void testValuesWithPrefixAllOrNothing() {
    String prefix1 = "prefix1.";
    String prefix2 = "prefix2.";
    Properties props = new Properties();
    props.put("sasl.mechanism", "PLAIN");
    props.put("prefix1.sasl.mechanism", "GSSAPI");
    props.put("prefix1.sasl.kerberos.kinit.cmd", "/usr/bin/kinit2");
    props.put("prefix1.ssl.truststore.location", "my location");
    props.put("sasl.kerberos.service.name", "service name");
    props.put("ssl.keymanager.algorithm", "algorithm");
    TestSecurityConfig config = new TestSecurityConfig(props);
    Map<String, Object> valuesWithPrefixAllOrNothing1 = config.valuesWithPrefixAllOrNothing(prefix1);
    // All prefixed values are there
    assertEquals("GSSAPI", valuesWithPrefixAllOrNothing1.get("sasl.mechanism"));
    assertEquals("/usr/bin/kinit2", valuesWithPrefixAllOrNothing1.get("sasl.kerberos.kinit.cmd"));
    assertEquals("my location", valuesWithPrefixAllOrNothing1.get("ssl.truststore.location"));
    // Non-prefixed values are missing
    assertFalse(valuesWithPrefixAllOrNothing1.containsKey("sasl.kerberos.service.name"));
    assertFalse(valuesWithPrefixAllOrNothing1.containsKey("ssl.keymanager.algorithm"));
    Map<String, Object> valuesWithPrefixAllOrNothing2 = config.valuesWithPrefixAllOrNothing(prefix2);
    assertTrue(valuesWithPrefixAllOrNothing2.containsKey("sasl.kerberos.service.name"));
    assertTrue(valuesWithPrefixAllOrNothing2.containsKey("ssl.keymanager.algorithm"));
}
Also used : TestSecurityConfig(org.apache.kafka.common.security.TestSecurityConfig) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 27 with TestSecurityConfig

use of org.apache.kafka.common.security.TestSecurityConfig in project kafka by apache.

the class SslFactoryTest method testPemReconfiguration.

@Test
public void testPemReconfiguration() throws Exception {
    Properties props = new Properties();
    props.putAll(sslConfigsBuilder(Mode.SERVER).createNewTrustStore(null).usePem(true).build());
    TestSecurityConfig sslConfig = new TestSecurityConfig(props);
    SslFactory sslFactory = new SslFactory(Mode.SERVER);
    sslFactory.configure(sslConfig.values());
    SslEngineFactory sslEngineFactory = sslFactory.sslEngineFactory();
    assertNotNull(sslEngineFactory, "SslEngineFactory not created");
    props.put("some.config", "some.value");
    sslConfig = new TestSecurityConfig(props);
    sslFactory.reconfigure(sslConfig.values());
    assertSame(sslEngineFactory, sslFactory.sslEngineFactory(), "SslEngineFactory recreated unnecessarily");
    props.put(SslConfigs.SSL_KEYSTORE_KEY_CONFIG, new Password(((Password) props.get(SslConfigs.SSL_KEYSTORE_KEY_CONFIG)).value() + " "));
    sslConfig = new TestSecurityConfig(props);
    sslFactory.reconfigure(sslConfig.values());
    assertNotSame(sslEngineFactory, sslFactory.sslEngineFactory(), "SslEngineFactory not recreated");
    sslEngineFactory = sslFactory.sslEngineFactory();
    props.put(SslConfigs.SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG, new Password(((Password) props.get(SslConfigs.SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG)).value() + " "));
    sslConfig = new TestSecurityConfig(props);
    sslFactory.reconfigure(sslConfig.values());
    assertNotSame(sslEngineFactory, sslFactory.sslEngineFactory(), "SslEngineFactory not recreated");
    sslEngineFactory = sslFactory.sslEngineFactory();
    props.put(SslConfigs.SSL_TRUSTSTORE_CERTIFICATES_CONFIG, new Password(((Password) props.get(SslConfigs.SSL_TRUSTSTORE_CERTIFICATES_CONFIG)).value() + " "));
    sslConfig = new TestSecurityConfig(props);
    sslFactory.reconfigure(sslConfig.values());
    assertNotSame(sslEngineFactory, sslFactory.sslEngineFactory(), "SslEngineFactory not recreated");
    sslEngineFactory = sslFactory.sslEngineFactory();
}
Also used : SslEngineFactory(org.apache.kafka.common.security.auth.SslEngineFactory) TestSecurityConfig(org.apache.kafka.common.security.TestSecurityConfig) Properties(java.util.Properties) Password(org.apache.kafka.common.config.types.Password) Test(org.junit.jupiter.api.Test)

Aggregations

TestSecurityConfig (org.apache.kafka.common.security.TestSecurityConfig)27 InetSocketAddress (java.net.InetSocketAddress)13 Properties (java.util.Properties)8 SecurityProtocol (org.apache.kafka.common.security.auth.SecurityProtocol)8 LogContext (org.apache.kafka.common.utils.LogContext)8 Test (org.junit.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 Test (org.junit.jupiter.api.Test)7 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)7 HashMap (java.util.HashMap)5 Password (org.apache.kafka.common.config.types.Password)5 ListenerName (org.apache.kafka.common.network.ListenerName)3 NioEchoServer (org.apache.kafka.common.network.NioEchoServer)3 SaslChannelBuilder (org.apache.kafka.common.network.SaslChannelBuilder)3 ApiVersionsResponse (org.apache.kafka.common.requests.ApiVersionsResponse)3 JaasContext (org.apache.kafka.common.security.JaasContext)3 SelectionKey (java.nio.channels.SelectionKey)2 Map (java.util.Map)2 SSLEngine (javax.net.ssl.SSLEngine)2 SSLParameters (javax.net.ssl.SSLParameters)2