Ejemplo n.º 1
0
            protected internal virtual CredentialProvider GetCredentialProvider()
            {
                CredentialProvider         provider = null;
                IList <CredentialProvider> providers;

                try
                {
                    providers = CredentialProviderFactory.GetProviders(this._enclosing.GetConf());
                    if (this._enclosing.userSuppliedProvider)
                    {
                        provider = providers[0];
                    }
                    else
                    {
                        foreach (CredentialProvider p in providers)
                        {
                            if (!p.IsTransient())
                            {
                                provider = p;
                                break;
                            }
                        }
                    }
                }
                catch (IOException e)
                {
                    Runtime.PrintStackTrace(e, this._enclosing.err);
                }
                return(provider);
            }
Ejemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        public static IList <CredentialProvider> GetProviders(Configuration conf)
        {
            IList <CredentialProvider> result = new AList <CredentialProvider>();

            foreach (string path in conf.GetStringCollection(CredentialProviderPath))
            {
                try
                {
                    URI  uri   = new URI(path);
                    bool found = false;
                    foreach (CredentialProviderFactory factory in serviceLoader)
                    {
                        CredentialProvider kp = factory.CreateProvider(uri, conf);
                        if (kp != null)
                        {
                            result.AddItem(kp);
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        throw new IOException("No CredentialProviderFactory for " + uri + " in " + CredentialProviderPath
                                              );
                    }
                }
                catch (URISyntaxException error)
                {
                    throw new IOException("Bad configuration of " + CredentialProviderPath + " at " +
                                          path, error);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <exception cref="System.Exception"/>
        public virtual void CheckPermissionRetention(Configuration conf, string ourUrl, Path
                                                     path)
        {
            CredentialProvider provider = CredentialProviderFactory.GetProviders(conf)[0];

            // let's add a new credential and flush and check that permissions are still set to 777
            char[] cred = new char[32];
            for (int i = 0; i < cred.Length; ++i)
            {
                cred[i] = (char)i;
            }
            // create a new key
            try
            {
                provider.CreateCredentialEntry("key5", cred);
            }
            catch (Exception e)
            {
                Runtime.PrintStackTrace(e);
                throw;
            }
            provider.Flush();
            // get a new instance of the provider to ensure it was saved correctly
            provider = CredentialProviderFactory.GetProviders(conf)[0];
            Assert.AssertArrayEquals(cred, provider.GetCredentialEntry("key5").GetCredential(
                                         ));
            FileSystem fs = path.GetFileSystem(conf);
            FileStatus s  = fs.GetFileStatus(path);

            Assert.True("Permissions should have been retained from the preexisting "
                        + "keystore.", s.GetPermission().ToString().Equals("rwxrwxrwx"));
        }
Ejemplo n.º 4
0
        /// <exception cref="System.Exception"/>
        internal static void CheckSpecificProvider(Configuration conf, string ourUrl)
        {
            CredentialProvider provider = CredentialProviderFactory.GetProviders(conf)[0];

            char[] passwd = GeneratePassword(16);
            // ensure that we get nulls when the key isn't there
            Assert.Equal(null, provider.GetCredentialEntry("no-such-key"));
            Assert.Equal(null, provider.GetCredentialEntry("key"));
            // create a new key
            try
            {
                provider.CreateCredentialEntry("pass", passwd);
            }
            catch (Exception e)
            {
                Runtime.PrintStackTrace(e);
                throw;
            }
            // make sure we get back the right key
            Assert.AssertArrayEquals(passwd, provider.GetCredentialEntry("pass").GetCredential
                                         ());
            // try recreating pass
            try
            {
                provider.CreateCredentialEntry("pass", passwd);
                Assert.True("should throw", false);
            }
            catch (IOException e)
            {
                Assert.Equal("Credential pass already exists in " + ourUrl, e.
                             Message);
            }
            provider.DeleteCredentialEntry("pass");
            try
            {
                provider.DeleteCredentialEntry("pass");
                Assert.True("should throw", false);
            }
            catch (IOException e)
            {
                Assert.Equal("Credential pass does not exist in " + ourUrl, e.
                             Message);
            }
            char[] passTwo = new char[] { '1', '2', '3' };
            provider.CreateCredentialEntry("pass", passwd);
            provider.CreateCredentialEntry("pass2", passTwo);
            Assert.AssertArrayEquals(passTwo, provider.GetCredentialEntry("pass2").GetCredential
                                         ());
            // write them to disk so that configuration.getPassword will find them
            provider.Flush();
            // configuration.getPassword should get this from provider
            Assert.AssertArrayEquals(passTwo, conf.GetPassword("pass2"));
            // configuration.getPassword should get this from config
            conf.Set("onetwothree", "123");
            Assert.AssertArrayEquals(passTwo, conf.GetPassword("onetwothree"));
            // configuration.getPassword should NOT get this from config since
            // we are disabling the fallback to clear text config
            conf.Set(CredentialProvider.ClearTextFallback, "false");
            Assert.AssertArrayEquals(null, conf.GetPassword("onetwothree"));
            // get a new instance of the provider to ensure it was saved correctly
            provider = CredentialProviderFactory.GetProviders(conf)[0];
            Assert.True(provider != null);
            Assert.AssertArrayEquals(new char[] { '1', '2', '3' }, provider.GetCredentialEntry
                                         ("pass2").GetCredential());
            Assert.AssertArrayEquals(passwd, provider.GetCredentialEntry("pass").GetCredential
                                         ());
            IList <string> creds = provider.GetAliases();

            Assert.True("Credentials should have been returned.", creds.Count
                        == 2);
            Assert.True("Returned Credentials should have included pass.",
                        creds.Contains("pass"));
            Assert.True("Returned Credentials should have included pass2.",
                        creds.Contains("pass2"));
        }