Search in sources :

Example 1 with PlaintextAuthenticationContext

use of org.apache.kafka.common.security.auth.PlaintextAuthenticationContext in project apache-kafka-on-k8s by banzaicloud.

the class ChannelBuildersTest method testCreateOldPrincipalBuilder.

@Test
@SuppressWarnings("deprecation")
public void testCreateOldPrincipalBuilder() throws Exception {
    TransportLayer transportLayer = EasyMock.mock(TransportLayer.class);
    Authenticator authenticator = EasyMock.mock(Authenticator.class);
    Map<String, Object> configs = new HashMap<>();
    configs.put(BrokerSecurityConfigs.PRINCIPAL_BUILDER_CLASS_CONFIG, OldPrincipalBuilder.class);
    KafkaPrincipalBuilder builder = ChannelBuilders.createPrincipalBuilder(configs, transportLayer, authenticator, null);
    // test old principal builder is properly configured and delegated to
    assertTrue(OldPrincipalBuilder.configured);
    // test delegation
    KafkaPrincipal principal = builder.build(new PlaintextAuthenticationContext(InetAddress.getLocalHost()));
    assertEquals(OldPrincipalBuilder.PRINCIPAL_NAME, principal.getName());
    assertEquals(KafkaPrincipal.USER_TYPE, principal.getPrincipalType());
}
Also used : HashMap(java.util.HashMap) KafkaPrincipalBuilder(org.apache.kafka.common.security.auth.KafkaPrincipalBuilder) KafkaPrincipal(org.apache.kafka.common.security.auth.KafkaPrincipal) PlaintextAuthenticationContext(org.apache.kafka.common.security.auth.PlaintextAuthenticationContext) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 KafkaPrincipal (org.apache.kafka.common.security.auth.KafkaPrincipal)1 KafkaPrincipalBuilder (org.apache.kafka.common.security.auth.KafkaPrincipalBuilder)1 PlaintextAuthenticationContext (org.apache.kafka.common.security.auth.PlaintextAuthenticationContext)1 Test (org.junit.Test)1