Search in sources :

Example 11 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project akhq by tchiotludo.

the class KafkaModule method getRegistryRestClient.

public RestService getRegistryRestClient(String clusterId) {
    Connection connection = this.getConnection(clusterId);
    if (connection.getSchemaRegistry() != null) {
        RestService restService = new RestService(connection.getSchemaRegistry().getUrl());
        if (connection.getSchemaRegistry().getProperties() != null && !connection.getSchemaRegistry().getProperties().isEmpty()) {
            Map<String, Object> sslConfigs = connection.getSchemaRegistry().getProperties().entrySet().stream().filter(e -> e.getKey().startsWith("schema.registry.")).collect(Collectors.toMap(e -> e.getKey().substring("schema.registry.".length()), Map.Entry::getValue));
            SslFactory sslFactory = new SslFactory(sslConfigs);
            if (sslFactory != null && sslFactory.sslContext() != null) {
                restService.setSslSocketFactory(sslFactory.sslContext().getSocketFactory());
            }
        }
        restService.setHttpHeaders(Collections.singletonMap("Accept", "application/json"));
        if (connection.getSchemaRegistry().getBasicAuthUsername() != null) {
            BasicAuthCredentialProvider basicAuthCredentialProvider = BasicAuthCredentialProviderFactory.getBasicAuthCredentialProvider(new UserInfoCredentialProvider().alias(), ImmutableMap.of("schema.registry.basic.auth.user.info", connection.getSchemaRegistry().getBasicAuthUsername() + ":" + connection.getSchemaRegistry().getBasicAuthPassword()));
            restService.setBasicAuthCredentialProvider(basicAuthCredentialProvider);
        }
        if (connection.getSchemaRegistry().getProperties() != null) {
            restService.configure(connection.getSchemaRegistry().getProperties());
        }
        return restService;
    }
    return null;
}
Also used : AbstractProperties(org.akhq.configs.AbstractProperties) java.util(java.util) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) RestService(io.confluent.kafka.schemaregistry.client.rest.RestService) BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) Default(org.akhq.configs.Default) AdminClient(org.apache.kafka.clients.admin.AdminClient) KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) ByteArraySerializer(org.apache.kafka.common.serialization.ByteArraySerializer) SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) URIBuilder(org.codehaus.httpcache4j.uri.URIBuilder) JsonSchemaProvider(io.confluent.kafka.schemaregistry.json.JsonSchemaProvider) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) Configuration(org.sourcelab.kafka.connect.apiclient.Configuration) ImmutableMap(com.google.common.collect.ImmutableMap) KafkaConnectClient(org.sourcelab.kafka.connect.apiclient.KafkaConnectClient) Singleton(jakarta.inject.Singleton) AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider) Collectors(java.util.stream.Collectors) File(java.io.File) BasicAuthCredentialProviderFactory(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProviderFactory) Connection(org.akhq.configs.Connection) UserInfoCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.UserInfoCredentialProvider) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) Inject(jakarta.inject.Inject) SslFactory(io.confluent.kafka.schemaregistry.client.security.SslFactory) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) UserInfoCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.UserInfoCredentialProvider) Connection(org.akhq.configs.Connection) RestService(io.confluent.kafka.schemaregistry.client.rest.RestService) ImmutableMap(com.google.common.collect.ImmutableMap) SslFactory(io.confluent.kafka.schemaregistry.client.security.SslFactory)

Aggregations

BasicAuthCredentialProvider (io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider)11 Test (org.junit.Test)8 HashMap (java.util.HashMap)3 RestService (io.confluent.kafka.schemaregistry.client.rest.RestService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)1 AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)1 CachedSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)1 SslFactory (io.confluent.kafka.schemaregistry.client.security.SslFactory)1 BasicAuthCredentialProviderFactory (io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProviderFactory)1 UserInfoCredentialProvider (io.confluent.kafka.schemaregistry.client.security.basicauth.UserInfoCredentialProvider)1 BearerAuthCredentialProvider (io.confluent.kafka.schemaregistry.client.security.bearerauth.BearerAuthCredentialProvider)1 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)1 ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)1 Inject (jakarta.inject.Inject)1