[ 
https://issues.apache.org/jira/browse/CALCITE-4180?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17185114#comment-17185114
 ] 

fa edited comment on CALCITE-4180 at 8/26/20, 11:23 AM:
--------------------------------------------------------

I found the reason at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory#connect
{code:java}
private static RestClient connect(List<HttpHost> hosts, String pathPrefix) {
    Objects.requireNonNull(hosts, "hosts or coordinates");
    Preconditions.checkArgument(!hosts.isEmpty(), "no ES hosts specified");
    RestClientBuilder builder = RestClient.builder(hosts.toArray(new 
HttpHost[hosts.size()]));
    if (pathPrefix != null && !pathPrefix.isEmpty()) {
      builder.setPathPrefix(pathPrefix);
    }
    return builder.build();
}{code}
As shown in the code above, there is nothing authentication in that.


was (Author: geiguanbing):
I found the reason at 
`org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory#connect`

```java

private static RestClient connect(List<HttpHost> hosts, String pathPrefix) {

Objects.requireNonNull(hosts, "hosts or coordinates");
 Preconditions.checkArgument(!hosts.isEmpty(), "no ES hosts specified");

RestClientBuilder builder = RestClient.builder(hosts.toArray(new 
HttpHost[hosts.size()]));
 if (pathPrefix != null && !pathPrefix.isEmpty()) {
 builder.setPathPrefix(pathPrefix);
 }
 return builder.build();
 }

```

As shown in the code above, there is nothing authentication in that.

> Where to set elasticsearch username/password?
> ---------------------------------------------
>
>                 Key: CALCITE-4180
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4180
>             Project: Calcite
>          Issue Type: Bug
>          Components: elasticsearch-adapter
>            Reporter: fa
>            Priority: Major
>
>  
> {code:java}
> Properties config = new Properties();
> config.put("lex", "JAVA");
> String sql = "select * from index";
> try (Connection con = 
> DriverManager.getConnection("jdbc:calcite:model=src/main/resources/es.json", 
> config)) {
>     try (Statement stmt = con.createStatement()) {
>         try (ResultSet rs = stmt.executeQuery(sql)) {
>             printRs(rs);
>         }
>     }
> }
> {code}
>  
>  
> es.json
> {code:java}
> {
>   "version": "1.0",
>   "defaultSchema": "elasticsearch",
>   "schemas": [
>     {
>       "type": "custom",
>       "name": "elasticsearch",
>       "factory": 
> "org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory",
>       "operand": {
>         "coordinates": "{'192.168.133.104': 9200}",
>         "jdbcUser": "elastic",
>         "jdbcPassword": "elastic"
>       }
>     }
>   ]
> }
> {code}
> and throw Exception
> {code:java}
> {
>     "error":{
>         "root_cause":[
>             {
>                 "type":"security_exception",
>                 "reason":"missing authentication token for REST request 
> [/_alias]",
>                 "header":{
>                     "WWW-Authenticate":"Basic realm="security" 
> charset="UTF-8""
>                 }
>             }
>         ],
>         "type":"security_exception",
>         "reason":"missing authentication token for REST request [/_alias]",
>         "header":{
>             "WWW-Authenticate":"Basic realm="security" charset="UTF-8""
>         }
>     },
>     "status":401
> }
> {code}
> Where to set Elasticsearch username/password?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to