Search in sources :

Example 6 with DelegationTokenInformation

use of org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation in project hadoop by apache.

the class TestDelegationToken method testParallelDelegationTokenCreation.

@Test
public void testParallelDelegationTokenCreation() throws Exception {
    final TestDelegationTokenSecretManager dtSecretManager = new TestDelegationTokenSecretManager(2000, 24 * 60 * 60 * 1000, 7 * 24 * 60 * 60 * 1000, 2000);
    try {
        dtSecretManager.startThreads();
        int numThreads = 100;
        final int numTokensPerThread = 100;
        class tokenIssuerThread implements Runnable {

            @Override
            public void run() {
                for (int i = 0; i < numTokensPerThread; i++) {
                    generateDelegationToken(dtSecretManager, "auser", "arenewer");
                    try {
                        Thread.sleep(250);
                    } catch (Exception e) {
                    }
                }
            }
        }
        Thread[] issuers = new Thread[numThreads];
        for (int i = 0; i < numThreads; i++) {
            issuers[i] = new Daemon(new tokenIssuerThread());
            issuers[i].start();
        }
        for (int i = 0; i < numThreads; i++) {
            issuers[i].join();
        }
        Map<TestDelegationTokenIdentifier, DelegationTokenInformation> tokenCache = dtSecretManager.getAllTokens();
        Assert.assertEquals(numTokensPerThread * numThreads, tokenCache.size());
        Iterator<TestDelegationTokenIdentifier> iter = tokenCache.keySet().iterator();
        while (iter.hasNext()) {
            TestDelegationTokenIdentifier id = iter.next();
            DelegationTokenInformation info = tokenCache.get(id);
            Assert.assertTrue(info != null);
            DelegationKey key = dtSecretManager.getKey(id);
            Assert.assertTrue(key != null);
            byte[] storedPassword = dtSecretManager.retrievePassword(id);
            byte[] password = dtSecretManager.createPassword(id, key);
            Assert.assertTrue(Arrays.equals(password, storedPassword));
            //verify by secret manager api
            dtSecretManager.verifyToken(id, password);
        }
    } finally {
        dtSecretManager.stopThreads();
    }
}
Also used : IOException(java.io.IOException) AccessControlException(org.apache.hadoop.security.AccessControlException) DelegationTokenInformation(org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation) Daemon(org.apache.hadoop.util.Daemon) Test(org.junit.Test)

Aggregations

DelegationTokenInformation (org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation)6 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 Text (org.apache.hadoop.io.Text)2 Test (org.junit.Test)2 Configuration (org.apache.hadoop.conf.Configuration)1 HMSHandler (org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 TokenStoreException (org.apache.hadoop.hive.thrift.DelegationTokenStore.TokenStoreException)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 InvalidToken (org.apache.hadoop.security.token.SecretManager.InvalidToken)1 Token (org.apache.hadoop.security.token.Token)1 DelegationKey (org.apache.hadoop.security.token.delegation.DelegationKey)1 Daemon (org.apache.hadoop.util.Daemon)1