Esempio n. 1
0
        public static UserCredentials PromptForCredentials(string url, bool forceDisplay = false)
        {
            UserCredentials   result = null;
            CredentialsDialog dialog = new CredentialsDialog("Kato - Jenkins Authentication : \r\n" + url)
            {
                AlwaysDisplay = forceDisplay, SaveDisplayed = false
            };

            if (dialog.Show(saveChecked: true) == DialogResult.OK && (!string.IsNullOrWhiteSpace(dialog.Password) && !string.IsNullOrWhiteSpace(dialog.Name)))
            {
                var creds = new UserCredentials {
                    UserName = dialog.Name, Password = dialog.Password
                };

                if (!TryToAuthenticate(url, creds))
                {
                    return(null);
                }

                if (dialog.SaveChecked)
                {
                    dialog.Confirm(true);
                }

                result = creds;
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Ask for PSCredential from user
        /// </summary>
        /// <param name="caption">The caption for the message window.</param>
        /// <param name="message">The text of the message.</param>
        /// <param name="userName">The user name whose credential is to be prompted for. If this parameter set to null or an empty string, the function will prompt for the user name first.</param>
        /// <param name="targetName">The name of the target for which the credential is collected.</param>
        /// <param name="allowedCredentialTypes">A bitwise combination of the PSCredentialTypes enumeration values that identify the types of credentials that can be returned.</param>
        /// <param name="options">A bitwise combination of the PSCredentialUIOptions enumeration values that identify the UI behavior when it gathers the credentials.</param>
        /// <returns>A PSCredential object that contains the credentials for the target.</returns>
        public PSCredential GetPSCredential(string caption, string message, string userName,
                                            string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options)
        {
            PSCredential result = null;

            CredentialsDialog dialog = new CredentialsDialog(targetName, caption, message);

            dialog.Name = userName;

            switch (options)
            {
            case PSCredentialUIOptions.AlwaysPrompt:
                dialog.AlwaysDisplay = true;
                break;

            case PSCredentialUIOptions.ReadOnlyUserName:
                dialog.KeepName = true;
                break;

            case PSCredentialUIOptions.Default:
            case PSCredentialUIOptions.None:
                break;

            default:
                break;
            }

            if (dialog.Show() == DialogResult.OK)
            {
                result = new PSCredential(dialog.Name, dialog.Password);
            }

            return(result);
        }
Esempio n. 3
0
        private UserCredentials PromptForCredentials(string url)
        {
            UserCredentials   result = null;
            CredentialsDialog dialog = new CredentialsDialog("Kato - Jenkins Authentication : \r\n" + url);

            if (dialog.Show() == DialogResult.OK && (!String.IsNullOrWhiteSpace(dialog.Password) && !String.IsNullOrWhiteSpace(dialog.Name)))
            {
                var creds = new UserCredentials {
                    UserName = dialog.Name, Password = dialog.Password
                };

                if (!TryToAuthenticate(url, creds))
                {
                    return(null);
                }

                if (dialog.SaveChecked)
                {
                    dialog.Confirm(true);
                }
                result = creds;
            }

            return(result);
        }
Esempio n. 4
0
        private CredentialsDialog ShowDialog(
            string target,
            string username,
            string message,
            bool isNameReadonly)
        {
            CredentialsDialog dialog = new CredentialsDialog(target, "GitMind", message);

            dialog.SaveChecked = true;

            dialog.Name     = username;
            dialog.KeepName = isNameReadonly;

            // The credential dialog is only shown if there are no cached value for that user
            // The dialog contains a "save" check box, which when checked and credentials have been saved
            // will cache the credentials and thus skip showing the dialog the next time.
            // credentialDialog.AlwaysDisplay = true;
            if (dialog.Show(owner.Win32Window) == DialogResult.OK)
            {
                return(dialog);
            }

            Log.Debug($"User canceled {target}, {username}, {message}");
            return(null);
        }
Esempio n. 5
0
        /// <summary>
        ///     Use the credentials dialog, this will show if there are not correct credentials.
        ///     If there are credentials, call the real login.
        /// </summary>
        /// <returns>Task</returns>
        public async Task LoginAsync(CancellationToken cancellationToken = default)
        {
            await LogoutAsync(cancellationToken);

            try
            {
                // Get the system name, so the user knows where to login to
                var credentialsDialog = new CredentialsDialog(_jiraConfiguration.Url)
                {
                    Name = null
                };
                while (credentialsDialog.Show(null, credentialsDialog.Name) == DialogResult.OK)
                {
                    if (await DoLoginAsync(credentialsDialog.Name, credentialsDialog.Password, cancellationToken))
                    {
                        if (credentialsDialog.SaveChecked)
                        {
                            credentialsDialog.Confirm(true);
                        }
                        IsLoggedIn    = true;
                        _loggedInTime = DateTime.Now;
                        return;
                    }
                    // Login failed, confirm this
                    try
                    {
                        credentialsDialog.Confirm(false);
                    }
                    catch (ApplicationException e)
                    {
                        // exception handling ...
                        Log.Error().WriteLine(e, "Problem using the credentials dialog");
                    }
                    // For every windows version after XP show an incorrect password baloon
                    credentialsDialog.IncorrectPassword = true;
                    // Make sure the dialog is display, the password was false!
                    credentialsDialog.AlwaysDisplay = true;
                }
            }
            catch (ApplicationException e)
            {
                // exception handling ...
                Log.Error().WriteLine(e, "Problem using the credentials dialog");
            }
        }
Esempio n. 6
0
 public void Login()
 {
     Logout();
     try
     {
         // Get the system name, so the user knows where to login to
         var systemName = _url.Replace(DEFAULT_POSTFIX1, "");
         systemName = systemName.Replace(DEFAULT_POSTFIX2, "");
         var dialog = new CredentialsDialog(systemName)
         {
             Name = null
         };
         while (dialog.Show(null, dialog.Name) == DialogResult.OK)
         {
             if (DoLogin(dialog.Name, dialog.Password))
             {
                 if (dialog.SaveChecked)
                 {
                     dialog.Confirm(true);
                 }
                 return;
             }
             try
             {
                 dialog.Confirm(false);
             }
             catch (ApplicationException e)
             {
                 // exception handling ...
                 Log.Error().WriteLine(e, "Problem using the credentials dialog");
             }
             // For every windows version after XP show an incorrect password baloon
             dialog.IncorrectPassword = true;
             // Make sure the dialog is display, the password was false!
             dialog.AlwaysDisplay = true;
         }
     }
     catch (ApplicationException e)
     {
         // exception handling ...
         Log.Error().WriteLine(e, "Problem using the credentials dialog");
     }
 }
 public void login()
 {
     logout();
     try {
         // Get the system name, so the user knows where to login to
         string systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX1, "");
         systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX2, "");
         CredentialsDialog dialog = new CredentialsDialog(systemName);
         dialog.Name = null;
         while (dialog.Show(dialog.Name) == DialogResult.OK)
         {
             if (doLogin(dialog.Name, dialog.Password))
             {
                 if (dialog.SaveChecked)
                 {
                     dialog.Confirm(true);
                 }
                 return;
             }
             else
             {
                 try {
                     dialog.Confirm(false);
                 } catch (ApplicationException e) {
                     // exception handling ...
                     LOG.Error("Problem using the credentials dialog", e);
                 }
                 // For every windows version after XP show an incorrect password baloon
                 dialog.IncorrectPassword = true;
                 // Make sure the dialog is display, the password was false!
                 dialog.AlwaysDisplay = true;
             }
         }
     } catch (ApplicationException e) {
         // exception handling ...
         LOG.Error("Problem using the credentials dialog", e);
     }
 }
        /// <summary>
        /// Prompt the user for Proxy Credentials.
        /// </summary>
        /// <param name="message">The message to display to the user, usually containing the proxy realm.</param>
        /// <returns>A new NetworkCredential object with the values the user entered, or null if cancelled.</returns>
        private NetworkCredential GetProxyCredentials(string message)
        {
            if (WebRequest.DefaultWebProxy is WebProxy) // custom
            {
                proxyCredDialog.Target  = ((WebProxy)WebRequest.DefaultWebProxy).Address.AbsoluteUri;
                proxyCredDialog.Caption = String.Format(Language.NetManager_ConnectTo, ((WebProxy)WebRequest.DefaultWebProxy).Address.Host);
            }
            else
            {
                proxyCredDialog.Target  = "ieproxy";
                proxyCredDialog.Caption = Language.NetManager_ConnectToProxy;
            }
            proxyCredDialog.Message = message;

            if (proxyCredDialog.Show() == DialogResult.OK)
            {
                return(proxyCredDialog.NetworkCredentials);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 9
0
        // References:
        // http://msdn.microsoft.com/en-us/library/aa480470.aspx

        /// <summary>
        /// Accepts a user credentials if they haven't been saved or if they have changed, adds them to the credential cache, and makes
        /// a call to EWS to verify that the credentials work. If the credentials work, then a confirmation is sent to the credential
        /// manager and the credentials are provided back to the application to be used to make EWS calls.
        /// </summary>
        internal static bool AppLogin(IWin32Window owner, IUserData data, ref ExchangeService service)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(data.UserName) ||
                    string.IsNullOrWhiteSpace(data.Password))
                {
                    // Create the credential prompt that will handle the user credentials.
                    //CredPrompt prompt = new CredPrompt(@"Exchange Web Services (EWS)");
                    CredentialsDialog dlg = new CredentialsDialog(
                        @"Exchange Web Services (EWS)", "EWS credentials", "Enter your credentials");

                    // Show the prompt. This will either prompt for the user credentials or, if they
                    // already exist on the system, it will load credentials from the cache in the CredDialog object.
                    //DialogResult result = prompt.ShowPrompt();
                    DialogResult result = dlg.Show(owner, true);

                    if (result == DialogResult.OK)
                    {
                        // Authenticate the credentials and if they work, confirm the credentials and provide the
                        // ExchangeService object back to the application.
                        string[] parts = dlg.Name.Split('\\');
                        switch (parts.Length)
                        {
                        case 1:
                            data.UserName = parts[0];
                            break;

                        default:
                            data.Domain   = parts[0];
                            data.UserName = parts[1];
                            break;
                        }
                        data.Password = dlg.Password;

                        if (Authenticate(data, ref service))
                        {
                            // The credentials were authenticated. Confirm that we want the
                            // credential manager to save our credentials.
                            if (dlg.SaveChecked)
                            {
                                dlg.Confirm(true);
                            }
                            return(true);
                        }
                        // The credentials were not authenticated.
                        try
                        {
                            dlg.Confirm(false);
                            return(false);
                        }
                        catch (ApplicationException)
                        {
                            // Prompt user for credentials again. We may need to provide a way to break
                            while (true)
                            {
                                DialogResult res = MessageBox.Show(
                                    LocalizibleStrings.RetryConnection,
                                    Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                                return(res == DialogResult.Yes && AppLogin(owner, data, ref service));
                            }
                        }
                    }

                    if (result != DialogResult.Cancel)
                    {
                        throw new ApplicationException(LocalizibleStrings.UnhandledCondition + result);
                    }
                }
                else
                {
                    return(Authenticate(data, ref service));
                }
            }
            // This will capture errors stemming from CredUICmdLinePromptForCredentials.
            catch (ApplicationException exc)
            {
                Logger.Error(@"AppLogin", exc);
            }

            return(false);
        }