【问题标题】:How to programmatically authenticate to HDFS in fiware cosmos如何在 fiware cosmos 中以编程方式对 HDFS 进行身份验证
【发布时间】:2015-06-19 23:31:20
【问题描述】:

我正在使用 C# 编写一个 .net 应用程序,以编程方式在 fiware 上针对 hdfs 运行 REST api,但在 http POST 操作上它失败并显示 401(拒绝访问)。它适用于简单的 GET 操作,但我不确定如何进行身份验证。从规范看来,SPEGNA 和委派的身份验证令牌是两个选项,但我如何以编程方式执行此操作?我只有我的用户名和密码可以关闭。我正在使用 RestSharp 库来简化休息交互。

此代码有效

var client = new RestClient("http://cosmos.lab.fi-ware.org:14000");
request = new RestRequest("webhdfs/v1/user/<userID>");
request.AddParameter("op", "LISTSTATUS");
request.AddParameter("user.name", "<userID>");
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string

此代码因 http 401 而失败

var client = new RestClient("http://cosmos.lab.fi-ware.org:14000");
var request = new RestRequest("webhdfs/v1/user/<userID>/structured_data123.txt",Method.PUT);
request.AddParameter("op", "CREATE");
request.AddParameter("user.name", "<userID>");
IRestResponse response = client.Execute(request);

HTTP 状态 401 - org.apache.hadoop.security.authentication.client.AuthenticationException:不允许匿名请求

想法?想法?提前谢谢你!

【问题讨论】:

    标签: fiware filab cosmos


    【解决方案1】:

    不是 RestSharp 方面的专家,我见过addParameter 方法支持 5 种类型的参数 (link)。

    根据这 5 种类型,WebHDFS 请求需要参数是“QueryString”类型(参数必须添加到请求 URI 中,而不是请求正文的一部分);

    request.AddParameter("op", "CREATE", ParameterType.QueryString);
    request.AddParameter("user.name", "<userID>", ParameterType.QueryString);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多