use of org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder in project apache-kafka-on-k8s by banzaicloud.
the class DefaultKafkaPrincipalBuilderTest method testUseOldPrincipalBuilderForSslIfProvided.
@Test
@SuppressWarnings("deprecation")
public void testUseOldPrincipalBuilderForSslIfProvided() throws Exception {
TransportLayer transportLayer = mock(TransportLayer.class);
Authenticator authenticator = mock(Authenticator.class);
PrincipalBuilder oldPrincipalBuilder = mock(PrincipalBuilder.class);
SSLSession session = mock(SSLSession.class);
EasyMock.expect(oldPrincipalBuilder.buildPrincipal(transportLayer, authenticator)).andReturn(new DummyPrincipal("foo"));
oldPrincipalBuilder.close();
EasyMock.expectLastCall();
replayAll();
DefaultKafkaPrincipalBuilder builder = DefaultKafkaPrincipalBuilder.fromOldPrincipalBuilder(authenticator, transportLayer, oldPrincipalBuilder, null);
KafkaPrincipal principal = builder.build(new SslAuthenticationContext(session, InetAddress.getLocalHost()));
assertEquals(KafkaPrincipal.USER_TYPE, principal.getPrincipalType());
assertEquals("foo", principal.getName());
builder.close();
verifyAll();
}
use of org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder 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();
}
use of org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder in project apache-kafka-on-k8s by banzaicloud.
the class DefaultKafkaPrincipalBuilderTest method testReturnAnonymousPrincipalForPlaintext.
@Test
public void testReturnAnonymousPrincipalForPlaintext() throws Exception {
DefaultKafkaPrincipalBuilder builder = new DefaultKafkaPrincipalBuilder(null);
assertEquals(KafkaPrincipal.ANONYMOUS, builder.build(new PlaintextAuthenticationContext(InetAddress.getLocalHost())));
}
use of org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder in project kafka by apache.
the class EnvelopeRequestTest method testGetPrincipal.
@Test
public void testGetPrincipal() {
KafkaPrincipal kafkaPrincipal = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "principal", true);
DefaultKafkaPrincipalBuilder kafkaPrincipalBuilder = new DefaultKafkaPrincipalBuilder(null, null);
EnvelopeRequest.Builder requestBuilder = new EnvelopeRequest.Builder(ByteBuffer.allocate(0), kafkaPrincipalBuilder.serialize(kafkaPrincipal), "client-address".getBytes());
EnvelopeRequest request = requestBuilder.build(EnvelopeRequestData.HIGHEST_SUPPORTED_VERSION);
assertEquals(kafkaPrincipal, kafkaPrincipalBuilder.deserialize(request.requestPrincipal()));
}
use of org.apache.kafka.common.security.authenticator.DefaultKafkaPrincipalBuilder in project kafka by apache.
the class DefaultKafkaPrincipalBuilderTest method testPrincipalIfSSLPeerIsNotAuthenticated.
@Test
public void testPrincipalIfSSLPeerIsNotAuthenticated() throws Exception {
SSLSession session = mock(SSLSession.class);
when(session.getPeerPrincipal()).thenReturn(KafkaPrincipal.ANONYMOUS);
DefaultKafkaPrincipalBuilder builder = new DefaultKafkaPrincipalBuilder(null, null);
KafkaPrincipal principal = builder.build(new SslAuthenticationContext(session, InetAddress.getLocalHost(), SecurityProtocol.PLAINTEXT.name()));
assertEquals(KafkaPrincipal.ANONYMOUS, principal);
verify(session, atLeastOnce()).getPeerPrincipal();
}
Aggregations