You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hugegraph.apache.org by GitBox <gi...@apache.org> on 2022/07/06 03:47:29 UTC

[GitHub] [incubator-hugegraph] LzMingYueShanPao opened a new issue, #1919: 使用StandardAuthenticator模式开启权限认证后,使用默认的admin账号和空串密码发送Http请求,访问HugeGraph一些查询接口,出现NotAuthorizedException异常

LzMingYueShanPao opened a new issue, #1919:
URL: https://github.com/apache/incubator-hugegraph/issues/1919

   ### Problem Type (问题类型)
   
   other exception / error (其他异常报错)
   
   ### Before submit
   
   - [X] 我已经确认现有的 [Issues](https://github.com/hugegraph/hugegraph/issues) 与 [FAQ](https://hugegraph.github.io/hugegraph-doc/guides/faq.html) 中没有相同 / 重复问题
   
   ### Environment (环境信息)
   
   图名称:meta_hugegraph
   本地HTTP地址端口:192.168.66.83:8080
   版本:HugeGraph   0.11.2
   
   ### Your Question (问题描述)
   
   使用StandardAuthenticator模式开启权限认证后,使用默认的admin账号和空串密码发送Http请求,访问HugeGraph一些查询接口,出现{"exception":"class javax.ws.rs.NotAuthorizedException","message":"Authentication failed for user 'admin'","cause":""}。
   使用的Java示例代码如下:
   import org.apache.commons.net.util.Base64;
   import org.apache.http.HttpHeaders;
   import org.apache.http.HttpResponse;
   import org.apache.http.client.HttpClient;
   import org.apache.http.client.methods.HttpGet;
   import org.apache.http.impl.client.HttpClientBuilder;
   import org.apache.http.util.EntityUtils;
   import java.nio.charset.StandardCharsets;
   
   public class GetHttp {
   
       public static void main(String[] args) throws Exception {
           String url = "http://192.168.66.83:8080/graphs/meta_hugegraph/schema/vertexlabels";
           String user = "admin";
           String password = "";
   
           HttpGet request = new HttpGet(url);
           // 手动构建验证信息
           String auth = "Basic base64(" + user + ":" + password + ")";
           byte[] encodedAuth = Base64.encodeBase64(
                   auth.getBytes(StandardCharsets.UTF_8));
           String authHeader = new String(encodedAuth);
           System.out.println(authHeader);
           // 将验证信息放入到 Header
           request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
           HttpClient client = HttpClientBuilder.create().build();
           HttpResponse response = client.execute(request);
           int statusCode = response.getStatusLine().getStatusCode();
           System.out.println(statusCode);
           String s = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
           System.out.println(s);
       }
   }
   
   ### Vertex/Edge example (问题点 / 边数据举例)
   
   ```javascript
   无
   ```
   
   
   ### Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
   
   ```javascript
   无
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-hugegraph] javeme commented on issue #1919: 使用StandardAuthenticator模式开启权限认证后,使用默认的admin账号和空串密码发送Http请求,访问HugeGraph一些查询接口,出现NotAuthorizedException异常

Posted by GitBox <gi...@apache.org>.
javeme commented on issue #1919:
URL: https://github.com/apache/incubator-hugegraph/issues/1919#issuecomment-1175764951

   看了下代码有一些问题,修改如下后再尝试下:
   ```java
   package com.baidu.hugegraph.example;
   
   import java.nio.charset.StandardCharsets;
   import java.util.Base64;
   
   import org.apache.http.HttpHeaders;
   import org.apache.http.HttpResponse;
   import org.apache.http.client.HttpClient;
   import org.apache.http.client.methods.HttpGet;
   import org.apache.http.impl.client.HttpClientBuilder;
   import org.apache.http.util.EntityUtils;
   
   public class TestHttpBasicAuth {
   
       private static final String HOST = "127.0.0.1:8080";
   
       public static void main(String[] args) throws Exception {
           String url = String.format("http://%s/graphs", HOST);
           String user = "admin";
           String password = "pa";
   
           HttpClient client = HttpClientBuilder.create().build();
   
           HttpGet request = new HttpGet(url);
           // 手动构建验证信息
           String auth = user + ":" + password;
           byte[] encodedAuth = Base64.getEncoder().encode(
                                auth.getBytes(StandardCharsets.UTF_8));
           String authHeader = "Basic " + new String(encodedAuth);
           System.out.printf("Auth Header:\n  '%s: %s'\n",
                             HttpHeaders.AUTHORIZATION, authHeader);
           // 将验证信息放入到 Header
           request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
   
           HttpResponse response = client.execute(request);
           int status = response.getStatusLine().getStatusCode();
           String result = EntityUtils.toString(response.getEntity(),
                                                StandardCharsets.UTF_8);
           System.out.printf("Response(status %s) of '%s':\n  %s\n",
                             status, url, result);
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-hugegraph] javeme closed issue #1919: 使用StandardAuthenticator模式开启权限认证后,使用默认的admin账号和空串密码发送Http请求,访问HugeGraph一些查询接口,出现NotAuthorizedException异常

Posted by GitBox <gi...@apache.org>.
javeme closed issue #1919: 使用StandardAuthenticator模式开启权限认证后,使用默认的admin账号和空串密码发送Http请求,访问HugeGraph一些查询接口,出现NotAuthorizedException异常
URL: https://github.com/apache/incubator-hugegraph/issues/1919


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org