public DialogResult ShowDialog(IWin32Window owner, string fileName, object importIntoObject, bool chkUsersAndGroups, bool chkDBUsers, bool chkAuthorizations, SqlAzManMergeOptions mergeOptions) { this.DialogResult = DialogResult.None; this.TopMost = true; this.Show(owner); /*Application.DoEvents();*/ XmlDocument doc = new XmlDocument(); doc.Load(fileName); XmlNode xmlStartNode; if (this.checkScopeNodePosition(doc, ref importIntoObject, out xmlStartNode)) { IAzManStorage storage = this.getStorageReference(importIntoObject); try { storage.BeginTransaction(AzManIsolationLevel.ReadUncommitted); ((IAzManImport)importIntoObject).ImportChildren(xmlStartNode, chkUsersAndGroups, chkDBUsers, chkAuthorizations, mergeOptions); storage.CommitTransaction(); this.Hide(); return this.DialogResult = DialogResult.OK; } catch { storage.RollBackTransaction(); this.DialogResult = DialogResult.Cancel; this.Hide(); throw; } } else { return this.DialogResult = DialogResult.Cancel; } }
public void doImport(object importIntoObject, bool chkUsersAndGroups, bool chkDBUsers, bool chkAuthorizations, SqlAzManMergeOptions mergeOptions) { XmlDocument doc = new XmlDocument(); doc.Load(this.FileUpload1.PostedFile.InputStream); XmlNode xmlStartNode; if (this.checkScopeNodePosition(doc, ref importIntoObject, out xmlStartNode)) { try { this.storage.BeginTransaction(AzManIsolationLevel.ReadUncommitted); ((IAzManImport)importIntoObject).ImportChildren(xmlStartNode, chkUsersAndGroups, chkDBUsers, chkAuthorizations, mergeOptions); this.storage.CommitTransaction(); this.closeWindow(true); } catch { this.storage.RollBackTransaction(); throw; } } else { this.closeWindow(false); } }
private bool ImportRecord() { bool result = false; try { /** * List<IAzManExport> objectsToExport = new List<IAzManExport>(); * object selectedObject = Session["selectedObject"]; * * switch (_Type) * { * case AzManItemType.Storage: * objectsToExport.AddRange(_Storage.GetStores()); * break; * case AzManItemType.ItemDefinitions: * objectsToExport.AddRange(((IAzManApplication)selectedObject).GetItems()); * break; * default: * objectsToExport.Add((IAzManExport)selectedObject); * break; * } */ SqlAzManMergeOptions mergeOptions = SqlAzManMergeOptions.NoMerge; if (this.chkCreatesNewItems.Checked) { mergeOptions |= SqlAzManMergeOptions.CreatesNewItems; } if (this.chkOverwritesExistingItems.Checked) { mergeOptions |= SqlAzManMergeOptions.OverwritesExistingItems; } if (this.chkDeleteMissingItems.Checked) { mergeOptions |= SqlAzManMergeOptions.DeleteMissingItems; } if (this.chkCreatesNewItemAuthorizations.Checked) { mergeOptions |= SqlAzManMergeOptions.CreatesNewItemAuthorizations; } if (this.chkOverwritesItemAuthorizations.Checked) { mergeOptions |= SqlAzManMergeOptions.OverwritesExistingItemAuthorization; } if (this.chkDeleteMissingItemAuthorizations.Checked) { mergeOptions |= SqlAzManMergeOptions.DeleteMissingItemAuthorizations; } this.doImport(this.Session["selectedObject"], chkWindowsUsers.Checked, this.chkDBUsers.Checked, this.chkAuthorizations.Checked, mergeOptions); result = true; } catch (Exception ex) { //throw ex; } return(result); }
private void btnNext_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.None; frmImport frm = new frmImport(); try { this.Close(); SqlAzManMergeOptions mergeOptions = SqlAzManMergeOptions.NoMerge; if (this.chkCreatesNewItems.Checked) { mergeOptions |= SqlAzManMergeOptions.CreatesNewItems; } if (this.chkOverwritesExistingItems.Checked) { mergeOptions |= SqlAzManMergeOptions.OverwritesExistingItems; } if (this.chkDeleteMissingItems.Checked) { mergeOptions |= SqlAzManMergeOptions.DeleteMissingItems; } if (this.chkCreatesNewItemAuthorizations.Checked) { mergeOptions |= SqlAzManMergeOptions.CreatesNewItemAuthorizations; } if (this.chkOverwritesItemAuthorizations.Checked) { mergeOptions |= SqlAzManMergeOptions.OverwritesExistingItemAuthorization; } if (this.chkDeleteMissingItemAuthorizations.Checked) { mergeOptions |= SqlAzManMergeOptions.DeleteMissingItemAuthorizations; } frm.ShowDialog(this, fileName, importIntoObject, this.chkUsersAndGroups.Checked, this.chkDBUsers.Checked, this.chkAuthorizations.Checked, mergeOptions); /*Application.DoEvents();*/ } catch (Exception ex) { this.ShowError(ex.Message, Globalization.MultilanguageResource.GetString("frmImportOptions_Msg10")); } finally { this.DialogResult = DialogResult.OK; } }
protected void btnOk_Click(object sender, EventArgs e) { try { SqlAzManMergeOptions mergeOptions = SqlAzManMergeOptions.NoMerge; if (this.chkCreatesNewItems.Checked) { mergeOptions |= SqlAzManMergeOptions.CreatesNewItems; } if (this.chkOverwritesExistingItems.Checked) { mergeOptions |= SqlAzManMergeOptions.OverwritesExistingItems; } if (this.chkDeleteMissingItems.Checked) { mergeOptions |= SqlAzManMergeOptions.DeleteMissingItems; } if (this.chkCreatesNewItemAuthorizations.Checked) { mergeOptions |= SqlAzManMergeOptions.CreatesNewItemAuthorizations; } if (this.chkOverwritesItemAuthorizations.Checked) { mergeOptions |= SqlAzManMergeOptions.OverwritesExistingItemAuthorization; } if (this.chkDeleteMissingItemAuthorizations.Checked) { mergeOptions |= SqlAzManMergeOptions.DeleteMissingItemAuthorizations; } this.doImport(this.Session["selectedObject"], this.chkUsersAndGroups.Checked, this.chkDBUsers.Checked, this.chkAuthorizations.Checked, mergeOptions); this.closeWindow(true); } catch (Exception ex) { this.ShowError(ex.Message); } }
/// <summary> /// Imports the specified XML reader. /// </summary> /// <param name="xmlNode">The XML node.</param> /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param> /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param> /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param> /// <param name="mergeOptions">The merge options.</param> public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions) { foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "Attributes") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Attribute") { IAzManAttribute <IAzManAuthorization> newAuthorizationAttribute = this.CreateAttribute(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value); } } } else if (node.Name == "Attribute") { IAzManAttribute <IAzManAuthorization> newAuthorizationAttribute = this.CreateAttribute(node.Attributes["Key"].Value, node.Attributes["Value"].Value); } } }
/// <summary> /// Imports the specified XML reader. /// </summary> /// <param name="xmlNode">The XML node.</param> /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param> /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param> /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param> /// <param name="mergeOptions">The merge options.</param> public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions) { List<IAzManAuthorization> importedAuthorizations = new List<IAzManAuthorization>(); foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "Attributes") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Attribute") { if (!this.Attributes.ContainsKey(childNode.Attributes["Key"].Value)) { IAzManAttribute<IAzManItem> newItemAttribute = this.CreateAttribute(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value); } } } } else if (node.Name == "Attribute") { if (!this.Attributes.ContainsKey(node.Attributes["Key"].Value)) { IAzManAttribute<IAzManItem> newItemAttribute = this.CreateAttribute(node.Attributes["Key"].Value, node.Attributes["Value"].Value); } } System.Windows.Forms.Application.DoEvents(); if (node.Name == "BizRule") { string sLang = node.Attributes["BizRuleSourceLanguage"].Value; NetSqlAzMan.BizRuleSourceLanguage lang = NetSqlAzMan.BizRuleSourceLanguage.CSharp; if (String.Compare(sLang, NetSqlAzMan.BizRuleSourceLanguage.VBNet.ToString(), true) == 0) { lang = NetSqlAzMan.BizRuleSourceLanguage.VBNet; } string source = node.InnerText; this.ReloadBizRule(source, lang); } if (node.Name == "Member") { IAzManItem member = this.application.GetItem(node.Attributes["Name"].Value); if (!this.Members.ContainsKey(member.Name)) this.AddMember(member); } else if (node.Name == "Members") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Member") { IAzManItem member = this.application.GetItem(childNode.Attributes["Name"].Value); if (!this.Members.ContainsKey(member.Name)) this.AddMember(member); } } } else if (includeAuthorizations && node.Name == "Authorizations") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Authorization") { WhereDefined sidWhereDefined; switch (childNode.Attributes["SidWhereDefined"].Value) { case "Application": sidWhereDefined = WhereDefined.Application; break; case "LDAP": sidWhereDefined = WhereDefined.LDAP; break; case "Local": sidWhereDefined = WhereDefined.Local; break; case "Store": sidWhereDefined = WhereDefined.Store; break; case "Database": sidWhereDefined = WhereDefined.Database; break; default: throw new System.Xml.Schema.XmlSchemaValidationException("WhereDefined attribute not valid."); } WhereDefined ownerSidWhereDefined; switch (childNode.Attributes["OwnerSidWhereDefined"].Value) { case "Application": ownerSidWhereDefined = WhereDefined.Application; break; case "LDAP": ownerSidWhereDefined = WhereDefined.LDAP; break; case "Local": ownerSidWhereDefined = WhereDefined.Local; break; case "Store": ownerSidWhereDefined = WhereDefined.Store; break; case "Database": ownerSidWhereDefined = WhereDefined.Database; break; default: throw new System.Xml.Schema.XmlSchemaValidationException("OwnerSidWhereDefined attribute not valid."); } AuthorizationType authorizationType; switch (childNode.Attributes["AuthorizationType"].Value) { case "Allow": authorizationType = AuthorizationType.Allow; break; case "AllowWithDelegation": authorizationType = AuthorizationType.AllowWithDelegation; break; case "Deny": authorizationType = AuthorizationType.Deny; break; case "Neutral": authorizationType = AuthorizationType.Neutral; break; default: throw new System.Xml.Schema.XmlSchemaValidationException("AuthorizationType attribute not valid."); } DateTime? validFrom = null; DateTime? validTo = null; DateTime app; if (DateTime.TryParse(childNode.Attributes["ValidFrom"].Value, out app)) validFrom = app; if (DateTime.TryParse(childNode.Attributes["ValidTo"].Value, out app)) validTo = app; if (includeWindowsUsersAndGroups || !includeWindowsUsersAndGroups && sidWhereDefined != WhereDefined.LDAP && sidWhereDefined != WhereDefined.Local && this.application.Store.Storage.Mode != NetSqlAzManMode.Developer || includeDBUsers && sidWhereDefined == WhereDefined.Database || sidWhereDefined == WhereDefined.Store || sidWhereDefined == WhereDefined.Application) { IAzManSid authSid = new SqlAzManSID(childNode.Attributes["Sid"].Value, sidWhereDefined == WhereDefined.Database); IAzManSid ownerSid = new SqlAzManSID(childNode.Attributes["Owner"].Value, sidWhereDefined == WhereDefined.Database); IAzManAuthorization authorization = null; if (MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.OverwritesExistingItemAuthorization)) { authorization = this.CreateAuthorization(ownerSid, ownerSidWhereDefined, authSid, sidWhereDefined, authorizationType, validFrom, validTo); importedAuthorizations.Add(authorization); } else if (MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.CreatesNewItemAuthorizations)) { bool alreadyExists = false; foreach (var auth in this.GetAuthorizations(ownerSid, authSid)) { if (auth.ValidFrom == validFrom && auth.ValidTo == validTo && auth.AuthorizationType == authorizationType) { alreadyExists = true; break; } } if (!alreadyExists) { authorization = this.CreateAuthorization(ownerSid, ownerSidWhereDefined, authSid, sidWhereDefined, authorizationType, validFrom, validTo); importedAuthorizations.Add(authorization); } } if (authorization != null) authorization.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } } } //Delete missing item Authorizations if (MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.DeleteMissingItemAuthorizations)) { foreach (var auth in this.GetAuthorizations()) { bool exists = false; foreach (var iauth in importedAuthorizations) { if (this.areEquals(auth, iauth)) { exists = true; break; } } if (!exists) { auth.Delete(); } } } }
/// <summary> /// Imports the specified XML reader. /// </summary> /// <param name="xmlNode">The XML node.</param> /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param> /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param> /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param> /// <param name="mergeOptions">The merge options.</param> public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions) { //Create Store Groups foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "Attributes") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Attribute") { if (!this.Attributes.ContainsKey(childNode.Attributes["Key"].Value)) { IAzManAttribute <IAzManStore> newStoreAttribute = this.CreateAttribute(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value); } else { this.Attributes[childNode.Attributes["Key"].Value].Update(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value); } } } } else if (node.Name == "Attribute") { if (!this.Attributes.ContainsKey(node.Attributes["Key"].Value)) { IAzManAttribute <IAzManStore> newStoreAttribute = this.CreateAttribute(node.Attributes["Key"].Value, node.Attributes["Value"].Value); } else { this.Attributes[node.Attributes["Key"].Value].Update(node.Attributes["Key"].Value, node.Attributes["Value"].Value); } } if (node.Name == "Permissions") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Managers") { foreach (XmlNode childChildNode in childNode.ChildNodes) { if (childChildNode.Name == "Manager") { this.GrantAccessAsManager(childChildNode.Attributes["SqlUserOrRole"].Value); } } } else if (childNode.Name == "Users") { foreach (XmlNode childChildNode in childNode.ChildNodes) { if (childChildNode.Name == "User") { this.GrantAccessAsUser(childChildNode.Attributes["SqlUserOrRole"].Value); } } } else if (childNode.Name == "Readers") { foreach (XmlNode childChildNode in childNode.ChildNodes) { if (childChildNode.Name == "Reader") { this.GrantAccessAsReader(childChildNode.Attributes["SqlUserOrRole"].Value); } } } } } if (node.Name == "StoreGroups") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) { groupType = GroupType.LDapQuery; } IAzManStoreGroup storeGroup = null; string sid = null; if (this.StoreGroups.ContainsKey(childNode.Attributes["Name"].Value)) { storeGroup = this.StoreGroups[childNode.Attributes["Name"].Value]; sid = storeGroup.SID.StringValue; //Change Store Group SID MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid); } else { sid = SqlAzManSID.NewSqlAzManSid().StringValue; storeGroup = this.CreateStoreGroup(new SqlAzManSID(sid), childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value, childNode.Attributes["LDAPQuery"].Value, groupType); //Change Store Group SID MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid); } //newStoreGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeAuthorizations); } } } else if (node.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) { groupType = GroupType.LDapQuery; } IAzManStoreGroup storeGroup = null; string sid = null; if (this.StoreGroups.ContainsKey(node.Attributes["Name"].Value)) { storeGroup = this.StoreGroups[node.Attributes["Name"].Value]; sid = storeGroup.SID.StringValue; //Change Store Group SID MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid); } else { sid = SqlAzManSID.NewSqlAzManSid().StringValue; storeGroup = this.CreateStoreGroup(new SqlAzManSID(sid), node.Attributes["Name"].Value, node.Attributes["Description"].Value, node.Attributes["LDAPQuery"].Value, groupType); //Change Store Group SID MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid); } //newStoreGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeAuthorizations); } } //Create Applications & Store Group Members foreach (XmlNode node in xmlNode.ChildNodes) { System.Windows.Forms.Application.DoEvents(); if (node.Name == "Applications") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Application") { IAzManApplication newApplication = this.Applications.ContainsKey(childNode.Attributes["Name"].Value) ? this.Applications[childNode.Attributes["Name"].Value] : this.CreateApplication(childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value); newApplication.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } else if (node.Name == "Application") { IAzManApplication newApplication = this.Applications.ContainsKey(node.Attributes["Name"].Value) ? this.Applications[node.Attributes["Name"].Value] : this.CreateApplication(node.Attributes["Name"].Value, node.Attributes["Description"].Value); newApplication.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } else if (node.Name == "StoreGroups") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) { groupType = GroupType.LDapQuery; } if (groupType == GroupType.Basic) { IAzManStoreGroup newStoreGroup = this.StoreGroups[childNode.Attributes["Name"].Value]; newStoreGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } } else if (node.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) { groupType = GroupType.LDapQuery; } if (groupType == GroupType.Basic) { IAzManStoreGroup newStoreGroup = this.StoreGroups[node.Attributes["Name"].Value]; newStoreGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } this.applications = null; //Force refresh }
/// <summary> /// Determines whether the specified merge options is on. /// </summary> /// <param name="mergeOptions">The merge options.</param> /// <param name="option">The option.</param> /// <returns> /// <c>true</c> if the specified merge options is on; otherwise, <c>false</c>. /// </returns> public static bool IsOn(SqlAzManMergeOptions mergeOptions, SqlAzManMergeOptions option) { return (option & mergeOptions) == option; }
/// <summary> /// Imports the specified XML reader. /// </summary> /// <param name="xmlNode">The XML node.</param> /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param> /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param> /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param> /// <param name="mergeOptions">The merge options.</param> public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions) { foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "Store") { IAzManStore newStore = this.Stores.ContainsKey(node.Attributes["Name"].Value) ? this.Stores[node.Attributes["Name"].Value] : this.CreateStore(node.Attributes["Name"].Value, node.Attributes["Description"].Value); newStore.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } this.stores = null; //Force refresh }
/// <summary> /// Imports the specified XML reader. /// </summary> /// <param name="xmlNode">The XML node.</param> /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param> /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param> /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param> /// <param name="mergeOptions">The merge options.</param> public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions) { foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "ApplicationGroupMembers") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "ApplicationGroupMember") { WhereDefined whereDefined; switch (childNode.Attributes["WhereDefined"].Value) { case "Application": whereDefined = WhereDefined.Application; break; case "LDAP": whereDefined = WhereDefined.LDAP; break; case "Local": whereDefined = WhereDefined.Local; break; case "Store": whereDefined = WhereDefined.Store; break; case "Database": whereDefined = WhereDefined.Database; break; default: throw new System.Xml.Schema.XmlSchemaValidationException("WhereDefined attribute valid"); } bool isMember = false; if (childNode.Attributes["IsMember"].Value == "True") { isMember = true; } if (includeWindowsUsersAndGroups || !includeWindowsUsersAndGroups && whereDefined != WhereDefined.LDAP && whereDefined != WhereDefined.Local && this.application.Store.Storage.Mode != NetSqlAzManMode.Developer || includeDBUsers && whereDefined == WhereDefined.Database || whereDefined == WhereDefined.Store || whereDefined == WhereDefined.Application) { IAzManSid sid = new SqlAzManSID(childNode.Attributes["Sid"].Value, whereDefined == WhereDefined.Database); if (this.Members.Where(m => m.Key.StringValue == sid.StringValue).Count() == 0) this.CreateApplicationGroupMember(sid, whereDefined, isMember); } } } } else if (node.Name == "ApplicationGroupMember") { WhereDefined whereDefined; switch (node.Attributes["WhereDefined"].Value) { case "Application": whereDefined = WhereDefined.Application; break; case "LDAP": whereDefined = WhereDefined.LDAP; break; case "Local": whereDefined = WhereDefined.Local; break; case "Store": whereDefined = WhereDefined.Store; break; case "Database": whereDefined = WhereDefined.Database; break; default: throw new System.Xml.Schema.XmlSchemaValidationException("WhereDefined attribute not valid."); } bool isMember = false; if (node.Attributes["IsMember"].Value == "True") { isMember = true; } if (includeWindowsUsersAndGroups || !includeWindowsUsersAndGroups && whereDefined != WhereDefined.LDAP && whereDefined != WhereDefined.Local && this.application.Store.Storage.Mode != NetSqlAzManMode.Developer || includeDBUsers && whereDefined == WhereDefined.Database || whereDefined == WhereDefined.Store || whereDefined == WhereDefined.Application) { IAzManSid sid = new SqlAzManSID(node.Attributes["Sid"].Value, whereDefined == WhereDefined.Database); if (this.Members.Where(m => m.Key.StringValue == sid.StringValue).Count() == 0) this.CreateApplicationGroupMember(sid, whereDefined, isMember); } } } }
/// <summary> /// Imports the specified XML reader. /// </summary> /// <param name="xmlNode">The XML node.</param> /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param> /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param> /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param> /// <param name="mergeOptions">The merge options.</param> public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions) { foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "Attributes") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Attribute") { IAzManAttribute<IAzManAuthorization> newAuthorizationAttribute = this.CreateAttribute(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value); } } } else if (node.Name == "Attribute") { IAzManAttribute<IAzManAuthorization> newAuthorizationAttribute = this.CreateAttribute(node.Attributes["Key"].Value, node.Attributes["Value"].Value); } } }
/// <summary> /// Imports the specified XML reader. /// </summary> /// <param name="xmlNode">The XML node.</param> /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param> /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param> /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param> /// <param name="mergeOptions">The merge options.</param> public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions) { List<string> importedItemNames = new List<string>(); //First ... Create Application Groups foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "Attributes") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Attribute") { if (!this.Attributes.ContainsKey(childNode.Attributes["Key"].Value)) { IAzManAttribute<IAzManApplication> newApplicationAttribute = this.CreateAttribute(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value); } else { this.Attributes[childNode.Attributes["Key"].Value].Update(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value); } } } } else if (node.Name == "Attribute") { if (!this.Attributes.ContainsKey(node.Attributes["Key"].Value)) { IAzManAttribute<IAzManApplication> newApplicationAttribute = this.CreateAttribute(node.Attributes["Key"].Value, node.Attributes["Value"].Value); } else { this.Attributes[node.Attributes["Key"].Value].Update(node.Attributes["Key"].Value, node.Attributes["Value"].Value); } } System.Windows.Forms.Application.DoEvents(); if (node.Name == "Permissions") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Managers") { foreach (XmlNode childChildNode in childNode.ChildNodes) { if (childChildNode.Name == "Manager") this.GrantAccessAsManager(childChildNode.Attributes["SqlUserOrRole"].Value); } } else if (childNode.Name == "Users") { foreach (XmlNode childChildNode in childNode.ChildNodes) { if (childChildNode.Name == "User") this.GrantAccessAsUser(childChildNode.Attributes["SqlUserOrRole"].Value); } } else if (childNode.Name == "Readers") { foreach (XmlNode childChildNode in childNode.ChildNodes) { if (childChildNode.Name == "Reader") this.GrantAccessAsReader(childChildNode.Attributes["SqlUserOrRole"].Value); } } } } if (node.Name == "StoreGroups") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) groupType = GroupType.LDapQuery; IAzManStoreGroup storeGroup = null; string sid = null; if (this.Store.StoreGroups.ContainsKey(childNode.Attributes["Name"].Value)) { storeGroup = this.Store.StoreGroups[childNode.Attributes["Name"].Value]; sid = storeGroup.SID.StringValue; //Change Store Group SID MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid); } else { sid = SqlAzManSID.NewSqlAzManSid().StringValue; storeGroup = this.Store.CreateStoreGroup(new SqlAzManSID(sid), childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value, childNode.Attributes["LDAPQuery"].Value, groupType); //Change Store Group SID MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid); } //newStoreGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeAuthorizations); } } } else if (node.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) groupType = GroupType.LDapQuery; IAzManStoreGroup storeGroup = null; string sid = null; if (this.Store.StoreGroups.ContainsKey(node.Attributes["Name"].Value)) { storeGroup = this.Store.StoreGroups[node.Attributes["Name"].Value]; sid = storeGroup.SID.StringValue; //Change Store Group SID MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid); } else { sid = SqlAzManSID.NewSqlAzManSid().StringValue; storeGroup = this.Store.CreateStoreGroup(new SqlAzManSID(sid), node.Attributes["Name"].Value, node.Attributes["Description"].Value, node.Attributes["LDAPQuery"].Value, groupType); //Change Store Group SID MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid); } //newStoreGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeAuthorizations); } if (node.Name == "ApplicationGroups") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "ApplicationGroup") { GroupType groupType = GroupType.Basic; if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) groupType = GroupType.LDapQuery; IAzManApplicationGroup applicationGroup = null; string sid = null; if (this.ApplicationGroups.ContainsKey(childNode.Attributes["Name"].Value)) { applicationGroup = this.ApplicationGroups[childNode.Attributes["Name"].Value]; sid = applicationGroup.SID.StringValue; //Change Application Group SID MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid); } else { sid = SqlAzManSID.NewSqlAzManSid().StringValue; applicationGroup = this.CreateApplicationGroup(new SqlAzManSID(sid), childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value, childNode.Attributes["LDAPQuery"].Value, groupType); //Change Application Group SID MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid); } //newApplicationGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeAuthorizations); } } } else if (node.Name == "ApplicationGroup") { GroupType groupType = GroupType.Basic; if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) groupType = GroupType.LDapQuery; IAzManApplicationGroup applicationGroup = null; string sid = null; if (this.ApplicationGroups.ContainsKey(node.Attributes["Name"].Value)) { applicationGroup = this.ApplicationGroups[node.Attributes["Name"].Value]; sid = applicationGroup.SID.StringValue; //Change Application Group SID MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid); } else { sid = SqlAzManSID.NewSqlAzManSid().StringValue; applicationGroup = this.CreateApplicationGroup(new SqlAzManSID(sid), node.Attributes["Name"].Value, node.Attributes["Description"].Value, node.Attributes["LDAPQuery"].Value, groupType); //Change Application Group SID MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid); } //newApplicationGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeAuthorizations); } } //Then ... Create Items & Application Groups members foreach (XmlNode node in xmlNode.ChildNodes) { System.Windows.Forms.Application.DoEvents(); if (node.Name == "Item") { ItemType itemType; switch (node.Attributes["ItemType"].Value) { case "Role": itemType = ItemType.Role; break; case "Task": itemType = ItemType.Task; break; case "Operation": itemType = ItemType.Operation; break; default: throw new SerializationException("Invalid ItemType on xml node: " + node.InnerXml); } IAzManItem item = this.Items.ContainsKey(node.Attributes["Name"].Value) ? this.Items[node.Attributes["Name"].Value] : null; if (item == null && MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.CreatesNewItems)) { this.CreateItem(node.Attributes["Name"].Value, node.Attributes["Description"].Value, itemType); importedItemNames.Add(node.Attributes["Name"].Value); } else if (MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.OverwritesExistingItems)) { if (item != null) item.Delete(); this.CreateItem(node.Attributes["Name"].Value, node.Attributes["Description"].Value, itemType); importedItemNames.Add(node.Attributes["Name"].Value); } //Overwrites existing authorizations if (item != null && MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.OverwritesExistingItemAuthorization)) { foreach (var auth in item.GetAuthorizations()) { auth.Delete(); } } } else if (node.Name == "Items") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Item") { ItemType childItemType; switch (childNode.Attributes["ItemType"].Value) { case "Role": childItemType = ItemType.Role; break; case "Task": childItemType = ItemType.Task; break; case "Operation": childItemType = ItemType.Operation; break; default: throw new SerializationException("Invalid ItemType on xml node: " + childNode.InnerXml); } IAzManItem newItem = this.Items.ContainsKey(childNode.Attributes["Name"].Value) ? this.Items[childNode.Attributes["Name"].Value] : null; if (newItem == null && MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.CreatesNewItems)) { this.CreateItem(childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value, childItemType); importedItemNames.Add(childNode.Attributes["Name"].Value); } else if (MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.OverwritesExistingItems)) { if (newItem != null) { //If overwrite ... clear attributes, bizrules, members newItem.Update(childNode.Attributes["Description"].Value); foreach (var attr in newItem.GetAttributes()) { attr.Delete(); } newItem.ClearBizRule(); foreach (var member in newItem.GetMembers()) { newItem.RemoveMember(member); } } else { this.CreateItem(childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value, childItemType); } importedItemNames.Add(childNode.Attributes["Name"].Value); } //Overwrites existing authorizations if (newItem != null && MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.OverwritesExistingItemAuthorization)) { foreach (var auth in newItem.GetAuthorizations()) { auth.Delete(); } } } } } else if (node.Name == "ApplicationGroups") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "ApplicationGroup") { GroupType groupType = GroupType.Basic; if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) groupType = GroupType.LDapQuery; if (groupType == GroupType.Basic) { IAzManApplicationGroup newApplicationGroup = this.GetApplicationGroup(childNode.Attributes["Name"].Value); newApplicationGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } } else if (node.Name == "ApplicationGroup") { GroupType groupType = GroupType.Basic; if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) groupType = GroupType.LDapQuery; if (groupType == GroupType.Basic) { IAzManApplicationGroup newApplicationGroup = this.GetApplicationGroup(node.Attributes["Name"].Value); newApplicationGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } else if (node.Name == "StoreGroups") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) groupType = GroupType.LDapQuery; if (groupType == GroupType.Basic) { IAzManStoreGroup newStoreGroup = this.Store.GetStoreGroup(childNode.Attributes["Name"].Value); newStoreGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } } else if (node.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) groupType = GroupType.LDapQuery; if (groupType == GroupType.Basic) { IAzManStoreGroup newStoreGroup = this.Store.GetStoreGroup(new SqlAzManSID(node.Attributes["Name"].Value)); newStoreGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } //Then ... Create Item Members foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "Item") { IAzManItem item = this.GetItem(node.Attributes["Name"].Value); if (item != null) item.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } else if (node.Name == "Items") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Item") { IAzManItem item = this.GetItem(childNode.Attributes["Name"].Value); if (item != null) item.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } } //Delete missing items if (MergeUtilities.IsOn(mergeOptions, SqlAzManMergeOptions.DeleteMissingItems)) { foreach (var it in this.GetItems()) { bool exists = false; foreach (var iit in importedItemNames) { if (String.Compare(iit, it.Name, true) == 0) { exists = true; break; } } if (!exists) it.Delete(); } } this.items = null; //Force refresh }
/// <summary> /// Imports the specified XML reader. /// </summary> /// <param name="xmlNode">The XML node.</param> /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param> /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param> /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param> /// <param name="mergeOptions">The merge options.</param> public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions) { foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "StoreGroupMembers") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "StoreGroupMember") { WhereDefined whereDefined; switch (childNode.Attributes["WhereDefined"].Value) { case "Application": whereDefined = WhereDefined.Application; break; case "LDAP": whereDefined = WhereDefined.LDAP; break; case "Local": whereDefined = WhereDefined.Local; break; case "Store": whereDefined = WhereDefined.Store; break; case "Database": whereDefined = WhereDefined.Database; break; default: throw new System.Xml.Schema.XmlSchemaValidationException("WhereDefined attribute valid"); } bool isMember = false; if (childNode.Attributes["IsMember"].Value == "True") { isMember = true; } if (includeWindowsUsersAndGroups || !includeWindowsUsersAndGroups && whereDefined != WhereDefined.LDAP && whereDefined != WhereDefined.Local && this.Store.Storage.Mode != NetSqlAzManMode.Developer || includeDBUsers && whereDefined == WhereDefined.Database || whereDefined == WhereDefined.Store || whereDefined == WhereDefined.Application) { IAzManSid sid = new SqlAzManSID(childNode.Attributes["Sid"].Value, whereDefined == WhereDefined.Database); if (this.Members.Where(m => m.Key.StringValue == sid.StringValue).Count() == 0) { this.CreateStoreGroupMember(sid, whereDefined, isMember); } } } } } else if (node.Name == "StoreGroupMember") { WhereDefined whereDefined; switch (node.Attributes["WhereDefined"].Value) { case "Application": whereDefined = WhereDefined.Application; break; case "LDAP": whereDefined = WhereDefined.LDAP; break; case "Local": whereDefined = WhereDefined.Local; break; case "Store": whereDefined = WhereDefined.Store; break; default: throw new System.Xml.Schema.XmlSchemaValidationException("WhereDefined attribute not valid."); } bool isMember = false; if (node.Attributes["IsMember"].Value == "True") { isMember = true; } if (includeWindowsUsersAndGroups || !includeWindowsUsersAndGroups && whereDefined != WhereDefined.LDAP && whereDefined != WhereDefined.Local && this.Store.Storage.Mode != NetSqlAzManMode.Developer || whereDefined == WhereDefined.Store || whereDefined == WhereDefined.Application) { IAzManSid sid = new SqlAzManSID(node.Attributes["Sid"].Value, whereDefined == WhereDefined.Database); if (this.Members.Where(m => m.Key.StringValue == sid.StringValue).Count() == 0) { this.CreateStoreGroupMember(sid, whereDefined, isMember); } } } } }
/// <summary> /// Determines whether the specified merge options is on. /// </summary> /// <param name="mergeOptions">The merge options.</param> /// <param name="option">The option.</param> /// <returns> /// <c>true</c> if the specified merge options is on; otherwise, <c>false</c>. /// </returns> public static bool IsOn(SqlAzManMergeOptions mergeOptions, SqlAzManMergeOptions option) { return((option & mergeOptions) == option); }
public DialogResult ShowDialog(IWin32Window owner, string fileName, object importIntoObject, bool chkUsersAndGroups, bool chkDBUsers, bool chkAuthorizations, SqlAzManMergeOptions mergeOptions) { this.DialogResult = DialogResult.None; this.TopMost = true; this.Show(owner); /*Application.DoEvents();*/ XmlDocument doc = new XmlDocument(); doc.Load(fileName); XmlNode xmlStartNode; if (this.checkScopeNodePosition(doc, ref importIntoObject, out xmlStartNode)) { IAzManStorage storage = this.getStorageReference(importIntoObject); try { storage.BeginTransaction(AzManIsolationLevel.ReadUncommitted); ((IAzManImport)importIntoObject).ImportChildren(xmlStartNode, chkUsersAndGroups, chkDBUsers, chkAuthorizations, mergeOptions); storage.CommitTransaction(); this.Hide(); return(this.DialogResult = DialogResult.OK); } catch { storage.RollBackTransaction(); this.DialogResult = DialogResult.Cancel; this.Hide(); throw; } } else { return(this.DialogResult = DialogResult.Cancel); } }