Elasticsearch httpclient authentication Mechanism

Source: Internet
Author: User

Recently the company relocation, all the services are stopped, I am responsible for the Elasticsearch do not know how to go, has been unable to run it, so I have been responsible for debugging work. After two days of debugging work, I found that the new server added the httpclient authentication mechanism, after several studies, found that the server has the following additions:

Http.basic.log:false
Http.basic.user: "Hett"
Http.basic.password: "* * * *"

Therefore, each time the IK split Word will be prompted when the message is: HTTP does not have authentication, therefore, the loading of HTTP links between the pre-authentication mechanism, in the initialization of the bean when the authentication begins, the code to do the following changes:

public class Elasticsearchserviceimpl implements Ielasticsearchservice, Initializingbean

The class inherits the authentication of the initialization bean.


To implement a method of the parent class:

@Override
public void Afterpropertiesset () throws Exception {
try {
Properties props = Propertiesloaderutils
. Loadallproperties ("********");
String Authuser = Stringutil
. NULL2STR (Props.getproperty ("username"));
String authpwd = Stringutil.null2str (Props.getproperty ("password"));
Credentialcontext = Httpclientcontext.create ();
Certification provider
Credentialsprovider Credsprovider = new Basiccredentialsprovider ();

Credsprovider.setcredentials (Authscope.any,
New Usernamepasswordcredentials (Authuser, authpwd));

Authcache Authcache = new Basicauthcache ();
Pre-populated authentication information is cached in the context so that the method executed in this context uses preemptive authentication. May be wrong
Credentialcontext.setauthcache (Authcache);
Credentialcontext.setcredentialsprovider (Credsprovider);
} catch (Exception ex) {
Logger.warn ("Read Elasticsearch credential Error", ex);
}
}

When you visit again, you will be prompted as follows:

The information that debug throws is authenticated through

After a few days of tossing and finishing finally completed the search tags such as services
So happy.

Elasticsearch httpclient authentication Mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.