Java Code Examples for org.apache.hadoop.fs.FileSystem.getDelegationToken()

The following are Jave code examples for showing how to use getDelegationToken() of the org.apache.hadoop.fs.FileSystem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hadoop   File: TestWebHDFS.java   Source Code and License Vote up 6 votes
@Test
public void testDTInInsecureCluster() throws Exception {
  MiniDFSCluster cluster = null;
  final Configuration conf = WebHdfsTestUtil.createConf();
  try {
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
    final FileSystem webHdfs = WebHdfsTestUtil.getWebHdfsFileSystem(conf,
        WebHdfsFileSystem.SCHEME);
    webHdfs.getDelegationToken(null);
    fail("No exception is thrown.");
  } catch (AccessControlException ace) {
    Assert.assertTrue(ace.getMessage().startsWith(
        WebHdfsFileSystem.CANT_FALLBACK_TO_INSECURE_MSG));
  } finally {
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
Example 2
Project: ditb   File: FsDelegationToken.java   Source Code and License Vote up 6 votes
/**
 * Acquire the delegation token for the specified filesytem.
 * Before requesting a new delegation token, tries to find one already available.
 *
 * @param fs the filesystem that requires the delegation token
 * @throws IOException on fs.getDelegationToken() failure
 */
public void acquireDelegationToken(final FileSystem fs)
    throws IOException {
  if (userProvider.isHadoopSecurityEnabled()) {
    this.fs = fs;
    userToken = userProvider.getCurrent().getToken("HDFS_DELEGATION_TOKEN",
                                                    fs.getCanonicalServiceName());
    if (userToken == null) {
      hasForwardedToken = false;
      try {
        userToken = fs.getDelegationToken(renewer);
      } catch (NullPointerException npe) {
        // we need to handle NullPointerException in case HADOOP-10009 is missing
        LOG.error("Failed to get token for " + renewer);
      }
    } else {
      hasForwardedToken = true;
      LOG.info("Use the existing token: " + userToken);
    }
  }
}
 
Example 3
Project: hadoop   File: TestDistributedFileSystem.java   Source Code and License Vote up 5 votes
@Test
public void testEmptyDelegationToken() throws IOException {
  Configuration conf = getTestConfiguration();
  MiniDFSCluster cluster = null;
  try {
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
    FileSystem fileSys = cluster.getFileSystem();
    fileSys.getDelegationToken("");
  } finally {
    cluster.shutdown();
  }
}