示例#1
0
        public string getAuthenticationTicket(bool promptUser)
        {
            string strAuthTicket = "";
             if (m_AuthenticationTicket == "")
             {
            // If we've been given a CIFS server then try to authenticate against it
            if (this.CIFSServer.Length > 0)
            {
               // Try CIFS
               IServerHelper myAuthTicket = new CIFSHelper(this.CIFSServer);
               m_AuthenticationTicket = myAuthTicket.GetAuthenticationTicket();
            }

            // Did we get a ticket from the CIFS server?
            if (m_AuthenticationTicket != "")
            {
               m_DefaultToCIFS = true;
            }
            else
            {
               // Try WebDAV
               /* Only reset flag if no CIFS config present */
               m_DefaultToCIFS = (this.CIFSServer.Length > 0);
               IServerHelper myAuthTicket = new WebDAVHelper(this.WebDAVURL);
               strAuthTicket = myAuthTicket.GetAuthenticationTicket();
               if (strAuthTicket != "401")
               {
                  m_AuthenticationTicket = strAuthTicket;
               }
               else
               {
                  // Authentication failed - do we have a saved username/password?
                  if ((this.Username.Length > 0) && (this.Password.Length > 0))
                  {
                     strAuthTicket = myAuthTicket.GetAuthenticationTicket(this.Username, this.Password);
                  }
                  // Check whether 'Negotiate' authentication is required and try to log-in with the Default System Credentials (to cover SSO case)
                  else if (EAuthenticationType.NEGOTIATE == myAuthTicket.GetAuthenticationType())
                  {
                      strAuthTicket = myAuthTicket.GetAuthenticationTicket("negotiator", this.Password);
                  }
                  if (strAuthTicket != "401")
                  {
                     m_AuthenticationTicket = strAuthTicket;
                  }
                  else if (promptUser)
                  {
                     // Last option - pop up the login form
                     using (Login myLogin = new Login())
                     {
                        bool bRetry = true;

                        // Pre-populate with values already configured
                        myLogin.Username = this.Username;
                        myLogin.Password = this.Password;

                        // Retry loop for typos
                        while (bRetry)
                        {
                           if (myLogin.ShowDialog() == DialogResult.OK)
                           {
                              // Try to authenticate with entered credentials
                              strAuthTicket = myAuthTicket.GetAuthenticationTicket(myLogin.Username, myLogin.Password);
                              if ((strAuthTicket == "401") || (strAuthTicket == ""))
                              {
                                 // Retry?
                                 bRetry = (MessageBox.Show(Properties.Resources.UnableToAuthenticate, Properties.Resources.MessageBoxTitle, MessageBoxButtons.RetryCancel) == DialogResult.Retry);
                              }
                              else
                              {
                                 // Successful login
                                 m_AuthenticationTicket = strAuthTicket;
                                 bRetry = false;
                              }
                           }
                           else
                           {
                              // Cancel or close chosen on login dialog
                              bRetry = false;
                           }
                        }
                     }
                  }
               }
            }
             }

             return m_AuthenticationTicket;
        }
示例#2
0
        public string getAuthenticationTicket(bool promptUser)
        {
            string strAuthTicket = "";

            if (m_AuthenticationTicket == "")
            {
                // If we've been given a CIFS server then try to authenticate against it
                if (this.CIFSServer.Length > 0)
                {
                    // Try CIFS
                    IServerHelper myAuthTicket = new CIFSHelper(this.CIFSServer);
                    m_AuthenticationTicket = myAuthTicket.GetAuthenticationTicket();
                }

                // Did we get a ticket from the CIFS server?
                if (m_AuthenticationTicket != "")
                {
                    m_DefaultToCIFS = true;
                }
                else
                {
                    // Try WebDAV
                    /* Only reset flag if no CIFS config present */
                    m_DefaultToCIFS = (this.CIFSServer.Length > 0);
                    IServerHelper myAuthTicket = new WebDAVHelper(this.WebDAVURL);
                    strAuthTicket = myAuthTicket.GetAuthenticationTicket();
                    if (strAuthTicket != "401")
                    {
                        m_AuthenticationTicket = strAuthTicket;
                    }
                    else
                    {
                        // Authentication failed - do we have a saved username/password?
                        if ((this.Username.Length > 0) && (this.Password.Length > 0))
                        {
                            strAuthTicket = myAuthTicket.GetAuthenticationTicket(this.Username, this.Password);
                        }
                        if (strAuthTicket != "401")
                        {
                            m_AuthenticationTicket = strAuthTicket;
                        }
                        else if (promptUser)
                        {
                            // Last option - pop up the login form
                            using (Login myLogin = new Login())
                            {
                                bool bRetry = true;

                                // Pre-populate with values already configured
                                myLogin.Username = this.Username;
                                myLogin.Password = this.Password;

                                // Retry loop for typos
                                while (bRetry)
                                {
                                    if (myLogin.ShowDialog() == DialogResult.OK)
                                    {
                                        // Try to authenticate with entered credentials
                                        strAuthTicket = myAuthTicket.GetAuthenticationTicket(myLogin.Username, myLogin.Password);
                                        if ((strAuthTicket == "401") || (strAuthTicket == ""))
                                        {
                                            // Retry?
                                            bRetry = (MessageBox.Show(Properties.Resources.UnableToAuthenticate, Properties.Resources.MessageBoxTitle, MessageBoxButtons.RetryCancel) == DialogResult.Retry);
                                        }
                                        else
                                        {
                                            // Successful login
                                            m_AuthenticationTicket = strAuthTicket;
                                            bRetry = false;
                                        }
                                    }
                                    else
                                    {
                                        // Cancel or close chosen on login dialog
                                        bRetry = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(m_AuthenticationTicket);
        }