private void InitializeRootApplications() { RootNode.Children.Clear(); bizilante.SSO.Helper.SSO sSO = new bizilante.SSO.Helper.SSO(); string[] applications = sSO.GetApplications(); for (int i = 0; i < applications.Length; i++) { ApplicationScopeNode applicationScopeNode = new ApplicationScopeNode(applications[i]); applicationScopeNode.ApplicationImported += new EventHandler(this.rootNode_ApplicationImported); base.RootNode.Children.Add(applicationScopeNode); } }
public ActionsSnapIn() { //System.Diagnostics.Debugger.Launch(); ApplicationScopeNode applicationScopeNode = new ApplicationScopeNode(true); applicationScopeNode.ApplicationImported += new EventHandler(rootNode_ApplicationImported); RootNode = applicationScopeNode; if (HasSecurityRights) { InitializeRootApplications(); } SmallImages.Add(Resources.authority_16); SmallImages.Add(Resources.add_scope); }
public static DialogResult OpenSSOImportFile(out string applicationFileName, out string encryptedText, ApplicationScopeNode callingNode) { DialogResult dialogResult = DialogResult.None; applicationFileName = string.Empty; encryptedText = string.Empty; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.CheckFileExists = true; openFileDialog.CheckPathExists = true; openFileDialog.DefaultExt = "*.sso"; openFileDialog.Filter = "SSO Extract files (*.sso)|*.sso|All files (*.*)|*.*"; openFileDialog.Title = "Import SSO Application"; dialogResult = callingNode.SnapIn.Console.ShowDialog(openFileDialog); if (dialogResult == DialogResult.Cancel) { return(dialogResult); } applicationFileName = Path.GetFileNameWithoutExtension(openFileDialog.FileName); StreamReader streamReader = new StreamReader(openFileDialog.OpenFile()); try { encryptedText = streamReader.ReadToEnd(); } catch (Exception ex) { EventLog.WriteEntry("SSO MMC SnapIn - ImportSSOApplication \r\n", ex.ToString()); throw; } finally { streamReader.Dispose(); } } return(dialogResult); }
public static bool ExportSSOApplication(string appName, string encryptionKey, ApplicationScopeNode currentNode) { bizilante.SSO.Helper.SSO sSO = new bizilante.SSO.Helper.SSO(); string[] keys = sSO.GetKeys(appName); string[] values = sSO.GetValues(appName); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><SSOApplicationExport><applicationData>"); for (int i = 0; i < keys.Length; i++) { if (keys[i] != null && !(keys[i] == "")) { stringBuilder.Append(string.Concat(new string[] { "<add key=\"", keys[i], "\" value=\"", HttpUtility.HtmlEncode(values[i]), "\" />" })); } } stringBuilder.Append("</applicationData></SSOApplicationExport>"); bool result; using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.CheckPathExists = true; saveFileDialog.Filter = "SSO Extract files (*.sso)|*.sso|All files (*.*)|*.*"; saveFileDialog.DefaultExt = "*.sso"; saveFileDialog.FileName = appName + ".sso"; saveFileDialog.Title = "Export SSO Application"; DialogResult dialogResult = currentNode.SnapIn.Console.ShowDialog(saveFileDialog); if (dialogResult != DialogResult.Cancel) { StreamWriter streamWriter = new StreamWriter(saveFileDialog.FileName, false); try { streamWriter.Write(bizilante.SSO.Helper.SSO.Encrypt(stringBuilder.ToString(), encryptionKey)); streamWriter.Flush(); } catch (Exception ex) { EventLog.WriteEntry("SSO MMC SnapIn - ExportSSOApplication \r\n", ex.ToString()); result = false; return(result); } finally { streamWriter.Close(); streamWriter.Dispose(); } } result = true; } return(result); }
protected override void OnAction(Microsoft.ManagementConsole.Action action, AsyncStatus status) { string a; if ((a = (string)action.Tag) != null) { if (a == "Delete") { ScopeNode scopeNode = new ScopeNode(); scopeNode.DisplayName = base.DisplayName; bizilante.SSO.Helper.SSO sSO = new bizilante.SSO.Helper.SSO(); sSO.GetApplications(); int index = 0; for (int i = 0; i < base.Parent.Children.Count; i++) { if (Parent.Children[i].DisplayName.ToUpper() == DisplayName.ToUpper()) { index = i; } } sSO.DeleteApplication(base.DisplayName); Parent.Children.RemoveAt(index); return; } if (a == "Add_KeyValue") { if (DisplayName.ToUpper() == "_NewApplication".ToUpper()) { EnabledStandardVerbs = StandardVerbs.None; } _hasKeyValuePropertyPage = true; ShowPropertySheet("Add Key/Value Pair"); OnRefresh(status); base.OnRefresh(status); return; } if (a == "Add_Application") { string[] array = new string[1]; string[] array2 = new string[1]; array[0] = ""; array2[0] = ""; string text = "_NewApplication"; bool flag = false; bizilante.SSO.Helper.SSO sSO = new bizilante.SSO.Helper.SSO(); string[] applications = sSO.GetApplications(); for (int j = 0; j < applications.Length; j++) { if (applications[j].ToUpper() == text.ToUpper()) { flag = true; } } if (flag) { MessageBoxParameters messageBoxParameters = new MessageBoxParameters(); messageBoxParameters.Text = "This application already exists"; messageBoxParameters.Caption = "Add New Application"; messageBoxParameters.Icon = MessageBoxIcon.Exclamation; SnapIn.Console.ShowDialog(messageBoxParameters); } else { ScopeNode scopeNode2 = new ScopeNode(); scopeNode2.DisplayName = "_NewApplication"; ScopeNode scopeNode3 = new ScopeNode(); Children.Add(scopeNode2); int count = Children.Count; sSO.CreateApplicationFieldsValues("_NewApplication", array, array2); Children[count - 1] = new ApplicationScopeNode("_NewApplication"); } base.OnRefresh(status); return; } if (!(a == "Export")) { if (!(a == "Import")) { return; } DialogResult dialogResult = SSOHelper.OpenSSOImportFile( out _applicationFileName, out _encryptedText, this); if (dialogResult != DialogResult.Cancel) { EncryptionKey_PropertyPage encryptionKey_PropertyPage = new EncryptionKey_PropertyPage("Import", _applicationFileName, _encryptedText); encryptionKey_PropertyPage.EncryptionKeyEnteredForImport += new EventHandler <EventArgs <bool, string> >(propertyPage_EncryptionKeyEnteredForImport); AcceptKeyForImportForm form = new AcceptKeyForImportForm(encryptionKey_PropertyPage); base.SnapIn.Console.ShowDialog(form); } base.OnRefresh(status); } else { EncryptionKey_PropertyPage encryptionKey_PropertyPage2 = new EncryptionKey_PropertyPage("Export", base.DisplayName); AcceptKeyForImportForm form2 = new AcceptKeyForImportForm(encryptionKey_PropertyPage2); base.SnapIn.Console.ShowDialog(form2); if (encryptionKey_PropertyPage2.EncryptionKey != null && encryptionKey_PropertyPage2.EncryptionKey.Length != 0) { if (!SSOHelper.ExportSSOApplication(base.DisplayName, encryptionKey_PropertyPage2.EncryptionKey, this)) { MessageBoxParameters messageBoxParameters2 = new MessageBoxParameters(); messageBoxParameters2.Text = "Error exporting the application. Please check the event log for further information"; messageBoxParameters2.Caption = "Export Application Error"; messageBoxParameters2.Icon = MessageBoxIcon.Hand; base.SnapIn.Console.ShowDialog(messageBoxParameters2); return; } } } } }