use of io.confluent.kafka.schemaregistry.client.security.basicauth.UserInfoCredentialProvider 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;
}
Aggregations