spring-boot-demo icon indicating copy to clipboard operation
spring-boot-demo copied to clipboard

[BUG]elasticsearchRestHighLeve 使用账号密码认证失败

Open CharmNight opened this issue 5 years ago • 0 comments
trafficstars

请先看《提问的智慧》,并尝试到 issue 列表 搜寻是否已经有人遇到过同样的问题。


描述问题

spring-boot-demo-elasticsearch-rest-high-level-client 项目中 使用 阿里服务es 用户登录 校验失败

其他信息

ElasticsearchAutoConfiguration#getRestHighLevelClient 使用账号密码时缺少部分代码, 认为应修改如下, 参考阿里文档 https://help.aliyun.com/document_detail/172371.html?spm=a2c4g.11186623.6.870.4d0dce3aUMI6kj

      // Callback used the basic credential auth
        ElasticsearchProperties.Account account = elasticsearchProperties.getAccount();
        if (!StringUtils.isEmpty(account.getUsername()) && !StringUtils.isEmpty(account.getPassword())) {
            final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(account.getUsername(), account.getPassword()));
            builder.setHttpClientConfigCallback(
                (httpClientBuilder) -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
        }

CharmNight avatar Sep 29 '20 09:09 CharmNight