/// <summary>This method is intended to be used only while reading edit logs.</summary>
 /// <param name="identifier">
 /// DelegationTokenIdentifier read from the edit logs or
 /// fsimage
 /// </param>
 /// <param name="expiryTime">token expiry time</param>
 /// <exception cref="System.IO.IOException"/>
 public override void AddPersistedDelegationToken(DelegationTokenIdentifier identifier
                                                  , long expiryTime)
 {
     lock (this)
     {
         if (running)
         {
             // a safety check
             throw new IOException("Can't add persisted delegation token to a running SecretManager."
                                   );
         }
         int           keyId = identifier.GetMasterKeyId();
         DelegationKey dKey  = allKeys[keyId];
         if (dKey == null)
         {
             Log.Warn("No KEY found for persisted identifier " + identifier.ToString());
             return;
         }
         byte[] password = CreatePassword(identifier.GetBytes(), dKey.GetKey());
         if (identifier.GetSequenceNumber() > this.delegationTokenSequenceNumber)
         {
             this.delegationTokenSequenceNumber = identifier.GetSequenceNumber();
         }
         if (currentTokens[identifier] == null)
         {
             currentTokens[identifier] = new AbstractDelegationTokenSecretManager.DelegationTokenInformation
                                             (expiryTime, password, GetTrackingIdIfEnabled(identifier));
         }
         else
         {
             throw new IOException("Same delegation token being added twice; invalid entry in fsimage or editlogs"
                                   );
         }
     }
 }
Пример #2
0
 /// <exception cref="Org.Apache.Hadoop.Security.Token.SecretManager.InvalidToken"/>
 public virtual long GetRenewDate(RMDelegationTokenIdentifier ident)
 {
     AbstractDelegationTokenSecretManager.DelegationTokenInformation info = currentTokens
                                                                            [ident];
     if (info == null)
     {
         throw new SecretManager.InvalidToken("token (" + ident.ToString() + ") can't be found in cache"
                                              );
     }
     return(info.GetRenewDate());
 }
 /// <summary>Returns expiry time of a token given its identifier.</summary>
 /// <param name="dtId">DelegationTokenIdentifier of a token</param>
 /// <returns>Expiry time of the token</returns>
 /// <exception cref="System.IO.IOException"/>
 public virtual long GetTokenExpiryTime(DelegationTokenIdentifier dtId)
 {
     lock (this)
     {
         AbstractDelegationTokenSecretManager.DelegationTokenInformation info = currentTokens
                                                                                [dtId];
         if (info != null)
         {
             return(info.GetRenewDate());
         }
         else
         {
             throw new IOException("No delegation token found for this identifier");
         }
     }
 }
 /// <summary>Update the token cache with renewal record in edit logs.</summary>
 /// <param name="identifier">DelegationTokenIdentifier of the renewed token</param>
 /// <param name="expiryTime">expirty time in milliseconds</param>
 /// <exception cref="System.IO.IOException"/>
 public virtual void UpdatePersistedTokenRenewal(DelegationTokenIdentifier identifier
                                                 , long expiryTime)
 {
     lock (this)
     {
         if (running)
         {
             // a safety check
             throw new IOException("Can't update persisted delegation token renewal to a running SecretManager."
                                   );
         }
         AbstractDelegationTokenSecretManager.DelegationTokenInformation info = null;
         info = currentTokens[identifier];
         if (info != null)
         {
             int    keyId    = identifier.GetMasterKeyId();
             byte[] password = CreatePassword(identifier.GetBytes(), allKeys[keyId].GetKey());
             currentTokens[identifier] = new AbstractDelegationTokenSecretManager.DelegationTokenInformation
                                             (expiryTime, password, GetTrackingIdIfEnabled(identifier));
         }
     }
 }
 /// <summary>Private helper methods to save delegation keys and tokens in fsimage</summary>
 /// <exception cref="System.IO.IOException"/>
 private void SaveCurrentTokens(DataOutputStream @out, string sdPath)
 {
     lock (this)
     {
         StartupProgress prog = NameNode.GetStartupProgress();
         Step            step = new Step(StepType.DelegationTokens, sdPath);
         prog.BeginStep(Phase.SavingCheckpoint, step);
         prog.SetTotal(Phase.SavingCheckpoint, step, this._enclosing.currentTokens.Count);
         StartupProgress.Counter counter = prog.GetCounter(Phase.SavingCheckpoint, step);
         @out.WriteInt(this._enclosing.currentTokens.Count);
         IEnumerator <DelegationTokenIdentifier> iter = this._enclosing.currentTokens.Keys.
                                                        GetEnumerator();
         while (iter.HasNext())
         {
             DelegationTokenIdentifier id = iter.Next();
             id.Write(@out);
             AbstractDelegationTokenSecretManager.DelegationTokenInformation info = this._enclosing
                                                                                    .currentTokens[id];
             @out.WriteLong(info.GetRenewDate());
             counter.Increment();
         }
         prog.EndStep(Phase.SavingCheckpoint, step);
     }
 }