Search in sources :

Example 1 with DelegationTokenExtension

use of org.apache.hadoop.crypto.key.KeyProviderDelegationTokenExtension.DelegationTokenExtension in project hadoop by apache.

the class TestEncryptionZones method testDelegationToken.

/**
   * Tests obtaining delegation token from stored key
   */
@Test
public void testDelegationToken() throws Exception {
    UserGroupInformation.createRemoteUser("JobTracker");
    DistributedFileSystem dfs = cluster.getFileSystem();
    KeyProvider keyProvider = Mockito.mock(KeyProvider.class, withSettings().extraInterfaces(DelegationTokenExtension.class, CryptoExtension.class));
    Mockito.when(keyProvider.getConf()).thenReturn(conf);
    byte[] testIdentifier = "Test identifier for delegation token".getBytes();
    Token<?> testToken = new Token(testIdentifier, new byte[0], new Text(), new Text());
    Mockito.when(((DelegationTokenExtension) keyProvider).addDelegationTokens(anyString(), (Credentials) any())).thenReturn(new Token<?>[] { testToken });
    dfs.getClient().setKeyProvider(keyProvider);
    Credentials creds = new Credentials();
    final Token<?>[] tokens = dfs.addDelegationTokens("JobTracker", creds);
    DistributedFileSystem.LOG.debug("Delegation tokens: " + Arrays.asList(tokens));
    Assert.assertEquals(2, tokens.length);
    Assert.assertEquals(tokens[1], testToken);
    Assert.assertEquals(1, creds.numberOfTokens());
}
Also used : KeyProvider(org.apache.hadoop.crypto.key.KeyProvider) CryptoExtension(org.apache.hadoop.crypto.key.KeyProviderCryptoExtension.CryptoExtension) DelegationTokenExtension(org.apache.hadoop.crypto.key.KeyProviderDelegationTokenExtension.DelegationTokenExtension) Token(org.apache.hadoop.security.token.Token) Text(org.apache.hadoop.io.Text) Credentials(org.apache.hadoop.security.Credentials) Test(org.junit.Test)

Aggregations

KeyProvider (org.apache.hadoop.crypto.key.KeyProvider)1 CryptoExtension (org.apache.hadoop.crypto.key.KeyProviderCryptoExtension.CryptoExtension)1 DelegationTokenExtension (org.apache.hadoop.crypto.key.KeyProviderDelegationTokenExtension.DelegationTokenExtension)1 Text (org.apache.hadoop.io.Text)1 Credentials (org.apache.hadoop.security.Credentials)1 Token (org.apache.hadoop.security.token.Token)1 Test (org.junit.Test)1