当前位置: 首页>>代码示例>>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;未经允许,请勿转载。