Elasticsearch HTTP authentication in Spring(Spring 中的 Elasticsearch HTTP 身份验证)
问题描述
我想访问一个受用户名和密码保护的远程弹性搜索.https://[用户名]:[密码]]@aws-eu-west-1-portal1.dblayer.com:11109/
I want to access a remote elasticsearch which is protected by a username and password. https://[username]:[password]@aws-eu-west-1-portal1.dblayer.com:11109/
在 Spring 中使用 XML 配置我能够访问我的本地主机弹性,如下所示
In Spring using the XML config I was able to access my localhost elastic as shown below
<!-- ElasticSearch -->
<elasticsearch:repositories base-package="be.smartsearch.service.repository.elasticsearch" />
<elasticsearch:transport-client id="esClient" cluster-nodes="localhost:9300" />
<bean id="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="esClient" />
</bean>
到目前为止,我发现的唯一有用的文档是 PHP:https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_security.html
The only usefull documentation I found so far is for PHP: https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_security.html
如何使用 XML 配置的 Spring 数据中的凭据连接到远程 elasticsearh?
How can I connect to a remote elasticsearh with credentials in Spring data with the XML config?
在 Mongo 中,我可以通过以下方法做到这一点
In Mongo I was able to do it by the following method
<!-- Mongo -->
<mongo:mongo host="${mongo.host}" port="${mongo.port}"/>
<mongo:db-factory dbname="SmartSearchAfterDemo" mongo-ref="mongo" username="${mongo.user}" password="${mongo.password}"/>
<!--<mongo:db-factory dbname="${mongo.dbname}" mongo-ref="mongo"/> -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>
<mongo:repositories base-package="be.smartsearch.service.repository.mongo"/>
推荐答案
Spring Data Elasticsearch 基于官方的 Elasticsearch Java Client,它使用二进制传输协议(而不是像 PHP 那样的 REST HTTP 协议).
Spring Data Elasticsearch is base on the official Elasticsearch Java Client which uses the binary Transport procol (not the REST HTTP procol like PHP).
如果您使用 Shield 来保护您的 Elasticsearch,那么您可以在传输客户端/传输协议上设置用户/密码
If you're using Shield to secure your Elasticsearch, then you can set the user/password on the Transport client/Transport procol
TransportClient client = TransportClient.builder()
.addPlugin(ShieldPlugin.class)
.settings(Settings.builder()
.put("cluster.name", "yourcluster")
.put("shield.user", "youruser:yourpassword")
...
.build())
如果你不想在 Java 代码中使用 HTTP 协议,那么社区客户端:
If you wan't to use the HTTP protocol from Java code then there are to community clients:
- Jest 支持 HTTP 身份验证
- Elasticsearch HTTP 这是相当新的
- Jest which supports HTTP authentication
- Elasticsearch HTTP which is pretty new
但是这些解决方案与 Spring Data 不兼容
But these solutions are not compatible with Spring Data
这篇关于Spring 中的 Elasticsearch HTTP 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Spring 中的 Elasticsearch HTTP 身份验证
基础教程推荐
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01