Search in sources :

Example 16 with ListenerName

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

the class KafkaClusterTestKit method clientProperties.

public Properties clientProperties() {
    Properties properties = new Properties();
    if (!brokers.isEmpty()) {
        StringBuilder bld = new StringBuilder();
        String prefix = "";
        for (Entry<Integer, BrokerServer> entry : brokers.entrySet()) {
            int brokerId = entry.getKey();
            BrokerServer broker = entry.getValue();
            ListenerName listenerName = nodes.externalListenerName();
            int port = broker.boundPort(listenerName);
            if (port <= 0) {
                throw new RuntimeException("Broker " + brokerId + " does not yet " + "have a bound port for " + listenerName + ".  Did you start " + "the cluster yet?");
            }
            bld.append(prefix).append("localhost:").append(port);
            prefix = ",";
        }
        properties.setProperty(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, bld.toString());
    }
    return properties;
}
Also used : BrokerServer(kafka.server.BrokerServer) MetaProperties(kafka.server.MetaProperties) Properties(java.util.Properties) ListenerName(org.apache.kafka.common.network.ListenerName)

Example 17 with ListenerName

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

the class JaasContextTest method testLoadForServerWithWrongListenerName.

@Test(expected = IllegalArgumentException.class)
public void testLoadForServerWithWrongListenerName() throws IOException {
    writeConfiguration("Server", "test.LoginModule required;");
    JaasContext.load(JaasContext.Type.SERVER, new ListenerName("plaintext"), Collections.<String, Object>emptyMap());
}
Also used : ListenerName(org.apache.kafka.common.network.ListenerName) Test(org.junit.Test)

Example 18 with ListenerName

use of org.apache.kafka.common.network.ListenerName in project ranger by apache.

the class RangerKafkaAuthorizer method configure.

/*
	 * (non-Javadoc)
	 *
	 * @see kafka.security.auth.Authorizer#configure(Map<String, Object>)
	 */
@Override
public void configure(Map<String, ?> configs) {
    RangerBasePlugin me = rangerPlugin;
    if (me == null) {
        synchronized (RangerKafkaAuthorizer.class) {
            me = rangerPlugin;
            if (me == null) {
                try {
                    // Possible to override JAAS configuration which is used by Ranger, otherwise
                    // SASL_PLAINTEXT is used, which force Kafka to use 'sasl_plaintext.KafkaServer',
                    // if it's not defined, then it reverts to 'KafkaServer' configuration.
                    final Object jaasContext = configs.get("ranger.jaas.context");
                    final String listenerName = (jaasContext instanceof String && StringUtils.isNotEmpty((String) jaasContext)) ? (String) jaasContext : SecurityProtocol.SASL_PLAINTEXT.name();
                    final String saslMechanism = SaslConfigs.GSSAPI_MECHANISM;
                    JaasContext context = JaasContext.loadServerContext(new ListenerName(listenerName), saslMechanism, configs);
                    MiscUtil.setUGIFromJAASConfig(context.name());
                    logger.info("LoginUser=" + MiscUtil.getUGILoginUser());
                } catch (Throwable t) {
                    logger.error("Error getting principal.", t);
                }
                me = rangerPlugin = new RangerBasePlugin("kafka", "kafka");
            }
        }
    }
    logger.info("Calling plugin.init()");
    rangerPlugin.init();
    auditHandler = new RangerKafkaAuditHandler();
    rangerPlugin.setResultProcessor(auditHandler);
}
Also used : JaasContext(org.apache.kafka.common.security.JaasContext) ListenerName(org.apache.kafka.common.network.ListenerName) RangerBasePlugin(org.apache.ranger.plugin.service.RangerBasePlugin)

Example 19 with ListenerName

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

the class RequestResponseTest method createUpdateMetadataRequest.

