コード例 #1
0
        private void btnRecoverySubmit_Click(object sender, EventArgs e)
        {
            this.PanelResult.Visible = false;
            this.labelResult.Text    = string.Empty;

            this.InitializeControls();

            _Default     defaultPage = (_Default)this.Page;
            PasswordInfo data        = null;

            // read configuration if PasswordHistory is visible
            bool isPasswordHistoryVisible = false;

            if (ConfigurationManager.AppSettings["AdmPwd.IsPasswordHistoryVisible"] != null && ConfigurationManager.AppSettings["AdmPwd.IsPasswordHistoryVisible"] != string.Empty)
            {
                if (!bool.TryParse(ConfigurationManager.AppSettings["AdmPwd.IsPasswordHistoryVisible"].ToString(), out isPasswordHistoryVisible))
                {
                    isPasswordHistoryVisible = false;
                }
            }

            var current = System.Security.Principal.WindowsIdentity.GetCurrent();

            using (WindowsImpersonationContext wic = ((WindowsIdentity)Page.User.Identity).Impersonate())
            {
                try
                {
                    data = PDSUtils.PdsWrapper.GetLocalAdminPassword(this.cboForestNames.Text, this.textComputerName.Text, isPasswordHistoryVisible, false); //or false if we don't need password history
                }
                catch (AutodiscoverException ex)
                {
                    this.labelResult.Text     = Messages.Errors_ServiceNotAvailable + " - " + ex.Message;
                    this.PanelResult.CssClass = "errorMessage";
                    this.PanelResult.Visible  = true;
                    return;
                }
                catch (PDSException ex)
                {
                    switch (ex.IssueCode)
                    {
                    case IssueType.ComputerNotFound:
                        this.labelResult.Text = Messages.Errors_ADNoComputerFoundException + " " + ex.Message;
                        break;

                    case IssueType.ComputerAmbiguous:
                        this.labelResult.Text = Messages.Errors_MultipleComputerObjectsFound + ": " + ex.Message;
                        break;

                    case IssueType.AccessDenied:
                        this.labelResult.Text = Messages.Errors_NoReadPasswordForUserOnComputerObject + ": " + ex.Message;
                        break;

                    case IssueType.CannotRetrievePassword:
                        this.labelResult.Text = Messages.Errors_CannotRetrievePassword + ": " + ex.Message;
                        break;

                    default:
                        this.labelResult.Text = Messages.Errors_CannotRetrievePassword + ": " + ex.Message;
                        break;
                    }
                    this.PanelResult.CssClass = "errorMessage";
                    this.PanelResult.Visible  = true;
                    return;
                }
                catch (Exception ex)
                {
                    labelResult.Text    = Messages.Errors_CannotRetrievePassword + " - " + ex.Message;
                    PanelResult.Visible = true;
                    return;
                }
            }
            current = System.Security.Principal.WindowsIdentity.GetCurrent();

            if (!String.IsNullOrEmpty(data.Password))
            {
                this.btnRecoverySubmit.Visible = false;
                textComputerName.Enabled       = false;

                this.PanelAdminPasswordData.Visible   = true;
                this.textAdminPassword.Text           = data.Password;
                this.textAdminPasswordExpiration.Text = data.ExpirationTimestamp > DateTime.MinValue ? data.ExpirationTimestamp.ToString() : string.Empty;
                this.textAdminPasswordComputerDN.Text = data.DistinguishedName;

                if (isPasswordHistoryVisible)
                {
                    if (data.PasswordHistory.Count > 0)
                    {
                        PanelPasswordHistory.Visible   = true;
                        tblPasswordHistoryList.Visible = true;
                        foreach (PasswordHistory pi in data.PasswordHistory)
                        {
                            TableRow rw = new TableRow();
                            rw.Cells.Add(new TableCell()
                            {
                                Text = pi.Password
                            });
                            rw.Cells.Add(new TableCell()
                            {
                                Text = pi.ValidSince.ToString()
                            });
                            rw.Cells.Add(new TableCell()
                            {
                                Text = pi.ValidUntil.ToString()
                            });
                            tblPasswordHistoryList.Rows.Add(rw);
                        }
                    }
                    else
                    {
                        PanelPasswordHistory.Visible = false;
                    }
                }

                defaultPage.ShowBackToNewRequestButton();

                this.textUpdateExpirationDateNewValue.Text = DateTime.Now.ToString();
                PanelExpirationDateChange.Visible          = true;
            }
        }
コード例 #2
0
        protected void btnUpdateExpirationDate_Click(object sender, EventArgs e)
        {
            this.PanelPasswordHistory.Visible = false;

            _Default defaultPage = (_Default)this.Page;
            DateTime newExpirationDate;

            if (!DateTime.TryParse(textUpdateExpirationDateNewValue.Text, out newExpirationDate))
            {
                this.PanelResult.Visible  = true;
                this.labelResult.Text     = Messages.RC_NotValidExpirationDate;
                this.PanelResult.CssClass = "errorMessage";
            }
            else
            {
                PasswordResetStatus rslt = null;
                var current = System.Security.Principal.WindowsIdentity.GetCurrent();
                using (WindowsImpersonationContext wic = ((WindowsIdentity)Page.User.Identity).Impersonate())
                {
                    try
                    {
                        rslt = PDSUtils.PdsWrapper.ResetLocalAdminPassword(this.cboForestNames.Text, this.textComputerName.Text, newExpirationDate.ToUniversalTime());
                    }
                    catch (AdmPwd.Types.PDSException ex)
                    {
                        switch (ex.IssueCode)
                        {
                        case IssueType.ComputerNotFound:
                            this.labelResult.Text     = Messages.Errors_ADNoComputerFoundException + " " + ex.Message;
                            this.PanelResult.CssClass = "errorMessage";
                            break;

                        case IssueType.ComputerAmbiguous:
                            this.labelResult.Text = Messages.Errors_MultipleComputerObjectsFound + ": " + ex.Message;
                            break;

                        case IssueType.AccessDenied:
                            this.labelResult.Text = Messages.Errors_NoResetPasswordForUserOnComputerObject + ": " + ex.Message;
                            break;

                        case IssueType.CannotResetPassword:
                            this.labelResult.Text = Messages.Errors_CannotResetPassword + ": " + ex.Message;
                            break;

                        default:
                            this.labelResult.Text = Messages.Errors_CannotResetPassword + ": " + ex.Message;
                            break;
                        }
                        this.PanelResult.CssClass = "errorMessage";
                        this.PanelResult.Visible  = true;
                        defaultPage.ShowBackToNewRequestButton();
                        return;
                    }
                    catch (Exception ex)
                    {
                        labelResult.Text          = Messages.Errors_ServiceNotAvailable + " - " + ex.Message;
                        this.PanelResult.CssClass = "errorMessage";
                        PanelResult.Visible       = true;
                        defaultPage.ShowBackToNewRequestButton();
                        return;
                    }
                }
                current = System.Security.Principal.WindowsIdentity.GetCurrent();

                PanelExpirationDateChange.Visible = false;
                textAdminPasswordExpiration.Text  = newExpirationDate.ToString();

                this.PanelPasswordHistory.Visible = false;
                this.PanelResult.Visible          = true;
                this.labelResult.Text             = Messages.RC_ExpirationDateUpdated;
                this.PanelResult.CssClass         = "okMessage";

                defaultPage.ShowBackToNewRequestButton();
            }
        }