Search in sources :

Example 1 with KerberosShortNamer

use of org.apache.kafka.common.security.kerberos.KerberosShortNamer in project apache-kafka-on-k8s by banzaicloud.

the class DefaultKafkaPrincipalBuilderTest method testPrincipalBuilderGssapi.

@Test
public void testPrincipalBuilderGssapi() throws Exception {
    SaslServer server = mock(SaslServer.class);
    KerberosShortNamer kerberosShortNamer = mock(KerberosShortNamer.class);
    EasyMock.expect(server.getMechanismName()).andReturn(SaslConfigs.GSSAPI_MECHANISM);
    EasyMock.expect(server.getAuthorizationID()).andReturn("foo/host@REALM.COM");
    EasyMock.expect(kerberosShortNamer.shortName(EasyMock.anyObject(KerberosName.class))).andReturn("foo");
    replayAll();
    DefaultKafkaPrincipalBuilder builder = new DefaultKafkaPrincipalBuilder(kerberosShortNamer);
    KafkaPrincipal principal = builder.build(new SaslAuthenticationContext(server, SecurityProtocol.SASL_PLAINTEXT, InetAddress.getLocalHost()));
    assertEquals(KafkaPrincipal.USER_TYPE, principal.getPrincipalType());
    assertEquals("foo", principal.getName());
    verifyAll();
}
Also used : KerberosShortNamer(org.apache.kafka.common.security.kerberos.KerberosShortNamer) DefaultKafkaPrincipalBuilder(org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder) SaslServer(javax.security.sasl.SaslServer) KerberosName(org.apache.kafka.common.security.kerberos.KerberosName) Test(org.junit.Test)

Example 2 with KerberosShortNamer

use of org.apache.kafka.common.security.kerberos.KerberosShortNamer in project kafka by apache.

the class DefaultKafkaPrincipalBuilderTest method testPrincipalBuilderGssapi.

@Test
public void testPrincipalBuilderGssapi() throws Exception {
    SaslServer server = mock(SaslServer.class);
    KerberosShortNamer kerberosShortNamer = mock(KerberosShortNamer.class);
    when(server.getMechanismName()).thenReturn(SaslConfigs.GSSAPI_MECHANISM);
    when(server.getAuthorizationID()).thenReturn("foo/host@REALM.COM");
    when(kerberosShortNamer.shortName(any())).thenReturn("foo");
    DefaultKafkaPrincipalBuilder builder = new DefaultKafkaPrincipalBuilder(kerberosShortNamer, 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();
    verify(kerberosShortNamer, atLeastOnce()).shortName(any());
}
Also used : KerberosShortNamer(org.apache.kafka.common.security.kerberos.KerberosShortNamer) DefaultKafkaPrincipalBuilder(org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder) SaslServer(javax.security.sasl.SaslServer) Test(org.junit.jupiter.api.Test)

Example 3 with KerberosShortNamer

use of org.apache.kafka.common.security.kerberos.KerberosShortNamer in project kafka by apache.

the class DefaultKafkaPrincipalBuilderTest method testPrincipalBuilderSerde.

@Test
public void testPrincipalBuilderSerde() throws Exception {
    SaslServer server = mock(SaslServer.class);
    KerberosShortNamer kerberosShortNamer = mock(KerberosShortNamer.class);
    when(server.getMechanismName()).thenReturn(SaslConfigs.GSSAPI_MECHANISM);
    when(server.getAuthorizationID()).thenReturn("foo/host@REALM.COM");
    when(kerberosShortNamer.shortName(any())).thenReturn("foo");
    DefaultKafkaPrincipalBuilder builder = new DefaultKafkaPrincipalBuilder(kerberosShortNamer, 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());
    byte[] serializedPrincipal = builder.serialize(principal);
    KafkaPrincipal deserializedPrincipal = builder.deserialize(serializedPrincipal);
    assertEquals(principal, deserializedPrincipal);
    verify(server, atLeastOnce()).getMechanismName();
    verify(server, atLeastOnce()).getAuthorizationID();
    verify(kerberosShortNamer, atLeastOnce()).shortName(any());
}
Also used : KerberosShortNamer(org.apache.kafka.common.security.kerberos.KerberosShortNamer) DefaultKafkaPrincipalBuilder(org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder) SaslServer(javax.security.sasl.SaslServer) Test(org.junit.jupiter.api.Test)

Aggregations

SaslServer (javax.security.sasl.SaslServer)3 DefaultKafkaPrincipalBuilder (org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder)3 KerberosShortNamer (org.apache.kafka.common.security.kerberos.KerberosShortNamer)3 Test (org.junit.jupiter.api.Test)2 KerberosName (org.apache.kafka.common.security.kerberos.KerberosName)1 Test (org.junit.Test)1