Example #1
0
 //NLU AuthenticationToken
 private void OnGetToken(AuthenticationToken authenticationToken, string customData)
 {
     _nluAuthenticationToken = authenticationToken.ToString();
     //Log.Debug("ExampleGetToken.OnGetToken()", "created: {0} | time to expiration: {1} minutes | token: {2}", _authenticationToken.Created, _authenticationToken.TimeUntilExpiration, _authenticationToken.Token);
 }
Example #2
0
        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
                                                ());
        }
Example #3
0
 private void OnGetTokenNLU(AuthenticationToken authenticationToken, string customData)
 {
     _authenticationTokenNLU = authenticationToken.ToString();
 }