Search in sources :

Example 1 with CertStores

use of org.apache.kafka.common.network.CertStores in project apache-kafka-on-k8s by banzaicloud.

the class SaslAuthenticatorTest method setup.

@Before
public void setup() throws Exception {
    LoginManager.closeAll();
    serverCertStores = new CertStores(true, "localhost");
    clientCertStores = new CertStores(false, "localhost");
    saslServerConfigs = serverCertStores.getTrustingConfig(clientCertStores);
    saslClientConfigs = clientCertStores.getTrustingConfig(serverCertStores);
    credentialCache = new CredentialCache();
}
Also used : CertStores(org.apache.kafka.common.network.CertStores) Before(org.junit.Before)

Example 2 with CertStores

use of org.apache.kafka.common.network.CertStores in project kafka by apache.

the class SaslAuthenticatorTest method verifySslClientAuthForSaslSslListener.

private void verifySslClientAuthForSaslSslListener(boolean useListenerPrefix, SslClientAuth configuredClientAuth) throws Exception {
    SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;
    configureMechanisms("PLAIN", Collections.singletonList("PLAIN"));
    String listenerPrefix = useListenerPrefix ? ListenerName.forSecurityProtocol(securityProtocol).configPrefix() : "";
    saslServerConfigs.put(listenerPrefix + BrokerSecurityConfigs.SSL_CLIENT_AUTH_CONFIG, configuredClientAuth.name());
    saslServerConfigs.put(BrokerSecurityConfigs.PRINCIPAL_BUILDER_CLASS_CONFIG, SaslSslPrincipalBuilder.class.getName());
    server = createEchoServer(securityProtocol);
    SslClientAuth expectedClientAuth = useListenerPrefix ? configuredClientAuth : SslClientAuth.NONE;
    String certDn = "O=A client,CN=localhost";
    KafkaPrincipal principalWithMutualTls = SaslSslPrincipalBuilder.saslSslPrincipal(TestJaasConfig.USERNAME, certDn);
    KafkaPrincipal principalWithOneWayTls = SaslSslPrincipalBuilder.saslSslPrincipal(TestJaasConfig.USERNAME, "ANONYMOUS");
    // Client configured with valid key store
    createAndCheckClientConnectionAndPrincipal(securityProtocol, "0", expectedClientAuth == SslClientAuth.NONE ? principalWithOneWayTls : principalWithMutualTls);
    // Client does not configure key store
    removeClientSslKeystore();
    if (expectedClientAuth != SslClientAuth.REQUIRED) {
        createAndCheckClientConnectionAndPrincipal(securityProtocol, "1", principalWithOneWayTls);
    } else {
        createAndCheckSslAuthenticationFailure(securityProtocol, "1");
    }
    // Client configures untrusted key store
    CertStores newStore = new CertStores(false, "localhost");
    newStore.keyStoreProps().forEach((k, v) -> saslClientConfigs.put(k, v));
    if (expectedClientAuth == SslClientAuth.NONE) {
        createAndCheckClientConnectionAndPrincipal(securityProtocol, "2", principalWithOneWayTls);
    } else {
        createAndCheckSslAuthenticationFailure(securityProtocol, "2");
    }
}
Also used : SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) KafkaPrincipal(org.apache.kafka.common.security.auth.KafkaPrincipal) SslClientAuth(org.apache.kafka.common.config.SslClientAuth) CertStores(org.apache.kafka.common.network.CertStores)

Example 3 with CertStores

use of org.apache.kafka.common.network.CertStores in project kafka by apache.

the class SaslAuthenticatorTest method setup.

@BeforeEach
public void setup() throws Exception {
    LoginManager.closeAll();
    time = Time.SYSTEM;
    serverCertStores = new CertStores(true, "localhost");
    clientCertStores = new CertStores(false, "localhost");
    saslServerConfigs = serverCertStores.getTrustingConfig(clientCertStores);
    saslClientConfigs = clientCertStores.getTrustingConfig(serverCertStores);
    credentialCache = new CredentialCache();
    TestLogin.loginCount.set(0);
}
Also used : CertStores(org.apache.kafka.common.network.CertStores) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CertStores

use of org.apache.kafka.common.network.CertStores in project kafka by apache.

the class SaslAuthenticatorFailureDelayTest method setup.

@BeforeEach
public void setup() throws Exception {
    LoginManager.closeAll();
    serverCertStores = new CertStores(true, "localhost");
    clientCertStores = new CertStores(false, "localhost");
    saslServerConfigs = serverCertStores.getTrustingConfig(clientCertStores);
    saslClientConfigs = clientCertStores.getTrustingConfig(serverCertStores);
    credentialCache = new CredentialCache();
    SaslAuthenticatorTest.TestLogin.loginCount.set(0);
    startTimeMs = time.milliseconds();
}
Also used : CertStores(org.apache.kafka.common.network.CertStores) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CertStores (org.apache.kafka.common.network.CertStores)4 BeforeEach (org.junit.jupiter.api.BeforeEach)2 SslClientAuth (org.apache.kafka.common.config.SslClientAuth)1 KafkaPrincipal (org.apache.kafka.common.security.auth.KafkaPrincipal)1 SecurityProtocol (org.apache.kafka.common.security.auth.SecurityProtocol)1 Before (org.junit.Before)1