Exemple #1
0
 /// <exception cref="System.IO.IOException"/>
 public override void Initialize(URI name, Configuration conf)
 {
     base.Initialize(name, conf);
     SetConf(conf);
     this.uri    = URI.Create(name.GetScheme() + "://" + name.GetAuthority());
     tokenAspect = new TokenAspect <TestTokenAspect.DummyFs>(this, SecurityUtil.BuildTokenService
                                                                 (uri), TokenKind);
     if (emulateSecurityEnabled || UserGroupInformation.IsSecurityEnabled())
     {
         tokenAspect.InitDelegationToken(ugi);
     }
 }
Exemple #2
0
        public virtual void TestRenewal()
        {
            Configuration conf = new Configuration();

            Org.Apache.Hadoop.Security.Token.Token <object> token1 = Org.Mockito.Mockito.Mock <
                Org.Apache.Hadoop.Security.Token.Token>();
            Org.Apache.Hadoop.Security.Token.Token <object> token2 = Org.Mockito.Mockito.Mock <
                Org.Apache.Hadoop.Security.Token.Token>();
            long renewCycle = 100;

            DelegationTokenRenewer.renewCycle = renewCycle;
            UserGroupInformation ugi = UserGroupInformation.CreateUserForTesting("foo", new string
                                                                                 [] { "bar" });

            TestTokenAspect.DummyFs fs = Org.Mockito.Mockito.Spy(new TestTokenAspect.DummyFs(
                                                                     ));
            Org.Mockito.Mockito.DoReturn(token1).DoReturn(token2).When(fs).GetDelegationToken
                (null);
            Org.Mockito.Mockito.DoReturn(token1).When(fs).GetRenewToken();
            // cause token renewer to abandon the token
            Org.Mockito.Mockito.DoThrow(new IOException("renew failed")).When(token1).Renew(conf
                                                                                            );
            Org.Mockito.Mockito.DoThrow(new IOException("get failed")).When(fs).AddDelegationTokens
                (null, null);
            URI uri = new URI("dummyfs://127.0.0.1:1234");
            TokenAspect <TestTokenAspect.DummyFs> tokenAspect = new TokenAspect <TestTokenAspect.DummyFs
                                                                                 >(fs, SecurityUtil.BuildTokenService(uri), TestTokenAspect.DummyFs.TokenKind);

            fs.Initialize(uri, conf);
            tokenAspect.InitDelegationToken(ugi);
            // trigger token acquisition
            tokenAspect.EnsureTokenInitialized();
            DelegationTokenRenewer.RenewAction <object> action = GetActionFromTokenAspect(tokenAspect
                                                                                          );
            Org.Mockito.Mockito.Verify(fs).SetDelegationToken(token1);
            NUnit.Framework.Assert.IsTrue(action.IsValid());
            // upon renewal, token will go bad based on above stubbing
            Sharpen.Thread.Sleep(renewCycle * 2);
            NUnit.Framework.Assert.AreSame(action, GetActionFromTokenAspect(tokenAspect));
            NUnit.Framework.Assert.IsFalse(action.IsValid());
            // now that token is invalid, should get a new one
            tokenAspect.EnsureTokenInitialized();
            Org.Mockito.Mockito.Verify(fs, Org.Mockito.Mockito.Times(2)).GetDelegationToken(Matchers.AnyString
                                                                                                ());
            Org.Mockito.Mockito.Verify(fs).SetDelegationToken(token2);
            NUnit.Framework.Assert.AreNotSame(action, GetActionFromTokenAspect(tokenAspect));
            action = GetActionFromTokenAspect(tokenAspect);
            NUnit.Framework.Assert.IsTrue(action.IsValid());
        }
        public virtual void TestTokenCompatibilityFor203()
        {
            Configuration  conf = new Configuration();
            HftpFileSystem fs   = new HftpFileSystem();

            Org.Apache.Hadoop.Security.Token.Token <object> token = new Org.Apache.Hadoop.Security.Token.Token
                                                                    <TokenIdentifier>(new byte[0], new byte[0], DelegationTokenIdentifier.HdfsDelegationKind
                                                                                      , new Text("127.0.0.1:8020"));
            Credentials cred = new Credentials();

            cred.AddToken(HftpFileSystem.TokenKind, token);
            ByteArrayOutputStream os = new ByteArrayOutputStream();

            cred.Write(new DataOutputStream(os));
            HttpURLConnection conn = Org.Mockito.Mockito.Mock <HttpURLConnection>();

            Org.Mockito.Mockito.DoReturn(new ByteArrayInputStream(os.ToByteArray())).When(conn
                                                                                          ).GetInputStream();
            Org.Mockito.Mockito.DoReturn(HttpURLConnection.HttpOk).When(conn).GetResponseCode
                ();
            URLConnectionFactory factory = Org.Mockito.Mockito.Mock <URLConnectionFactory>();

            Org.Mockito.Mockito.DoReturn(conn).When(factory).OpenConnection(Org.Mockito.Mockito
                                                                            .Any <Uri>(), Matchers.AnyBoolean());
            URI uri = new URI("hftp://127.0.0.1:8020");

            fs.Initialize(uri, conf);
            fs.connectionFactory = factory;
            UserGroupInformation ugi = UserGroupInformation.CreateUserForTesting("foo", new string
                                                                                 [] { "bar" });
            TokenAspect <HftpFileSystem> tokenAspect = new TokenAspect <HftpFileSystem>(fs, SecurityUtil
                                                                                        .BuildTokenService(uri), HftpFileSystem.TokenKind);

            tokenAspect.InitDelegationToken(ugi);
            tokenAspect.EnsureTokenInitialized();
            NUnit.Framework.Assert.AreSame(HftpFileSystem.TokenKind, fs.GetRenewToken().GetKind
                                               ());
            Org.Apache.Hadoop.Security.Token.Token <object> tok = (Org.Apache.Hadoop.Security.Token.Token
                                                                   <object>)Whitebox.GetInternalState(fs, "delegationToken");
            NUnit.Framework.Assert.AreNotSame("Not making a copy of the remote token", token,
                                              tok);
            NUnit.Framework.Assert.AreEqual(token.GetKind(), tok.GetKind());
        }
 protected internal override void InitTokenAspect()
 {
     tokenAspect = new TokenAspect <HsftpFileSystem>(this, tokenServiceName, TokenKind);
 }
 /// <summary>Initialize connectionFactory and tokenAspect.</summary>
 /// <remarks>
 /// Initialize connectionFactory and tokenAspect. This function is intended to
 /// be overridden by HsFtpFileSystem.
 /// </remarks>
 protected internal virtual void InitTokenAspect()
 {
     tokenAspect = new TokenAspect <HftpFileSystem>(this, tokenServiceName, TokenKind);
 }
Exemple #6
0
 private static DelegationTokenRenewer.RenewAction <object> GetActionFromTokenAspect
     (TokenAspect <TestTokenAspect.DummyFs> tokenAspect)
 {
     return((DelegationTokenRenewer.RenewAction <object>)Whitebox.GetInternalState(tokenAspect
                                                                                   , "action"));
 }