/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> internal static string GetDelegationToken(NamenodeProtocols nn, HttpServletRequest request, Configuration conf, UserGroupInformation ugi) { Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = ugi.DoAs (new _PrivilegedExceptionAction_39(nn, ugi)); return(token == null ? null : token.EncodeToUrlString()); }
/// <summary>Cancel a Delegation Token.</summary> /// <param name="nnAddr">the NameNode's address</param> /// <param name="tok">the token to cancel</param> /// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Hadoop.Security.Authentication.Client.AuthenticationException /// "/> public static void CancelDelegationToken(URLConnectionFactory factory, URI nnAddr , Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> tok) { StringBuilder buf = new StringBuilder(nnAddr.ToString()).Append(CancelDelegationTokenServlet .PathSpec).Append("?").Append(CancelDelegationTokenServlet.Token).Append("=").Append (tok.EncodeToUrlString()); HttpURLConnection conn = Run(factory, new Uri(buf.ToString())); conn.Disconnect(); }
public virtual void TestDeserializeHAToken() { Configuration conf = DFSTestUtil.NewHAConfiguration(LogicalName); Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = new Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier>(); QueryStringDecoder decoder = new QueryStringDecoder(WebHdfsHandler.WebhdfsPrefix + "/?" + NamenodeAddressParam.Name + "=" + LogicalName + "&" + DelegationParam.Name + "=" + token.EncodeToUrlString()); ParameterParser testParser = new ParameterParser(decoder, conf); Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> tok2 = testParser .DelegationToken(); NUnit.Framework.Assert.IsTrue(HAUtil.IsTokenForLogicalUri(tok2)); }
/// <exception cref="System.Exception"/> public static void TestEncodeWritable() { string[] values = new string[] { string.Empty, "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhh", "iiiiiiiii", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM" + "NOPQRSTUVWXYZ01234567890!@#$%^&*()-=_+[]{}|;':,./<>?" }; Org.Apache.Hadoop.Security.Token.Token <AbstractDelegationTokenIdentifier> orig; Org.Apache.Hadoop.Security.Token.Token <AbstractDelegationTokenIdentifier> copy = new Org.Apache.Hadoop.Security.Token.Token <AbstractDelegationTokenIdentifier>(); // ensure that for each string the input and output values match for (int i = 0; i < values.Length; ++i) { string val = values[i]; System.Console.Out.WriteLine("Input = " + val); orig = new Org.Apache.Hadoop.Security.Token.Token <AbstractDelegationTokenIdentifier >(Runtime.GetBytesForString(val), Runtime.GetBytesForString(val) , new Text(val), new Text(val)); string encode = orig.EncodeToUrlString(); copy.DecodeFromUrlString(encode); Assert.Equal(orig, copy); CheckUrlSafe(encode); } }
/// <summary>Renew a Delegation Token.</summary> /// <param name="nnAddr">the NameNode's address</param> /// <param name="tok">the token to renew</param> /// <returns>the Date that the token will expire next.</returns> /// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Hadoop.Security.Authentication.Client.AuthenticationException /// "/> public static long RenewDelegationToken(URLConnectionFactory factory, URI nnAddr, Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> tok) { StringBuilder buf = new StringBuilder(nnAddr.ToString()).Append(RenewDelegationTokenServlet .PathSpec).Append("?").Append(RenewDelegationTokenServlet.Token).Append("=").Append (tok.EncodeToUrlString()); HttpURLConnection connection = null; BufferedReader @in = null; try { connection = Run(factory, new Uri(buf.ToString())); @in = new BufferedReader(new InputStreamReader(connection.GetInputStream(), Charsets .Utf8)); long result = long.Parse(@in.ReadLine()); return(result); } catch (IOException ie) { Log.Info("error in renew over HTTP", ie); IOException e = GetExceptionFromResponse(connection); if (e != null) { Log.Info("rethrowing exception from HTTP request: " + e.GetLocalizedMessage()); throw e; } throw; } finally { IOUtils.Cleanup(Log, @in); if (connection != null) { connection.Disconnect(); } } }
/// <exception cref="System.IO.IOException"/> private static IDictionary DelegationTokenToJSON(Org.Apache.Hadoop.Security.Token.Token token) { IDictionary json = new LinkedHashMap(); json[KerberosDelegationTokenAuthenticator.DelegationTokenUrlStringJson] = token.EncodeToUrlString (); IDictionary response = new LinkedHashMap(); response[KerberosDelegationTokenAuthenticator.DelegationTokenJson] = json; return(response); }