Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2c6bc4ca
authored
Mar 09, 2021
by
sunxiwang
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
es添加密码验证
1 parent
a90b6219
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
linkwe-admin/src/main/resources/application.yml
linkwe-common/src/main/java/com/linkwechat/common/config/ElasticSearchConfig.java
linkwe-admin/src/main/resources/application.yml
View file @
2c6bc4c
...
@@ -150,6 +150,8 @@ xss:
...
@@ -150,6 +150,8 @@ xss:
elasticsearch
:
elasticsearch
:
schema
:
http
schema
:
http
address
:
${ES_ADDRESS:localhost}
address
:
${ES_ADDRESS:localhost}
userName
:
"
"
password
:
"
"
connectTimeout
:
10000
connectTimeout
:
10000
socketTimeout
:
10000
socketTimeout
:
10000
connectionRequestTimeout
:
10000
connectionRequestTimeout
:
10000
...
...
linkwe-common/src/main/java/com/linkwechat/common/config/ElasticSearchConfig.java
View file @
2c6bc4c
package
com
.
linkwechat
.
common
.
config
;
package
com
.
linkwechat
.
common
.
config
;
import
org.apache.http.HttpHost
;
import
org.apache.http.HttpHost
;
import
org.apache.http.auth.AuthScope
;
import
org.apache.http.auth.UsernamePasswordCredentials
;
import
org.apache.http.client.CredentialsProvider
;
import
org.apache.http.impl.client.BasicCredentialsProvider
;
import
org.elasticsearch.client.RestClient
;
import
org.elasticsearch.client.RestClient
;
import
org.elasticsearch.client.RestClientBuilder
;
import
org.elasticsearch.client.RestClientBuilder
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.client.RestHighLevelClient
;
...
@@ -30,6 +34,11 @@ public class ElasticSearchConfig {
...
@@ -30,6 +34,11 @@ public class ElasticSearchConfig {
@Value
(
"${elasticsearch.address}"
)
@Value
(
"${elasticsearch.address}"
)
private
String
address
;
private
String
address
;
@Value
(
"${elasticsearch.userName}"
)
private
String
userName
;
@Value
(
"${elasticsearch.password}"
)
private
String
password
;
/**
/**
* 连接超时时间
* 连接超时时间
*/
*/
...
@@ -70,6 +79,8 @@ public class ElasticSearchConfig {
...
@@ -70,6 +79,8 @@ public class ElasticSearchConfig {
String
port
=
addr
.
split
(
":"
)[
1
];
String
port
=
addr
.
split
(
":"
)[
1
];
hostLists
.
add
(
new
HttpHost
(
host
,
Integer
.
parseInt
(
port
),
schema
));
hostLists
.
add
(
new
HttpHost
(
host
,
Integer
.
parseInt
(
port
),
schema
));
}
}
final
CredentialsProvider
credentialsProvider
=
new
BasicCredentialsProvider
();
credentialsProvider
.
setCredentials
(
AuthScope
.
ANY
,
new
UsernamePasswordCredentials
(
userName
,
password
));
// 转换成 HttpHost 数组
// 转换成 HttpHost 数组
HttpHost
[]
httpHost
=
hostLists
.
toArray
(
new
HttpHost
[]{});
HttpHost
[]
httpHost
=
hostLists
.
toArray
(
new
HttpHost
[]{});
// 构建连接对象
// 构建连接对象
...
@@ -85,6 +96,7 @@ public class ElasticSearchConfig {
...
@@ -85,6 +96,7 @@ public class ElasticSearchConfig {
builder
.
setHttpClientConfigCallback
(
httpClientBuilder
->
{
builder
.
setHttpClientConfigCallback
(
httpClientBuilder
->
{
httpClientBuilder
.
setMaxConnTotal
(
maxConnectNum
);
httpClientBuilder
.
setMaxConnTotal
(
maxConnectNum
);
httpClientBuilder
.
setMaxConnPerRoute
(
maxConnectPerRoute
);
httpClientBuilder
.
setMaxConnPerRoute
(
maxConnectPerRoute
);
httpClientBuilder
.
setDefaultCredentialsProvider
(
credentialsProvider
);
return
httpClientBuilder
;
return
httpClientBuilder
;
});
});
return
new
RestHighLevelClient
(
builder
);
return
new
RestHighLevelClient
(
builder
);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment