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


Java TokenIdentifier类代码示例

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


TokenIdentifier类属于org.apache.hadoop.security.token包,在下文中一共展示了TokenIdentifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFileSystemForServiceName

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
public static MockFileSystem createFileSystemForServiceName(
    final Text service, final FileSystem... children) throws IOException {
  final MockFileSystem fs = new MockFileSystem();
  final MockFileSystem mockFs = fs.getRawFileSystem();
  if (service != null) {
    when(mockFs.getCanonicalServiceName()).thenReturn(service.toString());
    when(mockFs.getDelegationToken(any(String.class))).thenAnswer(
      new Answer<Token<?>>() {
        @Override
        public Token<?> answer(InvocationOnMock invocation) throws Throwable {
          Token<?> token = new Token<TokenIdentifier>();
          token.setService(service);
          return token;
        }
      });
  }
  when(mockFs.getChildFileSystems()).thenReturn(children);
  return fs;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestFileSystemTokens.java

示例2: testAddCreds

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@SuppressWarnings("unchecked") // from Mockito mocks
@Test (timeout = 30000)
public <T extends TokenIdentifier> void testAddCreds() throws Exception {
  UserGroupInformation ugi = 
      UserGroupInformation.createRemoteUser("someone"); 
  
  Text service = new Text("service");
  Token<T> t1 = mock(Token.class);
  when(t1.getService()).thenReturn(service);
  Token<T> t2 = mock(Token.class);
  when(t2.getService()).thenReturn(new Text("service2"));
  byte[] secret = new byte[]{};
  Text secretKey = new Text("sshhh");

  // fill credentials
  Credentials creds = new Credentials();
  creds.addToken(t1.getService(), t1);
  creds.addToken(t2.getService(), t2);
  creds.addSecretKey(secretKey, secret);
  
  // add creds to ugi, and check ugi
  ugi.addCredentials(creds);
  checkTokens(ugi, t1, t2);
  assertSame(secret, ugi.getCredentials().getSecretKey(secretKey));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestUserGroupInformation.java

示例3: testGetRemoteToken

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@Test
public void testGetRemoteToken() throws IOException, URISyntaxException {
  Configuration conf = new Configuration();
  DummyFs fs = spy(new DummyFs());
  Token<TokenIdentifier> token = new Token<TokenIdentifier>(new byte[0],
      new byte[0], DummyFs.TOKEN_KIND, new Text("127.0.0.1:1234"));

  doReturn(token).when(fs).getDelegationToken(anyString());
  doReturn(token).when(fs).getRenewToken();

  fs.initialize(new URI("dummyfs://127.0.0.1:1234"), conf);

  fs.tokenAspect.ensureTokenInitialized();

  // Select a token, store and renew it
  verify(fs).setDelegationToken(token);
  assertNotNull(Whitebox.getInternalState(fs.tokenAspect, "dtRenewer"));
  assertNotNull(Whitebox.getInternalState(fs.tokenAspect, "action"));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestTokenAspect.java

示例4: testGetCreds

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@SuppressWarnings("unchecked") // from Mockito mocks
@Test (timeout = 30000)
public <T extends TokenIdentifier> void testGetCreds() throws Exception {
  UserGroupInformation ugi = 
      UserGroupInformation.createRemoteUser("someone"); 
  
  Text service = new Text("service");
  Token<T> t1 = mock(Token.class);
  when(t1.getService()).thenReturn(service);
  Token<T> t2 = mock(Token.class);
  when(t2.getService()).thenReturn(new Text("service2"));
  Token<T> t3 = mock(Token.class);
  when(t3.getService()).thenReturn(service);
  
  // add token to ugi
  ugi.addToken(t1);
  ugi.addToken(t2);
  checkTokens(ugi, t1, t2);

  Credentials creds = ugi.getCredentials();
  creds.addToken(t3.getService(), t3);
  assertSame(t3, creds.getToken(service));
  // check that ugi wasn't modified
  checkTokens(ugi, t1, t2);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestUserGroupInformation.java

示例5: verifyTokenService

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
private void
verifyTokenService(InetSocketAddress addr, String host, String ip, int port, boolean useIp) {
  //LOG.info("address:"+addr+" host:"+host+" ip:"+ip+" port:"+port);

  SecurityUtil.setTokenServiceUseIp(useIp);
  String serviceHost = useIp ? ip : StringUtils.toLowerCase(host);
  
  Token<?> token = new Token<TokenIdentifier>();
  Text service = new Text(serviceHost+":"+port);
  
  assertEquals(service, SecurityUtil.buildTokenService(addr));
  SecurityUtil.setTokenService(token, addr);
  assertEquals(service, token.getService());
  
  InetSocketAddress serviceAddr = SecurityUtil.getTokenServiceAddr(token);
  assertNotNull(serviceAddr);
  verifyValues(serviceAddr, serviceHost, ip, port);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:TestSecurityUtil.java

示例6: testAddNamedToken

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@SuppressWarnings("unchecked") // from Mockito mocks
@Test (timeout = 30000)
public <T extends TokenIdentifier> void testAddNamedToken() throws Exception {
  UserGroupInformation ugi = 
      UserGroupInformation.createRemoteUser("someone"); 
  
  Token<T> t1 = mock(Token.class);
  Text service1 = new Text("t1");
  Text service2 = new Text("t2");
  when(t1.getService()).thenReturn(service1);
  
  // add token
  ugi.addToken(service1, t1);
  assertSame(t1, ugi.getCredentials().getToken(service1));

  // add token with another name
  ugi.addToken(service2, t1);
  assertSame(t1, ugi.getCredentials().getToken(service1));
  assertSame(t1, ugi.getCredentials().getToken(service2));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:TestUserGroupInformation.java

示例7: selectToken

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@Override
public Token<AuthenticationTokenIdentifier> selectToken(Text serviceName,
    Collection<Token<? extends TokenIdentifier>> tokens) {
  if (serviceName != null) {
    for (Token ident : tokens) {
      if (serviceName.equals(ident.getService()) &&
          AuthenticationTokenIdentifier.AUTH_TOKEN_TYPE.equals(ident.getKind())) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Returning token "+ident);
        }
        return (Token<AuthenticationTokenIdentifier>)ident;
      }
    }
  }
  LOG.debug("No matching token found");
  return null;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:18,代码来源:AuthenticationTokenSelector.java

示例8: testPrivateTokenExclusion

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
/**
 * In some scenario, such as HA, delegation tokens are associated with a
 * logical name. The tokens are cloned and are associated with the
 * physical address of the server where the service is provided.
 * This test ensures cloned delegated tokens are locally used
 * and are not returned in {@link UserGroupInformation#getCredentials()}
 */
@Test
public void testPrivateTokenExclusion() throws Exception  {
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  TestTokenIdentifier tokenId = new TestTokenIdentifier();
  Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(
          tokenId.getBytes(), "password".getBytes(),
          tokenId.getKind(), null);
  ugi.addToken(new Text("regular-token"), token);

  // Now add cloned private token
  ugi.addToken(new Text("private-token"), new Token.PrivateToken<TestTokenIdentifier>(token));
  ugi.addToken(new Text("private-token1"), new Token.PrivateToken<TestTokenIdentifier>(token));

  // Ensure only non-private tokens are returned
  Collection<Token<? extends TokenIdentifier>> tokens = ugi.getCredentials().getAllTokens();
  assertEquals(1, tokens.size());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:TestUserGroupInformation.java

示例9: selectToken

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Token<AMRMTokenIdentifier> selectToken(Text service,
    Collection<Token<? extends TokenIdentifier>> tokens) {
  if (service == null) {
    return null;
  }
  LOG.debug("Looking for a token with service " + service.toString());
  for (Token<? extends TokenIdentifier> token : tokens) {
    LOG.debug("Token kind is " + token.getKind().toString()
        + " and the token's service name is " + token.getService());
    if (AMRMTokenIdentifier.KIND_NAME.equals(token.getKind())
        && checkService(service, token)) {
      return (Token<AMRMTokenIdentifier>) token;
    }
  }
  return null;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:AMRMTokenSelector.java

示例10: getTokenInfo

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@Override
public TokenInfo getTokenInfo(Class<?> protocol, Configuration conf) {
  if (!protocol
      .equals(ContainerManagementProtocolPB.class)) {
    return null;
  }
  return new TokenInfo() {

    @Override
    public Class<? extends Annotation> annotationType() {
      return null;
    }

    @Override
    public Class<? extends TokenSelector<? extends TokenIdentifier>>
        value() {
      return NMTokenSelector.class;
    }
  };

}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:ContainerManagerSecurityInfo.java

示例11: getTokenInfo

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@Override
public TokenInfo getTokenInfo(Class<?> protocol, Configuration conf) {
  if (!protocol.equals(ApplicationMasterProtocolPB.class)) {
    return null;
  }
  return new TokenInfo() {

    @Override
    public Class<? extends Annotation> annotationType() {
      return null;
    }

    @Override
    public Class<? extends TokenSelector<? extends TokenIdentifier>>
        value() {
      return AMRMTokenSelector.class;
    }
  };
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:SchedulerSecurityInfo.java

示例12: selectToken

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Token<TimelineDelegationTokenIdentifier> selectToken(Text service,
    Collection<Token<? extends TokenIdentifier>> tokens) {
  if (service == null) {
    return null;
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug("Looking for a token with service " + service.toString());
  }
  for (Token<? extends TokenIdentifier> token : tokens) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Token kind is " + token.getKind().toString()
          + " and the token's service name is " + token.getService());
    }
    if (TimelineDelegationTokenIdentifier.KIND_NAME.equals(token.getKind())
        && service.equals(token.getService())) {
      return (Token<TimelineDelegationTokenIdentifier>) token;
    }
  }
  return null;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:TimelineDelegationTokenSelector.java

示例13: selectToken

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Token<RMDelegationTokenIdentifier> selectToken(Text service,
    Collection<Token<? extends TokenIdentifier>> tokens) {
  if (service == null) {
    return null;
  }
  LOG.debug("Looking for a token with service " + service.toString());
  for (Token<? extends TokenIdentifier> token : tokens) {
    LOG.debug("Token kind is " + token.getKind().toString()
        + " and the token's service name is " + token.getService());
    if (RMDelegationTokenIdentifier.KIND_NAME.equals(token.getKind())
        && checkService(service, token)) {
      return (Token<RMDelegationTokenIdentifier>) token;
    }
  }
  return null;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:RMDelegationTokenSelector.java

示例14: getTokenInfo

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@Override
public TokenInfo getTokenInfo(Class<?> protocol, Configuration conf) {
  if (!protocol
      .equals(ApplicationClientProtocolPB.class)) {
    return null;
  }
  return new TokenInfo() {

    @Override
    public Class<? extends Annotation> annotationType() {
      return null;
    }

    @Override
    public Class<? extends TokenSelector<? extends TokenIdentifier>>
        value() {
      return RMDelegationTokenSelector.class;
    }
  };
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:ClientRMSecurityInfo.java

示例15: selectToken

import org.apache.hadoop.security.token.TokenIdentifier; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Token<ClientToAMTokenIdentifier> selectToken(Text service,
    Collection<Token<? extends TokenIdentifier>> tokens) {
  if (service == null) {
    return null;
  }
  LOG.debug("Looking for a token with service " + service.toString());
  for (Token<? extends TokenIdentifier> token : tokens) {
    LOG.debug("Token kind is " + token.getKind().toString()
        + " and the token's service name is " + token.getService());
    if (ClientToAMTokenIdentifier.KIND_NAME.equals(token.getKind())
        && service.equals(token.getService())) {
      return (Token<ClientToAMTokenIdentifier>) token;
    }
  }
  return null;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:ClientToAMTokenSelector.java


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