Search in sources :

Example 6 with SslEngineFactory

use of org.apache.kafka.common.security.auth.SslEngineFactory 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

SslEngineFactory (org.apache.kafka.common.security.auth.SslEngineFactory)6 GeneralSecurityException (java.security.GeneralSecurityException)2 HashMap (java.util.HashMap)2 SSLException (javax.net.ssl.SSLException)2 KafkaException (org.apache.kafka.common.KafkaException)2 ConfigException (org.apache.kafka.common.config.ConfigException)2 Test (org.junit.jupiter.api.Test)2 File (java.io.File)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Password (org.apache.kafka.common.config.types.Password)1 TestSecurityConfig (org.apache.kafka.common.security.TestSecurityConfig)1