예제 #1
0
 public override bool Equals(object that)
 {
     if (this == that)
     {
         return(true);
     }
     else
     {
         if (that == null || !(that is DelegationTokenRenewer.RenewAction))
         {
             return(false);
         }
     }
     return(token.Equals(((DelegationTokenRenewer.RenewAction <object>)that).token));
 }
예제 #2
0
            // my sleep class
            /// <summary>attempts to access tokenCache as from client</summary>
            /// <exception cref="System.IO.IOException"/>
            /// <exception cref="System.Exception"/>
            protected override void Map(IntWritable key, IntWritable value, Mapper.Context context
                                        )
            {
                // get context token storage:
                Credentials contextCredentials = context.GetCredentials();
                ICollection <Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> > contextTokenCollection
                    = contextCredentials.GetAllTokens();

                foreach (Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> t in contextTokenCollection)
                {
                    System.Console.Out.WriteLine("Context token: [" + t + "]");
                }
                if (contextTokenCollection.Count != 2)
                {
                    // one job token and one delegation token
                    // fail the test:
                    throw new RuntimeException("Exactly 2 tokens are expected in the contextTokenCollection: "
                                               + "one job token and one delegation token, but was found " + contextTokenCollection
                                               .Count + " tokens.");
                }
                Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> dt = contextCredentials.GetToken
                                                                                  (new Text(DelegationTokenKey));
                if (dt == null)
                {
                    throw new RuntimeException("Token for key [" + DelegationTokenKey + "] not found in the job context."
                                               );
                }
                string tokenFile0 = context.GetConfiguration().Get(MRJobConfig.MapreduceJobCredentialsBinary
                                                                   );

                if (tokenFile0 != null)
                {
                    throw new RuntimeException("Token file key [" + MRJobConfig.MapreduceJobCredentialsBinary
                                               + "] found in the configuration. It should have been removed from the configuration."
                                               );
                }
                string tokenFile = context.GetConfiguration().Get(KeySecurityTokenFileName);

                if (tokenFile == null)
                {
                    throw new RuntimeException("Token file key [" + KeySecurityTokenFileName + "] not found in the job configuration."
                                               );
                }
                Credentials binaryCredentials = new Credentials();

                binaryCredentials.ReadTokenStorageStream(new DataInputStream(new FileInputStream(
                                                                                 tokenFile)));
                ICollection <Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> > binaryTokenCollection
                    = binaryCredentials.GetAllTokens();

                if (binaryTokenCollection.Count != 1)
                {
                    throw new RuntimeException("The token collection read from file [" + tokenFile +
                                               "] must have size = 1.");
                }
                Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> binTok = binaryTokenCollection
                                                                                  .GetEnumerator().Next();
                System.Console.Out.WriteLine("The token read from binary file: t = [" + binTok +
                                             "]");
                // Verify that dt is same as the token in the file:
                if (!dt.Equals(binTok))
                {
                    throw new RuntimeException("Delegation token in job is not same as the token passed in file:"
                                               + " tokenInFile=[" + binTok + "], dt=[" + dt + "].");
                }
                // Now test the user tokens.
                UserGroupInformation ugi = UserGroupInformation.GetCurrentUser();
                // Print all the UGI tokens for diagnostic purposes:
                ICollection <Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> > ugiTokenCollection
                    = ugi.GetTokens();

                foreach (Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> t_1 in ugiTokenCollection)
                {
                    System.Console.Out.WriteLine("UGI token: [" + t_1 + "]");
                }
                Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> ugiToken = ugi.GetCredentials
                                                                                        ().GetToken(new Text(DelegationTokenKey));
                if (ugiToken == null)
                {
                    throw new RuntimeException("Token for key [" + DelegationTokenKey + "] not found among the UGI tokens."
                                               );
                }
                if (!ugiToken.Equals(binTok))
                {
                    throw new RuntimeException("UGI token is not same as the token passed in binary file:"
                                               + " tokenInBinFile=[" + binTok + "], ugiTok=[" + ugiToken + "].");
                }
                base.Map(key, value, context);
            }