private UpdateMetadataRequest createUpdateMetadataRequest(int version, String rack) {
    Map<TopicPartition, UpdateMetadataRequest.PartitionState> partitionStates = new HashMap<>();
    List<Integer> isr = asList(1, 2);
    List<Integer> replicas = asList(1, 2, 3, 4);
    List<Integer> offlineReplicas = asList();
    partitionStates.put(new TopicPartition("topic5", 105), new UpdateMetadataRequest.PartitionState(0, 2, 1, isr, 2, replicas, offlineReplicas));
    partitionStates.put(new TopicPartition("topic5", 1), new UpdateMetadataRequest.PartitionState(1, 1, 1, isr, 2, replicas, offlineReplicas));
    partitionStates.put(new TopicPartition("topic20", 1), new UpdateMetadataRequest.PartitionState(1, 0, 1, isr, 2, replicas, offlineReplicas));
    SecurityProtocol plaintext = SecurityProtocol.PLAINTEXT;
    List<UpdateMetadataRequest.EndPoint> endPoints1 = new ArrayList<>();
    endPoints1.add(new UpdateMetadataRequest.EndPoint("host1", 1223, plaintext, ListenerName.forSecurityProtocol(plaintext)));
    List<UpdateMetadataRequest.EndPoint> endPoints2 = new ArrayList<>();
    endPoints2.add(new UpdateMetadataRequest.EndPoint("host1", 1244, plaintext, ListenerName.forSecurityProtocol(plaintext)));
    if (version > 0) {
        SecurityProtocol ssl = SecurityProtocol.SSL;
        endPoints2.add(new UpdateMetadataRequest.EndPoint("host2", 1234, ssl, ListenerName.forSecurityProtocol(ssl)));
        endPoints2.add(new UpdateMetadataRequest.EndPoint("host2", 1334, ssl, new ListenerName("CLIENT")));
    }
    Set<UpdateMetadataRequest.Broker> liveBrokers = Utils.mkSet(new UpdateMetadataRequest.Broker(0, endPoints1, rack), new UpdateMetadataRequest.Broker(1, endPoints2, rack));
    return new UpdateMetadataRequest.Builder((short) version, 1, 10, partitionStates, liveBrokers).build();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) ArrayList(java.util.ArrayList) ListenerName(org.apache.kafka.common.network.ListenerName) TopicPartition(org.apache.kafka.common.TopicPartition)

Example 20 with ListenerName

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

the class JaasContextTest method testLoadForServerWithListenerNameAndFallback.

@Test
public void testLoadForServerWithListenerNameAndFallback() throws IOException {
    writeConfiguration(Arrays.asList("KafkaServer { test.LoginModule required; };", "other.KafkaServer { test.LoginModuleOther requisite; };"));
    JaasContext context = JaasContext.loadServerContext(new ListenerName("plaintext"), "SOME-MECHANISM", Collections.<String, Object>emptyMap());
    assertEquals("KafkaServer", context.name());
    assertEquals(JaasContext.Type.SERVER, context.type());
    assertEquals(1, context.configurationEntries().size());
    checkEntry(context.configurationEntries().get(0), "test.LoginModule", LoginModuleControlFlag.REQUIRED, Collections.<String, Object>emptyMap());
}
Also used : ListenerName(org.apache.kafka.common.network.ListenerName) Test(org.junit.Test)

Aggregations

ListenerName (org.apache.kafka.common.network.ListenerName)27 HashMap (java.util.HashMap)11 JaasContext (org.apache.kafka.common.security.JaasContext)9 Test (org.junit.jupiter.api.Test)8 Test (org.junit.Test)7 SaslChannelBuilder (org.apache.kafka.common.network.SaslChannelBuilder)5 ApiVersionsResponse (org.apache.kafka.common.requests.ApiVersionsResponse)5 SecurityProtocol (org.apache.kafka.common.security.auth.SecurityProtocol)5 Map (java.util.Map)4 Subject (javax.security.auth.Subject)4 TransportLayer (org.apache.kafka.common.network.TransportLayer)4 PlainLoginModule (org.apache.kafka.common.security.plain.PlainLoginModule)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 ApiVersionsResponseData (org.apache.kafka.common.message.ApiVersionsResponseData)3 ApiVersionCollection (org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersionCollection)3 NioEchoServer (org.apache.kafka.common.network.NioEchoServer)3 TestSecurityConfig (org.apache.kafka.common.security.TestSecurityConfig)3 LogContext (org.apache.kafka.common.utils.LogContext)3 InetSocketAddress (java.net.InetSocketAddress)2