當前位置: 首頁>>代碼示例>>Java>>正文


Java Token.setService方法代碼示例

本文整理匯總了Java中org.apache.hadoop.security.token.Token.setService方法的典型用法代碼示例。如果您正苦於以下問題:Java Token.setService方法的具體用法?Java Token.setService怎麽用?Java Token.setService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.security.token.Token的用法示例。


在下文中一共展示了Token.setService方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verifyNewVersionToken

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
private void verifyNewVersionToken(final Configuration conf, final CustomAM am,
    Token<ClientToAMTokenIdentifier> token, MockRM rm) throws IOException,
    InterruptedException {
  UserGroupInformation ugi;
  ugi = UserGroupInformation.createRemoteUser("me");
  
  Token<ClientToAMTokenIdentifier> newToken = 
      new Token<ClientToAMTokenIdentifier>(
          new ClientToAMTokenIdentifierForTest(token.decodeIdentifier(), "message"),
          am.getClientToAMTokenSecretManager());
  newToken.setService(token.getService());
  
  ugi.addToken(newToken);

  ugi.doAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      CustomProtocol client =
          (CustomProtocol) RPC.getProxy(CustomProtocol.class, 1L, am.address,
            conf);
      client.ping();
      Assert.assertTrue(am.pinged);
      return null;
    }
  });
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:TestClientToAMTokens.java

