0

I would like to make a webhdfs call to retrive a file from secure node using Java.

Here is what I am doing 1. login using keytab (works fine). I am getting a kerberos ticket 2. Now when I try to invoke the below code, what it does is, it tries to get the delegationtoken by making a https call and it fails with 401 https://mynode:50070/webhdfs/v1/?op=GETDELEGATIONTOKEN&user.name=myuser

Here is the code to open the hdfs file FileSystem webFS = FileSystem.get(new URI("swebhdfs://" + domain + "myfile"), conf);
BufferedReader br=new BufferedReader(new InputStreamReader(webFS.open(new Path("swebhdfs://" + domain + "myfile"))));

My question is since I have the kerberos ticket, how can I pass that one to UserGropupInformation object?

Thanks,

1 Answers1

0

I'm assuming you have access to keytab file. Add the following snippet before you connect to hadoop cluster.
The loginUserFromKeytab method will load and authenticate with the keytab for the specified user. ('logs in' in simple terms)

String user = "USER@REALM"
String keyPath = "somekeytab.keytab"
UserGroupInformation.loginUserFromKeytab(user, keyPath)

UserGroupInformation is located in hadoop-common jar.

Reference :

Authenticating Kerberos Principals in Java Code

Shyam
  • 516
  • 3
  • 7