/// <summary> /// Check if the CMIS server holds the client brand files /// </summary> /// <param name="credentials"></param> /// <returns>Whether the CMIS server holds the client brand files</returns> public bool TestServer(ServerCredentials credentials) { IRepository repo = this.GetRepo(credentials); if (repo == null) { return false; } try { ISession session = repo.CreateSession(); foreach (string path in this.PathList) { try { IDocument doc = session.GetObjectByPath(path) as IDocument; if (doc == null) { return false; } } catch (CmisObjectNotFoundException e) { Logger.Debug(e.ErrorContent, e); return false; } } } catch (Exception e) { Logger.Debug(e.Message, e); return false; } return true; }
public void GetRepositoriesTroughProxy( string cmisServerUrl, string cmisUser, string cmisPassword, string proxyUrl, string proxyUser, string proxyPassword) { if (string.IsNullOrEmpty(proxyUrl)) { Assert.Ignore(); } ServerCredentials credentials = new ServerCredentials { Address = new Uri(cmisServerUrl), UserName = cmisUser, Password = cmisPassword }; ProxySettings proxySettings = new ProxySettings(); proxySettings.Selection = string.IsNullOrEmpty(cmisServerUrl) ? ProxySelection.NOPROXY : ProxySelection.CUSTOM; proxySettings.Server = new Uri(proxyUrl); proxySettings.LoginRequired = !string.IsNullOrEmpty(proxyUser); if (proxySettings.LoginRequired) { proxySettings.Username = proxyUser; proxySettings.ObfuscatedPassword = Crypto.Obfuscate(proxyPassword); } HttpProxyUtils.SetDefaultProxy(proxySettings, true); Assert.That(credentials.GetRepositories(), Is.Not.Empty); }
public void SetServerAddress() { string url = "http://example.com/"; var cred = new ServerCredentials { Address = new Uri(url) }; Assert.AreEqual(url, cred.Address.ToString()); }
static public Dictionary<string, string> GetCmisParameters(ServerCredentials credentials) { Dictionary<string, string> cmisParameters = new Dictionary<string, string>(); cmisParameters[SessionParameter.BindingType] = credentials.Binding; if (credentials.Binding == BindingType.AtomPub) { cmisParameters[SessionParameter.AtomPubUrl] = credentials.Address.ToString(); } else if (credentials.Binding == BindingType.Browser) { cmisParameters[SessionParameter.BrowserUrl] = credentials.Address.ToString(); } cmisParameters[SessionParameter.User] = credentials.UserName; cmisParameters[SessionParameter.Password] = credentials.Password.ToString(); cmisParameters[SessionParameter.UserAgent] = Utils.CreateUserAgent(); return cmisParameters; }
public void GetRepositoriesReturnsListOfReposInOrder() { var underTest = new ServerCredentials { Address = new Uri("https://demo.deutsche-wolke.de/cmis/browser"), Binding = DotCMIS.BindingType.Browser, UserName = "******", Password = "******" }; var name = "Name"; var id = Guid.NewGuid().ToString(); var sessionFactory = new Mock<ISessionFactory>(); sessionFactory.SetupRepositories(Mock.Of<IRepository>(r => r.Id == id && r.Name == name), Mock.Of<IRepository>(r => r.Id == Guid.NewGuid().ToString() && r.Name == "other")); var repos = underTest.GetRepositories(sessionFactory.Object); Assert.That(repos.Count, Is.EqualTo(2)); Assert.That(repos.First().Id, Is.EqualTo(id)); Assert.That(repos.First().Name, Is.EqualTo(name)); }
public void TestServer( string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId, string binding) { ServerCredentials credentials = new ServerCredentials() { Address = new Uri(url), Binding = binding, UserName = user, Password = password }; var underTest = new ClientBrand(credentials, repositoryId, remoteFolderPath); Assert.That(underTest.TestServer(credentials), Is.True); }
private IRepository GetRepo(ServerCredentials credentials) { Dictionary<string, string> parameters = CmisUtils.GetCmisParameters(credentials); try { ISessionFactory factory = SessionFactory.NewInstance(); IList<IRepository> repos = factory.GetRepositories(parameters); foreach (IRepository repo in repos) { if (repo.Name == this.RepoName) { return repo; } } return null; } catch (Exception e) { Logger.Debug(e.Message); return null; } }
private void CheckPassword(object sender, DoWorkEventArgs args) { if (!passwordChanged) { return; } Dispatcher.BeginInvoke((Action)delegate { passwordHelp.Text = Properties_Resources.LoginCheck; passwordBox.IsEnabled = false; passwordProgress.Visibility = Visibility.Visible; }); ServerCredentials cred = new ServerCredentials() { Address = Credentials.Address, Binding = Credentials.Binding, UserName = Credentials.UserName, Password = passwordBox.Password }; cred.GetRepositories(); }
/// <summary> /// Load repositories information from a CMIS endpoint. /// </summary> public static LoginCredentials GetRepositories(ServerCredentials credentials) { var multipleCredentials = credentials.CreateFuzzyCredentials(); foreach (var cred in multipleCredentials) { if (cred.LogIn()) { return cred; } } return multipleCredentials.OrderBy(cred => cred.Priority).First(); }
public void CreateMultipleServerCredentialsBasedOnTheGivenOne() { var userName = "******"; var originalUrl = "https://demo.deutsche-wolke.de/wrongStuff"; var password = new Password(Guid.NewGuid().ToString()); var originalCredentials = new ServerCredentials { Address = new Uri(originalUrl), Password = password, Binding = BindingType.Browser, UserName = userName }; var list = originalCredentials.CreateFuzzyCredentials(); Assert.That(list, Is.Not.Null); Assert.That(list, Is.Not.Empty); Assert.That(list.First().Credentials, Is.EqualTo(originalCredentials)); Assert.That(list[1].Credentials.Address.ToString(), Is.EqualTo(originalCredentials.Address.ToString())); Assert.That(list[1].Credentials.Binding, Is.Not.EqualTo(originalCredentials.Binding)); foreach (var entry in list) { Assert.That(entry.Credentials.Password.ToString(), Is.EqualTo(password.ToString())); Assert.That(entry.Credentials.UserName, Is.EqualTo(userName)); Console.WriteLine(entry); } }
private void ShowAdd1Page() { this.Present(); this.Header = Properties_Resources.Where; VBox layout_vertical = new VBox(false, 12); HBox layout_fields = new HBox(true, 12); VBox layout_address = new VBox(true, 0); HBox layout_address_help = new HBox(false, 3); VBox layout_user = new VBox(true, 0); VBox layout_password = new VBox(true, 0); // Address Label address_label = new Label() { UseMarkup = true, Xalign = 0, Markup = "<b>" + Properties_Resources.EnterWebAddress + "</b>" }; Entry address_entry = new Entry() { Text = (this.controller.PreviousAddress == null || string.IsNullOrEmpty(this.controller.PreviousAddress.ToString())) ? DefaultEntries.Defaults.Url : this.controller.PreviousAddress.ToString(), IsEditable = DefaultEntries.Defaults.CanModifyUrl, ActivatesDefault = false }; Label address_help_label = new Label() { Xalign = 0, UseMarkup = true, Markup = "<span foreground=\"#808080\" size=\"small\">" + Properties_Resources.Help + ": " + "</span>" }; EventBox address_help_urlbox = new EventBox(); Label address_help_urllabel = new Label() { Xalign = 0, UseMarkup = true, Markup = "<span foreground=\"blue\" underline=\"single\" size=\"small\">" + Properties_Resources.WhereToFind + "</span>" }; address_help_urlbox.Add(address_help_urllabel); address_help_urlbox.ButtonPressEvent += delegate(object o, ButtonPressEventArgs args) { Process process = new Process(); process.StartInfo.FileName = "xdg-open"; process.StartInfo.Arguments = "https://github.com/nicolas-raoul/CmisSync/wiki/What-address"; process.Start(); }; address_help_urlbox.EnterNotifyEvent += delegate(object o, EnterNotifyEventArgs args) { address_help_urlbox.GdkWindow.Cursor = handCursor; }; Label address_error_label = new Label() { Xalign = 0, UseMarkup = true, Markup = string.Empty }; address_error_label.Hide(); // User Entry user_entry = new Entry() { Text = this.controller.PreviousPath, ActivatesDefault = false }; if (string.IsNullOrEmpty(this.controller.saved_user)) { user_entry.Text = DefaultEntries.Defaults.Name; } else { user_entry.Text = this.controller.saved_user; } // Password Entry password_entry = new Entry() { Visibility = false, ActivatesDefault = true }; this.controller.ChangeAddressFieldEvent += delegate(string text, string example_text) { Application.Invoke(delegate { address_entry.Text = text; }); }; this.controller.ChangeUserFieldEvent += delegate(string text, string example_text) { Application.Invoke(delegate { user_entry.Text = text; }); }; this.controller.ChangePasswordFieldEvent += delegate(string text, string example_text) { Application.Invoke(delegate { password_entry.Text = text; }); }; address_entry.Changed += delegate { string error = this.controller.CheckAddPage(address_entry.Text); if (!string.IsNullOrEmpty(error)) { address_error_label.Markup = "<span foreground=\"red\">" + Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture) + "</span>"; address_error_label.Show(); } else { address_error_label.Hide(); } }; // Address layout_address_help.PackStart(address_help_label, false, false, 0); layout_address_help.PackStart(address_help_urlbox, false, false, 0); layout_address.PackStart(address_label, true, true, 0); layout_address.PackStart(address_entry, true, true, 0); layout_address.PackStart(layout_address_help, true, true, 0); // User layout_user.PackStart( new Label() { Markup = "<b>" + Properties_Resources.User + ":</b>", Xalign = 0 }, true, true, 0); layout_user.PackStart(user_entry, false, false, 0); // Password layout_password.PackStart( new Label() { Markup = "<b>" + Properties_Resources.Password + ":</b>", Xalign = 0 }, true, true, 0); layout_password.PackStart(password_entry, false, false, 0); layout_fields.PackStart(layout_user); layout_fields.PackStart(layout_password); layout_vertical.PackStart(layout_address, false, false, 0); layout_vertical.PackStart(layout_fields, false, false, 0); layout_vertical.PackStart(address_error_label, true, true, 0); this.Add(layout_vertical); // Cancel button Button cancel_button = new Button(this.cancelText); cancel_button.Clicked += delegate { this.controller.PageCancelled(); }; // Continue button Button continue_button = new Button(this.continueText) { Sensitive = string.IsNullOrEmpty(this.controller.CheckAddPage(address_entry.Text)) }; continue_button.Clicked += delegate { // Show wait cursor this.GdkWindow.Cursor = waitCursor; // Try to find the CMIS server (asynchronous using a delegate) GetRepositoriesDelegate dlgt = new GetRepositoriesDelegate(SetupController.GetRepositories); ServerCredentials credentials = new ServerCredentials() { UserName = user_entry.Text, Password = password_entry.Text, Address = new Uri(address_entry.Text), Binding = this.controller.saved_binding ?? ServerCredentials.BindingBrowser }; IAsyncResult ar = dlgt.BeginInvoke(credentials, null, null); while (!ar.AsyncWaitHandle.WaitOne(100)) { while (Application.EventsPending()) { Application.RunIteration(); } } var result = dlgt.EndInvoke(ar); if (result.Repositories != null) { this.controller.repositories = result.Repositories.WithoutHiddenOnce(); address_entry.Text = result.Credentials.Address.ToString(); } else { this.controller.repositories = null; // Show best found Url address_entry.Text = result.Credentials.Address.ToString(); // Show warning string warning = this.controller.GetConnectionsProblemWarning(result.FailedException); address_error_label.Markup = "<span foreground=\"red\">" + warning + "</span>"; address_error_label.Show(); } // Hide wait cursor this.GdkWindow.Cursor = defaultCursor; if (this.controller.repositories != null) { // Continue to folder selection this.controller.Add1PageCompleted( new Uri(address_entry.Text), result.Credentials.Binding, user_entry.Text, password_entry.Text); } }; this.controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) { Application.Invoke(delegate { continue_button.Sensitive = button_enabled; if (button_enabled) { continue_button.SetFlag(Gtk.WidgetFlags.CanFocus); continue_button.SetFlag(Gtk.WidgetFlags.CanDefault); continue_button.GrabDefault(); } }); }; this.AddButton(cancel_button); this.AddButton(continue_button); this.controller.CheckAddPage(address_entry.Text); address_entry.GrabFocus(); }
public void GetRepositories( string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId, string binding) { ServerCredentials credentials = new ServerCredentials() { Address = new Uri(url), Binding = binding, UserName = user, Password = password }; var repos = credentials.GetRepositories(); Assert.That(repos, Is.Not.Null.Or.Empty); foreach (var repo in repos) { Assert.That(string.IsNullOrEmpty(repo.Id), Is.False); Assert.That(string.IsNullOrEmpty(repo.Name), Is.False); Console.WriteLine(repo.ToString()); } }
partial void OnContinue(MonoMac.Foundation.NSObject sender) { ServerCredentials credentials = new ServerCredentials() { UserName = UserText.StringValue, Password = PasswordText.StringValue, Address = new Uri(AddressText.StringValue), Binding = (this.Controller.saved_binding == null) ? ServerCredentials.BindingBrowser : this.Controller.saved_binding }; WarnText.StringValue = string.Empty; AddressText.Enabled = false; UserText.Enabled = false; PasswordText.Enabled = false; ContinueButton.Enabled = false; CancelButton.Enabled = false; // monomac bug: animation GUI effect will cause GUI to hang, when backend thread is busy // LoginProgress.StartAnimation(this); Thread check = new Thread(() => { var result = SetupController.GetRepositories(credentials); if (result.Repositories != null) { this.Controller.repositories = result.Repositories.WithoutHiddenOnce(); } else { this.Controller.repositories = null; } InvokeOnMainThread(delegate { if (this.Controller.repositories == null) { AddressText.StringValue = result.Credentials.Address.ToString(); WarnText.StringValue = this.Controller.GetConnectionsProblemWarning(result.FailedException); AddressText.Enabled = true; UserText.Enabled = true; PasswordText.Enabled = true; ContinueButton.Enabled = true; CancelButton.Enabled = true; } else { RemoveEvent(); Controller.Add1PageCompleted(result.Credentials.Address, result.Credentials.Binding, credentials.UserName, credentials.Password.ToString()); } LoginProgress.StopAnimation(this); }); }); check.Start(); }
private void LoadAddLoginWPF() { // define UI elements. Header = Properties_Resources.Where; System.Uri resourceLocater = new System.Uri("/DataSpaceSync;component/SetupAddLoginWPF.xaml", System.UriKind.Relative); UserControl LoadAddLoginWPF = Application.LoadComponent(resourceLocater) as UserControl; address_label = LoadAddLoginWPF.FindName("address_label") as TextBlock; address_box = LoadAddLoginWPF.FindName("address_box") as TextBox; address_help_label = LoadAddLoginWPF.FindName("address_help_label") as TextBlock; user_label = LoadAddLoginWPF.FindName("user_label") as TextBlock; user_box = LoadAddLoginWPF.FindName("user_box") as TextBox; user_help_label = LoadAddLoginWPF.FindName("user_help_label") as TextBlock; password_label = LoadAddLoginWPF.FindName("password_label") as TextBlock; password_box = LoadAddLoginWPF.FindName("password_box") as PasswordBox; password_progress = LoadAddLoginWPF.FindName("password_progress") as CircularProgressBar; password_help_label = LoadAddLoginWPF.FindName("password_help_label") as TextBlock; address_error_label = LoadAddLoginWPF.FindName("address_error_label") as TextBox; continue_button = LoadAddLoginWPF.FindName("continue_button") as Button; cancel_button = LoadAddLoginWPF.FindName("cancel_button") as Button; ContentCanvas.Children.Add(LoadAddLoginWPF); address_box.Text = (Controller.PreviousAddress != null) ? Controller.PreviousAddress.ToString() : String.Empty; if (Controller.saved_user == String.Empty || Controller.saved_user == null) { user_box.Text = DefaultEntries.Defaults.Name; } else { user_box.Text = Controller.saved_user; } TaskbarItemInfo.ProgressValue = 0.0; TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None; if (!DefaultEntries.Defaults.CanModifyUrl) { address_box.IsEnabled = false; address_box.Visibility = Visibility.Hidden; address_help_label.Visibility = Visibility.Hidden; address_label.Visibility = Visibility.Hidden; } if (Controller.PreviousAddress == null || Controller.PreviousAddress.ToString() == String.Empty) { address_box.Text = DefaultEntries.Defaults.Url; } else { address_box.Text = Controller.PreviousAddress.ToString(); } address_box.Focus(); address_box.Select(address_box.Text.Length, 0); // Actions. ControllerLoginInsertAction(); Controller.CheckAddPage(address_box.Text); address_box.TextChanged += delegate { string error = Controller.CheckAddPage(address_box.Text); if (!String.IsNullOrEmpty(error)) { address_error_label.Text = Properties_Resources.ResourceManager.GetString(error, CultureInfo.CurrentCulture); address_error_label.Visibility = Visibility.Visible; } else { address_error_label.Visibility = Visibility.Hidden; } }; cancel_button.Click += delegate { ControllerLoginRemoveAction(); Controller.PageCancelled(); }; string binding = Controller.saved_binding; if (binding == null) { binding = CmisRepoCredentials.BindingBrowser; } continue_button.Click += delegate { // Show wait cursor password_progress.Visibility = Visibility.Visible; System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; // Try to find the CMIS server (asynchronously) GetRepositoriesDelegate dlgt = new GetRepositoriesDelegate(SetupController.GetRepositories); ServerCredentials credentials = new ServerCredentials() { UserName = user_box.Text, Password = password_box.Password, Address = new Uri(address_box.Text), Binding = binding, }; IAsyncResult ar = dlgt.BeginInvoke(credentials, null, null); while (!ar.AsyncWaitHandle.WaitOne(100)) { System.Windows.Forms.Application.DoEvents(); } var result = dlgt.EndInvoke(ar); Controller.repositories = result.Repositories.WithoutHiddenOnce(); address_box.Text = result.Credentials.Address.ToString(); binding = result.Credentials.Binding; // Hide wait cursor System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; password_progress.Visibility = Visibility.Hidden; if (Controller.repositories == null) { // Could not retrieve repositories list from server, show warning. string warning = Controller.GetConnectionsProblemWarning(result.FailedException); address_error_label.Text = warning; address_error_label.Visibility = Visibility.Visible; } else { ControllerLoginRemoveAction(); // Continue to next step, which is choosing a particular folder. Controller.Add1PageCompleted( new Uri(address_box.Text), binding, user_box.Text, password_box.Password); } }; }
public void TestClientBrand( string canonical_name, string localPath, string remoteFolderPath, string url, string user, string password, string repositoryId, string binding) { ServerCredentials credentials = new ServerCredentials() { Address = new Uri(url), Binding = binding, UserName = user, Password = password }; var underTest = new ClientBrand(credentials, repositoryId, remoteFolderPath); Assert.That(underTest.SetupServer(credentials), Is.True); foreach (string path in underTest.PathList) { DateTime date; Assert.That(underTest.GetFileDateTime(path, out date), Is.True); using (var stream = new MemoryStream()) { Assert.That(underTest.GetFile(path, stream), Is.True); Assert.That(stream.Length, Is.GreaterThan(0)); } } }
/// <summary> /// Setup the CMIS server to support Client Brand /// </summary> /// <param name="credentials"></param> /// <returns>Whether the CMIS server is setup</returns> public bool SetupServer(ServerCredentials credentials) { if (!this.TestServer(credentials)) { return false; } IRepository repo = this.GetRepo(credentials); if (repo == null) { return false; } try { this.session = repo.CreateSession(); return true; } catch (Exception e) { Logger.Debug(e.Message); return false; } }
public void DefaultConstructor() { var cred = new ServerCredentials(); Assert.IsNull(cred.Address); Assert.IsNull(cred.UserName); Assert.IsNull(cred.Password); }
partial void OnPasswordChanged(NSObject sender) { this.LoginStatusLabel.StringValue = "logging in..."; this.LoginStatusLabel.Hidden = false; // monomac bug: animation GUI effect will cause GUI to hang, when backend thread is busy // this.LoginStatusProgress.StartAnimation(this); ServerCredentials cred = new ServerCredentials() { Address = Credentials.Address, Binding = Credentials.Binding, UserName = Credentials.UserName, Password = PasswordText.StringValue }; PasswordText.Enabled = false; new TaskFactory().StartNew(() => { try{ cred.GetRepositories(); InvokeOnMainThread(()=> { lock(loginLock) { if(!isClosed) this.LoginStatusLabel.StringValue = "login successful"; } }); }catch(Exception e) { InvokeOnMainThread(() => { lock (loginLock) { if(!isClosed) this.LoginStatusLabel.StringValue = "login failed: " + e.Message; } }); } InvokeOnMainThread(() => { lock (loginLock) { PasswordText.Enabled = true; if(!isClosed) this.LoginStatusProgress.StopAnimation(this); } }); }); }
public ClientBrand(ServerCredentials credentials, string repositoryId, string remoteFolderPath) { Dictionary<string, string> parameters = CmisUtils.GetCmisParameters(credentials); ISessionFactory factory = SessionFactory.NewInstance(); IList<IRepository> repos = factory.GetRepositories(parameters); foreach (IRepository repo in repos) { if (repo.Id == repositoryId) { this.repository = repo; this.repoName = repo.Name; } } if (this.repository == null) { throw new ArgumentException("No such repository for " + repositoryId); } this.session = this.repository.CreateSession(); this.folder = this.session.GetObjectByPath(remoteFolderPath) as IFolder; if (this.folder == null) { throw new ArgumentException("No such folder for " + remoteFolderPath); } foreach (string name in this.nameList) { this.pathList.Add((remoteFolderPath + "/" + name).Replace("//", "/")); } this.DeleteFiles(); this.CreateFiles(); }