/// <summary>Destroys the filter.</summary> /// <remarks> /// Destroys the filter. /// <p> /// It invokes the /// <see cref="AuthenticationHandler.Destroy()"/> /// method to release any resources it may hold. /// </remarks> public virtual void Destroy() { if (authHandler != null) { authHandler.Destroy(); authHandler = null; } if (secretProvider != null && isInitializedByTomcat) { secretProvider.Destroy(); secretProvider = null; } }
/// <exception cref="Javax.Servlet.ServletException"/> protected internal virtual void InitializeSecretProvider(FilterConfig filterConfig ) { secretProvider = (SignerSecretProvider)filterConfig.GetServletContext().GetAttribute (SignerSecretProviderAttribute); if (secretProvider == null) { // As tomcat cannot specify the provider object in the configuration. // It'll go into this path try { secretProvider = ConstructSecretProvider(filterConfig.GetServletContext(), config , false); isInitializedByTomcat = true; } catch (Exception ex) { throw new ServletException(ex); } } signer = new Signer(secretProvider); }
public virtual void TestDelegationTokenOperations() { CreateHttpFSServer(true); Uri url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY" ); HttpURLConnection conn = (HttpURLConnection)url.OpenConnection(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpUnauthorized, conn.GetResponseCode ()); AuthenticationToken token = new AuthenticationToken("u", "p", new KerberosDelegationTokenAuthenticationHandler ().GetType()); token.SetExpires(Runtime.CurrentTimeMillis() + 100000000); SignerSecretProvider secretProvider = StringSignerSecretProviderCreator.NewStringSignerSecretProvider (); Properties secretProviderProps = new Properties(); secretProviderProps.SetProperty(AuthenticationFilter.SignatureSecret, "secret"); secretProvider.Init(secretProviderProps, null, -1); Signer signer = new Signer(secretProvider); string tokenSigned = signer.Sign(token.ToString()); url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY"); conn = (HttpURLConnection)url.OpenConnection(); conn.SetRequestProperty("Cookie", AuthenticatedURL.AuthCookie + "=" + tokenSigned ); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode()); url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETDELEGATIONTOKEN" ); conn = (HttpURLConnection)url.OpenConnection(); conn.SetRequestProperty("Cookie", AuthenticatedURL.AuthCookie + "=" + tokenSigned ); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode()); JSONObject json = (JSONObject) new JSONParser().Parse(new InputStreamReader(conn.GetInputStream ())); json = (JSONObject)json[DelegationTokenAuthenticator.DelegationTokenJson]; string tokenStr = (string)json[DelegationTokenAuthenticator.DelegationTokenUrlStringJson ]; url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY&delegation=" + tokenStr); conn = (HttpURLConnection)url.OpenConnection(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode()); url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token=" + tokenStr); conn = (HttpURLConnection)url.OpenConnection(); conn.SetRequestMethod("PUT"); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpUnauthorized, conn.GetResponseCode ()); url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token=" + tokenStr); conn = (HttpURLConnection)url.OpenConnection(); conn.SetRequestMethod("PUT"); conn.SetRequestProperty("Cookie", AuthenticatedURL.AuthCookie + "=" + tokenSigned ); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode()); url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=CANCELDELEGATIONTOKEN&token=" + tokenStr); conn = (HttpURLConnection)url.OpenConnection(); conn.SetRequestMethod("PUT"); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, conn.GetResponseCode()); url = new Uri(TestJettyHelper.GetJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY&delegation=" + tokenStr); conn = (HttpURLConnection)url.OpenConnection(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpForbidden, conn.GetResponseCode ()); }