當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。