使用基本凭证提供者配置Elasticsearch Rest高级客户端 [英] Configure Elasticsearch rest high level client with Basic credential provider

查看:642
本文介绍了使用基本凭证提供者配置Elasticsearch Rest高级客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题在我的注释,在这里我解释了如何在Elasticsearch JHLRC请求中发送基本证书,但它不在客户端级别,而是在请求级别. >

我认为是在客户端级别进行配置的,这样可以避免在仅与少数用户打交道的情况下再次重复相同的代码,这将有助于在客户端本身中配置凭据.

解决方案

您可以按照this SO answer of how to secure JHLRC in this comment, where I explained how to send Basic Credential in Elasticsearch JHLRC request but it was not at the client level and was at the request level.

I feel configure at the client level, would avoid repeating the same code again in cases, where you are dealing with only a few users it would be helpful to configure the credentials in the client itself.

解决方案

You can follow the below steps as mentioned in this official link.

Create CredentialsProvider using the BasicCredentialsProvider.

final CredentialsProvider credentialsProvider =
                new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("elastic", "elastic"));

Now use the CredentialsProvider while building the rest client(JHLRC).

RestHighLevelClient restHighLevelClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost(scannerConfiguration.getElasticsearchConfig().getHost(),
                        scannerConfiguration.getElasticsearchConfig().getPort(),
                        "http")).setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                    @Override
                    public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                        return httpClientBuilder
                                .setDefaultCredentialsProvider(credentialsProvider);
                    }
                }));

这篇关于使用基本凭证提供者配置Elasticsearch Rest高级客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