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.GetPassword(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 (System.ServiceModel.FaultException<ServiceFault> faex)
{
switch (faex.Detail.IssueCode)
{
case IssueType.ComputerNotFound:
this.labelResult.Text = Messages.Errors_ADNoComputerFoundException + " " + faex.Message;
break;
case IssueType.ComputerAmbiguous:
this.labelResult.Text = Messages.Errors_MultipleComputerObjectsFound + ": " + faex.Message;
break;
case IssueType.AccessDenied:
this.labelResult.Text = Messages.Errors_NoReadPasswordForUserOnComputerObject + ": " + faex.Message;
break;
case IssueType.CannotRetrievePassword:
this.labelResult.Text = Messages.Errors_CannotRetrievePassword + ": " + faex.Message;
break;
default:
this.labelResult.Text = Messages.Errors_CannotRetrievePassword + ": " + faex.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;
}
}