Elasticsearch Add shield after transportclient how to connect?

Source: Internet
Author: User

Elasticsearch Add shield after transportclient how to connect?time 2015-12-28 10:24:01 heterodoxy Original http://log.medcl.net/item/2015/12/shieldtransportclient-xia-ru-he-shi-yong/ThemeElastic Search

Shield is a elasticsearch security plug-in that provides access control and log auditing capabilities that enable organizations to easily integrate with LDAP or activedirectory and reuse existing security authentication systems.

Elasticsearch use shield, Elasticsearch need permission to access, and the default way to call a little different, the following is a brief introduction of HTTP and TCP two ways of connection.

About the installation and configuration of shield I'm not going to introduce you here, create a user name and password are Tribe_user users, the permissions are admin.

1.HTTP mode now direct access to ES HTTP interface will be error

Curl http://localhost:9200 
{"Error ":{"Root_cause ":[{"Type ":reason":  "Missing authentication token for REST request [/]", " header ": {" www-authenticate ":  "Basic realm=\" shield\ ""}}], "type": reason":  "Missing authentication token for REST request [/]", " header ": {" www-authenticate ":  "Basic realm=\" shield\ ""}}, "status": 401}           

Shield supports httpbasic authentication, so the correct access posture is:

Curl-u tribe_user:tribe_user http://localhost:9200{  "Melter",  "Elasticsearch",  "you Know, for Search "}   

If it is a browser access, the first visit will pop up the verification window, and follow the same time as long as you do not close the browser to keep the session. Note that HTTP basic is an unsafe authentication method that is only used for development debugging, and the production environment also needs to be used in conjunction with HTTPS encrypted channels.

2.TransportClient Way Access Shield plus anti-elasticsearch, a little troublesome point, need to rely on shield package, the steps are as follows: 2.1 If you are a MAVEN managed project, Add the Elasticsearch Maven repository source to the Pom.xml file as follows:

<Repositories><Repository><id>elasticsearch-releases</id> <url>https://maven.elasticsearch.org/releases </url> <releases> << Span class= "title" >enabled>true</enabled> </ releases> <snapshots> << Span class= "title" >enabled>false</enabled> < /snapshots> </repository> </REPOSITORIES>           

2.2 Adding a dependent configuration

<dependency>   <groupid>org.elasticsearch.plugin</<artifactid> Shield</<version>2.1.1</version></dependency  

2.3 Building transportclient places to increase access to User Configuration

Static Org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
string clustername= "Elasticsearch"; String ip=  "127.0.0.1"; Settings Settings = Settings.settingsbuilder (). Put ( "Cluster.name", clustername). Put ( "Shield.user", 9300)); String token = Basicauthheadervalue ( "Tribe_user", New securedstring ( " Tribe_user ". ToCharArray ())); Client.preparesearch (). Putheader ( "Authorization", token).  Get (); } catch (Unknownhostexception e) {logger.error (      

Elasticsearch Add shield after transportclient how to connect?

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.