Java Code Examples for org.apache.hadoop.security.Credentials#mergeAll()

The following examples show how to use org.apache.hadoop.security.Credentials#mergeAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TokenCache.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static void mergeBinaryTokens(Credentials creds, Configuration conf) {
  String binaryTokenFilename =
      conf.get(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY);
  if (binaryTokenFilename != null) {
    Credentials binary;
    try {
      binary = Credentials.readTokenStorageFile(
          FileSystem.getLocal(conf).makeQualified(
              new Path(binaryTokenFilename)),
          conf);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    // supplement existing tokens with the tokens in the binary file
    creds.mergeAll(binary);
  }
}
 
Example 2
Source File: TokenCache.java    From big-c with Apache License 2.0 6 votes vote down vote up
private static void mergeBinaryTokens(Credentials creds, Configuration conf) {
  String binaryTokenFilename =
      conf.get(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY);
  if (binaryTokenFilename != null) {
    Credentials binary;
    try {
      binary = Credentials.readTokenStorageFile(
          FileSystem.getLocal(conf).makeQualified(
              new Path(binaryTokenFilename)),
          conf);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    // supplement existing tokens with the tokens in the binary file
    creds.mergeAll(binary);
  }
}
 
Example 3
Source File: TokenCache.java    From incubator-tez with Apache License 2.0 6 votes vote down vote up
/**
 * Merge tokens from a configured binary file into provided Credentials object
 * @param creds Credentials object to add new tokens to
 * @param tokenFilePath Location of tokens' binary file
 */
@InterfaceAudience.Private
public static void mergeBinaryTokens(Credentials creds,
    Configuration conf, String tokenFilePath)
    throws IOException {
  if (tokenFilePath == null || tokenFilePath.isEmpty()) {
    throw new RuntimeException("Invalid file path provided"
        + ", tokenFilePath=" + tokenFilePath);
  }
  LOG.info("Merging additional tokens from binary file"
      + ", binaryFileName=" + tokenFilePath);
  Credentials binary = Credentials.readTokenStorageFile(
      new Path("file:///" +  tokenFilePath), conf);

  // supplement existing tokens with the tokens in the binary file
  creds.mergeAll(binary);
}
 
Example 4
Source File: TokenCache.java    From tez with Apache License 2.0 6 votes vote down vote up
/**
 * Merge tokens from a configured binary file into provided Credentials object
 * @param creds Credentials object to add new tokens to
 * @param tokenFilePath Location of tokens' binary file
 */
@InterfaceAudience.Private
public static void mergeBinaryTokens(Credentials creds,
    Configuration conf, String tokenFilePath)
    throws IOException {
  if (tokenFilePath == null || tokenFilePath.isEmpty()) {
    throw new RuntimeException("Invalid file path provided"
        + ", tokenFilePath=" + tokenFilePath);
  }
  LOG.info("Merging additional tokens from binary file"
      + ", binaryFileName=" + tokenFilePath);
  Credentials binary = Credentials.readTokenStorageFile(
      new Path("file:///" +  tokenFilePath), conf);

  // supplement existing tokens with the tokens in the binary file
  creds.mergeAll(binary);
}
 
Example 5
Source File: TestCredentials.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void mergeAll() {
  Credentials creds = new Credentials();
  creds.addToken(service[0], token[0]);
  creds.addToken(service[1], token[1]);
  creds.addSecretKey(secret[0], secret[0].getBytes());
  creds.addSecretKey(secret[1], secret[1].getBytes());
  
  Credentials credsToAdd = new Credentials();
  // one duplicate with different value, one new
  credsToAdd.addToken(service[0], token[3]);
  credsToAdd.addToken(service[2], token[2]);
  credsToAdd.addSecretKey(secret[0], secret[3].getBytes());
  credsToAdd.addSecretKey(secret[2], secret[2].getBytes());
  
  creds.mergeAll(credsToAdd);
  assertEquals(3, creds.numberOfTokens());
  assertEquals(3, creds.numberOfSecretKeys());
  // existing token & secret should not be overwritten
  assertEquals(token[0], creds.getToken(service[0]));
  assertEquals(secret[0], new Text(creds.getSecretKey(secret[0])));
  // non-duplicate token & secret should be present
  assertEquals(token[1], creds.getToken(service[1]));
  assertEquals(secret[1], new Text(creds.getSecretKey(secret[1])));
  // new token & secret should be added
  assertEquals(token[2], creds.getToken(service[2]));
  assertEquals(secret[2], new Text(creds.getSecretKey(secret[2])));
}
 
Example 6
Source File: TestCredentials.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void mergeAll() {
  Credentials creds = new Credentials();
  creds.addToken(service[0], token[0]);
  creds.addToken(service[1], token[1]);
  creds.addSecretKey(secret[0], secret[0].getBytes());
  creds.addSecretKey(secret[1], secret[1].getBytes());
  
  Credentials credsToAdd = new Credentials();
  // one duplicate with different value, one new
  credsToAdd.addToken(service[0], token[3]);
  credsToAdd.addToken(service[2], token[2]);
  credsToAdd.addSecretKey(secret[0], secret[3].getBytes());
  credsToAdd.addSecretKey(secret[2], secret[2].getBytes());
  
  creds.mergeAll(credsToAdd);
  assertEquals(3, creds.numberOfTokens());
  assertEquals(3, creds.numberOfSecretKeys());
  // existing token & secret should not be overwritten
  assertEquals(token[0], creds.getToken(service[0]));
  assertEquals(secret[0], new Text(creds.getSecretKey(secret[0])));
  // non-duplicate token & secret should be present
  assertEquals(token[1], creds.getToken(service[1]));
  assertEquals(secret[1], new Text(creds.getSecretKey(secret[1])));
  // new token & secret should be added
  assertEquals(token[2], creds.getToken(service[2]));
  assertEquals(secret[2], new Text(creds.getSecretKey(secret[2])));
}
 
Example 7
Source File: TezClientUtils.java    From tez with Apache License 2.0 5 votes vote down vote up
static Credentials prepareAmLaunchCredentials(AMConfiguration amConfig, Credentials sessionCreds,
    TezConfiguration conf, Path binaryConfPath) throws IOException {
  // Setup security tokens
  Credentials amLaunchCredentials = new Credentials();

  // Add SimpleHistoryLoggingService logDir creds to the list of session credentials
  // If it is on HDFS
  String simpleHistoryLogDir = conf.get(TezConfiguration.TEZ_SIMPLE_HISTORY_LOGGING_DIR);
  if (simpleHistoryLogDir != null && !simpleHistoryLogDir.isEmpty()) {
    Path simpleHistoryLogDirPath = new Path(simpleHistoryLogDir);
    TokenCache.obtainTokensForFileSystems(sessionCreds, new Path[] { simpleHistoryLogDirPath },
        conf);
  }

  // Add Staging dir creds to the list of session credentials.
  TokenCache.obtainTokensForFileSystems(sessionCreds, new Path[] {binaryConfPath }, conf);

  populateTokenCache(conf, sessionCreds);

  // Add session specific credentials to the AM credentials.
  amLaunchCredentials.mergeAll(sessionCreds);

  if (amConfig.getCredentials() != null) {
    amLaunchCredentials.mergeAll(amConfig.getCredentials());
  }
  TezCommonUtils.logCredentials(LOG, amLaunchCredentials, "amLaunch");
  return amLaunchCredentials;
}