示例2: initialize

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
@Before
public void initialize() throws Exception {
  startHACluster(0, false, false, true);
  attemptId = this.cluster.createFakeApplicationAttemptId();
  amClient = ClientRMProxy
      .createRMProxy(this.conf, ApplicationMasterProtocol.class);

  Token<AMRMTokenIdentifier> appToken =
      this.cluster.getResourceManager().getRMContext()
        .getAMRMTokenSecretManager().createAndGetAMRMToken(attemptId);
  appToken.setService(ClientRMProxy.getAMRMTokenService(conf));
  UserGroupInformation.setLoginUser(UserGroupInformation
      .createRemoteUser(UserGroupInformation.getCurrentUser()
          .getUserName()));
  UserGroupInformation.getCurrentUser().addToken(appToken);
  syncToken(appToken);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestApplicationMasterServiceProtocolOnHA.java

示例3: getDelegationToken

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
@Override
public Token<DelegationTokenIdentifier> getDelegationToken(
    final String renewer) throws IOException {
  final HttpOpParam.Op op = GetOpParam.Op.GETDELEGATIONTOKEN;
  Token<DelegationTokenIdentifier> token =
      new FsPathResponseRunner<Token<DelegationTokenIdentifier>>(
          op, null, new RenewerParam(renewer)) {
    @Override
    Token<DelegationTokenIdentifier> decodeResponse(Map<?,?> json)
        throws IOException {
      return JsonUtil.toDelegationToken(json);
    }
  }.run();
  if (token != null) {
    token.setService(tokenServiceName);
  } else {
    if (disallowFallbackToInsecureCluster) {
      throw new AccessControlException(CANT_FALLBACK_TO_INSECURE_MSG);
    }
  }
  return token;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:WebHdfsFileSystem.java

示例4: setTokenService

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
/**
 * Set the given token's service to the format expected by the RPC client 
 * @param token a delegation token
 * @param addr the socket for the rpc connection
 */
public static void setTokenService(Token<?> token, InetSocketAddress addr) {
  Text service = buildTokenService(addr);
  if (token != null) {
    token.setService(service);
    if (LOG.isDebugEnabled()) {
      LOG.debug("Acquired token "+token);  // Token#toString() prints service
    }
  } else {
    LOG.warn("Failed to get token for service "+service);
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:17,代碼來源:SecurityUtil.java

示例5: testDelegationTokenSelector

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testDelegationTokenSelector() throws Exception {
  TestDelegationTokenSecretManager dtSecretManager = 
    new TestDelegationTokenSecretManager(24*60*60*1000,
      10*1000,1*1000,3600000);
  try {
    dtSecretManager.startThreads();
    AbstractDelegationTokenSelector ds = 
    new AbstractDelegationTokenSelector<TestDelegationTokenIdentifier>(KIND);
    
    //Creates a collection of tokens
    Token<TestDelegationTokenIdentifier> token1 = generateDelegationToken(
        dtSecretManager, "SomeUser1", "JobTracker");
    token1.setService(new Text("MY-SERVICE1"));
    
    Token<TestDelegationTokenIdentifier> token2 = generateDelegationToken(
        dtSecretManager, "SomeUser2", "JobTracker");
    token2.setService(new Text("MY-SERVICE2"));
    
    List<Token<TestDelegationTokenIdentifier>> tokens =
      new ArrayList<Token<TestDelegationTokenIdentifier>>();
    tokens.add(token1);
    tokens.add(token2);
    
    //try to select a token with a given service name (created earlier)
    Token<TestDelegationTokenIdentifier> t = 
      ds.selectToken(new Text("MY-SERVICE1"), tokens);
    Assert.assertEquals(t, token1);
  } finally {
    dtSecretManager.stopThreads();
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:34,代碼來源:TestDelegationToken.java

示例6: setAMRMTokenService

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
private static void setAMRMTokenService(final Configuration conf)
    throws IOException {
  for (Token<? extends TokenIdentifier> token : UserGroupInformation
    .getCurrentUser().getTokens()) {
    if (token.getKind().equals(AMRMTokenIdentifier.KIND_NAME)) {
      token.setService(getAMRMTokenService(conf));
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:ClientRMProxy.java

示例7: convertFromYarn

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
/**
 * Convert a protobuf token into a rpc token and set its service.
 *
 * @param protoToken the yarn token
 * @param service the service for the token
 */
public static <T extends TokenIdentifier> Token<T> convertFromYarn(
    org.apache.hadoop.yarn.api.records.Token protoToken,
    Text service) {
  Token<T> token = new Token<T>(protoToken.getIdentifier().array(),
      protoToken.getPassword().array(),
      new Text(protoToken.getKind()),
      new Text(protoToken.getService()));

  if (service != null) {
    token.setService(service);
  }
  return token;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:ConverterUtils.java

示例8: generateAMRMToken

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
protected Token<AMRMTokenIdentifier> generateAMRMToken(
    ApplicationAttemptId attemptId,
    AMRMTokenSecretManager appTokenMgr) {
  Token<AMRMTokenIdentifier> appToken =
      appTokenMgr.createAndGetAMRMToken(attemptId);
  appToken.setService(new Text("appToken service"));
  return appToken;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:9,代碼來源:RMStateStoreTestBase.java

示例9: delegationToken

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
Token<DelegationTokenIdentifier> delegationToken() throws IOException {
  String delegation = param(DelegationParam.NAME);
  final Token<DelegationTokenIdentifier> token = new
    Token<DelegationTokenIdentifier>();
  token.decodeFromUrlString(delegation);
  URI nnUri = URI.create(HDFS_URI_SCHEME + "://" + namenodeId());
  boolean isLogical = HAUtil.isLogicalUri(conf, nnUri);
  if (isLogical) {
    token.setService(HAUtil.buildTokenServiceForLogicalUri(nnUri,
      HDFS_URI_SCHEME));
  } else {
    token.setService(SecurityUtil.buildTokenService(nnUri));
  }
  return token;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:16,代碼來源:ParameterParser.java

示例10: generateToken

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
public Token<AuthenticationTokenIdentifier> generateToken(String username) {
  AuthenticationTokenIdentifier ident =
      new AuthenticationTokenIdentifier(username);
  Token<AuthenticationTokenIdentifier> token =
      new Token<AuthenticationTokenIdentifier>(ident, this);
  if (clusterId.hasId()) {
    token.setService(new Text(clusterId.getId()));
  }
  return token;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:11,代碼來源:AuthenticationTokenSecretManager.java

示例11: getDelegationToken

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
@Override
public Token<?> getDelegationToken(String renewer) throws IOException {
  Token<?> token = new Token<TokenIdentifier>();
  token.setService(new Text(getCanonicalServiceName()));
  return token;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:7,代碼來源:TestViewFileSystemDelegationTokenSupport.java

示例12: testGetUgi

import org.apache.hadoop.security.token.Token; //導入方法依賴的package包/類
@Test
public void testGetUgi() throws IOException {
  conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs://localhost:4321/");
  HttpServletRequest request = mock(HttpServletRequest.class);
  ServletContext context = mock(ServletContext.class);
  String user = "TheDoctor";
  Text userText = new Text(user);
  DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(userText,
      userText, null);
  Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(
      dtId, new DummySecretManager(0, 0, 0, 0));
  String tokenString = token.encodeToUrlString();
  when(request.getParameter(JspHelper.DELEGATION_PARAMETER_NAME)).thenReturn(
      tokenString);
  when(request.getRemoteUser()).thenReturn(user);

  //Test attribute in the url to be used as service in the token.
  when(request.getParameter(JspHelper.NAMENODE_ADDRESS)).thenReturn(
      "1.1.1.1:1111");

  conf.set(DFSConfigKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(conf);

  verifyServiceInToken(context, request, "1.1.1.1:1111");
  
  //Test attribute name.node.address 
  //Set the nnaddr url parameter to null.
  when(request.getParameter(JspHelper.NAMENODE_ADDRESS)).thenReturn(null);
  InetSocketAddress addr = new InetSocketAddress("localhost", 2222);
  when(context.getAttribute(NameNodeHttpServer.NAMENODE_ADDRESS_ATTRIBUTE_KEY))
      .thenReturn(addr);
  verifyServiceInToken(context, request, addr.getAddress().getHostAddress()
      + ":2222");
  
  //Test service already set in the token
  token.setService(new Text("3.3.3.3:3333"));
  tokenString = token.encodeToUrlString();
  //Set the name.node.address attribute in Servlet context to null
  when(context.getAttribute(NameNodeHttpServer.NAMENODE_ADDRESS_ATTRIBUTE_KEY))
      .thenReturn(null);
  when(request.getParameter(JspHelper.DELEGATION_PARAMETER_NAME)).thenReturn(
      tokenString);
  verifyServiceInToken(context, request, "3.3.3.3:3333");
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:45,代碼來源:TestJspHelper.java


注:本文中的org.apache.hadoop.security.token.Token.setService方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。