当前位置: 首页>>代码示例>>Java>>正文


Java Credentials.addSecretKey方法代码示例

本文整理汇总了Java中org.apache.hadoop.security.Credentials.addSecretKey方法的典型用法代码示例。如果您正苦于以下问题:Java Credentials.addSecretKey方法的具体用法?Java Credentials.addSecretKey怎么用?Java Credentials.addSecretKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.security.Credentials的用法示例。


在下文中一共展示了Credentials.addSecretKey方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUGICredentialsPropogation

import org.apache.hadoop.security.Credentials; //导入方法依赖的package包/类
@Test
public void testUGICredentialsPropogation() throws Exception {
  Credentials creds = new Credentials();
  Token<?> token = mock(Token.class);
  Text tokenService = new Text("service");
  Text secretName = new Text("secret");
  byte secret[] = new byte[]{};
      
  creds.addToken(tokenService,  token);
  creds.addSecretKey(secretName, secret);
  UserGroupInformation.getLoginUser().addCredentials(creds);
  
  JobConf jobConf = new JobConf();
  Job job = new Job(jobConf);

  assertSame(token, job.getCredentials().getToken(tokenService));
  assertSame(secret, job.getCredentials().getSecretKey(secretName));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestJob.java

示例2: addAll

import org.apache.hadoop.security.Credentials; //导入方法依赖的package包/类
@Test
public void addAll() {
  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.addAll(credsToAdd);
  assertEquals(3, creds.numberOfTokens());
  assertEquals(3, creds.numberOfSecretKeys());
  // existing token & secret should be overwritten
  assertEquals(token[3], creds.getToken(service[0]));
  assertEquals(secret[3], 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])));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:29,代码来源:TestCredentials.java

示例3: mergeAll

import org.apache.hadoop.security.Credentials; //导入方法依赖的package包/类
@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])));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:29,代码来源:TestCredentials.java

示例4: getCredentialsFromAppAttempt

import org.apache.hadoop.security.Credentials; //导入方法依赖的package包/类
public Credentials getCredentialsFromAppAttempt(RMAppAttempt appAttempt) {
  Credentials credentials = new Credentials();

  SecretKey clientTokenMasterKey =
      appAttempt.getClientTokenMasterKey();
  if(clientTokenMasterKey != null){
    credentials.addSecretKey(AM_CLIENT_TOKEN_MASTER_KEY_NAME,
        clientTokenMasterKey.getEncoded());
  }
  return credentials;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:RMStateStore.java

示例5: testAttemptContainerRequest

import org.apache.hadoop.security.Credentials; //导入方法依赖的package包/类
@Test
public void testAttemptContainerRequest() throws Exception {
  final Text SECRET_KEY_ALIAS = new Text("secretkeyalias");
  final byte[] SECRET_KEY = ("secretkey").getBytes();
  Map<ApplicationAccessType, String> acls =
      new HashMap<ApplicationAccessType, String>(1);
  acls.put(ApplicationAccessType.VIEW_APP, "otheruser");
  ApplicationId appId = ApplicationId.newInstance(1, 1);
  JobId jobId = MRBuilderUtils.newJobId(appId, 1);
  TaskId taskId = MRBuilderUtils.newTaskId(jobId, 1, TaskType.MAP);
  Path jobFile = mock(Path.class);

  EventHandler eventHandler = mock(EventHandler.class);
  TaskAttemptListener taListener = mock(TaskAttemptListener.class);
  when(taListener.getAddress()).thenReturn(new InetSocketAddress("localhost", 0));

  JobConf jobConf = new JobConf();
  jobConf.setClass("fs.file.impl", StubbedFS.class, FileSystem.class);
  jobConf.setBoolean("fs.file.impl.disable.cache", true);
  jobConf.set(JobConf.MAPRED_MAP_TASK_ENV, "");

  // setup UGI for security so tokens and keys are preserved
  jobConf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(jobConf);

  Credentials credentials = new Credentials();
  credentials.addSecretKey(SECRET_KEY_ALIAS, SECRET_KEY);
  Token<JobTokenIdentifier> jobToken = new Token<JobTokenIdentifier>(
      ("tokenid").getBytes(), ("tokenpw").getBytes(),
      new Text("tokenkind"), new Text("tokenservice"));

  TaskAttemptImpl taImpl =
      new MapTaskAttemptImpl(taskId, 1, eventHandler, jobFile, 1,
          mock(TaskSplitMetaInfo.class), jobConf, taListener,
          jobToken, credentials,
          new SystemClock(), null);

  jobConf.set(MRJobConfig.APPLICATION_ATTEMPT_ID, taImpl.getID().toString());

  ContainerLaunchContext launchCtx =
      TaskAttemptImpl.createContainerLaunchContext(acls,
          jobConf, jobToken, taImpl.createRemoteTask(),
          TypeConverter.fromYarn(jobId),
          mock(WrappedJvmID.class), taListener,
          credentials);

  Assert.assertEquals("ACLs mismatch", acls, launchCtx.getApplicationACLs());
  Credentials launchCredentials = new Credentials();

  DataInputByteBuffer dibb = new DataInputByteBuffer();
  dibb.reset(launchCtx.getTokens());
  launchCredentials.readTokenStorageStream(dibb);

  // verify all tokens specified for the task attempt are in the launch context
  for (Token<? extends TokenIdentifier> token : credentials.getAllTokens()) {
    Token<? extends TokenIdentifier> launchToken =
        launchCredentials.getToken(token.getService());
    Assert.assertNotNull("Token " + token.getService() + " is missing",
        launchToken);
    Assert.assertEquals("Token " + token.getService() + " mismatch",
        token, launchToken);
  }

  // verify the secret key is in the launch context
  Assert.assertNotNull("Secret key missing",
      launchCredentials.getSecretKey(SECRET_KEY_ALIAS));
  Assert.assertTrue("Secret key mismatch", Arrays.equals(SECRET_KEY,
      launchCredentials.getSecretKey(SECRET_KEY_ALIAS)));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:70,代码来源:TestTaskAttemptContainerRequest.java

示例6: setShuffleSecretKey

import org.apache.hadoop.security.Credentials; //导入方法依赖的package包/类
@InterfaceAudience.Private
public static void setShuffleSecretKey(byte[] key, Credentials credentials) {
  credentials.addSecretKey(SHUFFLE_TOKEN, key);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:5,代码来源:TokenCache.java

示例7: setEncryptedSpillKey

import org.apache.hadoop.security.Credentials; //导入方法依赖的package包/类
@InterfaceAudience.Private
public static void setEncryptedSpillKey(byte[] key, Credentials credentials) {
  credentials.addSecretKey(ENC_SPILL_KEY, key);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:5,代码来源:TokenCache.java


注:本文中的org.apache.hadoop.security.Credentials.addSecretKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。