Search in sources :

Example 16 with DefaultKafkaPrincipalBuilder

use of org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder in project kafka by apache.

the class DefaultKafkaPrincipalBuilderTest method testPrincipalBuilderScram.

@Test
public void testPrincipalBuilderScram() throws Exception {
    SaslServer server = mock(SaslServer.class);
    when(server.getMechanismName()).thenReturn(ScramMechanism.SCRAM_SHA_256.mechanismName());
    when(server.getAuthorizationID()).thenReturn("foo");
    DefaultKafkaPrincipalBuilder builder = new DefaultKafkaPrincipalBuilder(null, null);
    KafkaPrincipal principal = builder.build(new SaslAuthenticationContext(server, SecurityProtocol.SASL_PLAINTEXT, InetAddress.getLocalHost(), SecurityProtocol.SASL_PLAINTEXT.name()));
    assertEquals(KafkaPrincipal.USER_TYPE, principal.getPrincipalType());
    assertEquals("foo", principal.getName());
    verify(server, atLeastOnce()).getMechanismName();
    verify(server, atLeastOnce()).getAuthorizationID();
}
Also used : DefaultKafkaPrincipalBuilder(org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder) SaslServer(javax.security.sasl.SaslServer) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultKafkaPrincipalBuilder (org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder)16 Test (org.junit.jupiter.api.Test)8 Test (org.junit.Test)6 SSLSession (javax.net.ssl.SSLSession)5 SaslServer (javax.security.sasl.SaslServer)5 KerberosShortNamer (org.apache.kafka.common.security.kerberos.KerberosShortNamer)3 Configurable (org.apache.kafka.common.Configurable)2 InvalidConfigurationException (org.apache.kafka.common.errors.InvalidConfigurationException)2 Authenticator (org.apache.kafka.common.network.Authenticator)2 TransportLayer (org.apache.kafka.common.network.TransportLayer)2 KafkaPrincipalBuilder (org.apache.kafka.common.security.auth.KafkaPrincipalBuilder)2 X500Principal (javax.security.auth.x500.X500Principal)1 KafkaPrincipal (org.apache.kafka.common.security.auth.KafkaPrincipal)1 KerberosName (org.apache.kafka.common.security.kerberos.KerberosName)1 SslPrincipalMapper (org.apache.kafka.common.security.ssl.SslPrincipalMapper)1