Exemplo n.º 1
0
 private void raiseStoreAttributeCreated(IAzManStore owner, IAzManAttribute <IAzManStore> attributeCreated)
 {
     if (this.StoreAttributeCreated != null)
     {
         this.StoreAttributeCreated(owner, attributeCreated);
     }
 }
 private void btnRemove_Click(object sender, EventArgs e)
 {
     if (this.lsvAttributes.SelectedItems.Count > 0)
     {
         foreach (ListViewItem lvi in this.lsvAttributes.SelectedItems)
         {
             if ((lvi.Tag as IAzManAttribute <IAzManAuthorization>) != null)
             {
                 IAzManAttribute <IAzManAuthorization> lviTag = (IAzManAttribute <IAzManAuthorization>)lvi.Tag;
                 this.attributesToRemove.Add(new KeyValuePair <string, string>(lviTag.Key, lviTag.Value));
             }
             else //if ((lvi.Tag as KeyValuePair<string,string>) != null)
             {
                 KeyValuePair <string, string> lviTag         = (KeyValuePair <string, string>)lvi.Tag;
                 KeyValuePair <string, string> attributeFound = this.FindAttribute(this.attributesToAdd, lviTag.Key);
                 if (attributeFound.Key != null)
                 {
                     this.attributesToAdd.Remove(attributeFound);
                 }
                 attributeFound = this.FindAttribute(this.attributesToUpdate, lviTag.Key);
                 if (attributeFound.Key != null)
                 {
                     this.attributesToUpdate.Remove(attributeFound);
                     this.attributesToRemove.Add(attributeFound);
                 }
             }
         }
         this.modified         = true;
         this.btnApply.Enabled = true;
         this.refreshAuthorizationAttributes();
     }
     this.HourGlass(false);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Raises the attribute updated.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <param name="oldKey">The old key.</param>
 /// <param name="oldValue">The old value.</param>
 protected void raiseAttributeUpdated(IAzManAttribute <OWNER> attribute, string oldKey, string oldValue)
 {
     if (this.AttributeUpdated != null)
     {
         this.AttributeUpdated(attribute, oldKey, oldValue);
     }
 }
 private void btnMembersRemove_Click(object sender, EventArgs e)
 {
     this.HourGlass(true);
     foreach (ListViewItem lvi in this.lsvAttributes.CheckedItems)
     {
         if ((lvi.Tag as IAzManAttribute <IAzManAuthorization>) != null)
         {
             IAzManAttribute <IAzManAuthorization> lviTag = (IAzManAttribute <IAzManAuthorization>)(lvi.Tag);
             this.attributesToRemove.Add(new KeyValuePair <string, string>(lviTag.Key, lviTag.Value));
             this.modified = true;
         }
         else // if ((lvi.Tag as KeyValuePair<string, string>) != null)
         {
             KeyValuePair <string, string> lviTag = (KeyValuePair <string, string>)(lvi.Tag);
             this.attributesToRemove.Add(lviTag);
             this.modified = true;
         }
     }
     this.refreshAuthorizationAttributes();
     if (this.lsvAttributes.Items.Count == 0)
     {
         this.btnRemove.Enabled = false;
     }
     this.HourGlass(false);
 }
 private void raiseAuthorizationAttributeCreated(IAzManAuthorization owner, IAzManAttribute <IAzManAuthorization> attributeCreated)
 {
     if (this.AuthorizationAttributeCreated != null)
     {
         this.AuthorizationAttributeCreated(owner, attributeCreated);
     }
 }
        private ListViewItem CreateAuthorizationAttributeListViewItem(IAzManAttribute <IAzManAuthorization> Attribute)
        {
            ListViewItem lvi = new ListViewItem();

            lvi.Tag        = Attribute;
            lvi.ImageIndex = 0;
            lvi.Text       = Attribute.Key;
            lvi.SubItems.Add(Attribute.Value);
            return(lvi);
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            frmAttributeProperties frm = new frmAttributeProperties();

            if (this.lsvAttributes.SelectedItems[0].Tag as IAzManAttribute <IAzManAuthorization> != null)
            {
                IAzManAttribute <IAzManAuthorization> attr = this.lsvAttributes.SelectedItems[0].Tag as IAzManAttribute <IAzManAuthorization>;
                frm.key   = attr.Key;
                frm.value = attr.Value;
            }
            else //if (this.lsvAttributes.SelectedItems[0].Tag as KeyValuePair<string, string>)
            {
                KeyValuePair <string, string> attr = (KeyValuePair <string, string>) this.lsvAttributes.SelectedItems[0].Tag;
                frm.key   = attr.Key;
                frm.value = attr.Value;
            }
            DialogResult dr = frm.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                if (this.lsvAttributes.SelectedItems[0].Tag as IAzManAttribute <IAzManAuthorization> != null)
                {
                    IAzManAttribute <IAzManAuthorization> attr           = this.lsvAttributes.SelectedItems[0].Tag as IAzManAttribute <IAzManAuthorization>;
                    KeyValuePair <string, string>         keyValueToEdit = new KeyValuePair <string, string>(attr.Key, frm.value);
                    this.attributesToUpdate.Add(keyValueToEdit);
                    this.lsvAttributes.SelectedItems[0].SubItems[1].Text = keyValueToEdit.Value;
                    this.lsvAttributes.SelectedItems[0].Tag = keyValueToEdit;
                    this.lsvAttributes.Focus();
                }
                else //if (this.lsvAttributes.SelectedItems[0].Tag as KeyValuePair<string, string>)
                {
                    KeyValuePair <string, string> attr = this.FindAttribute(this.attributesToUpdate, frm.key);
                    if (attr.Key == null)
                    {
                        attr = this.FindAttribute(this.attributesToAdd, frm.key);
                    }
                    KeyValuePair <string, string> newAttr = new KeyValuePair <string, string>(attr.Key, frm.value);
                    this.attributesToUpdate.Remove(attr);
                    this.attributesToUpdate.Add(newAttr);
                    this.lsvAttributes.SelectedItems[0].SubItems[1].Text = newAttr.Value;
                    this.lsvAttributes.SelectedItems[0].Tag = newAttr;
                    this.lsvAttributes.Focus();
                }
                this.modified         = true;
                this.btnApply.Enabled = true;
            }
            this.HourGlass(false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create a Full Storage through .NET code
        /// </summary>
        private void CreateFullStorage()
        {
            // USER MUST BE A MEMBER OF SQL DATABASE ROLE: NetSqlAzMan_Administrators

            //Sql Storage connection string
            string sqlConnectionString = "data source=(local);initial catalog=NetSqlAzManStorage;user id=netsqlazmanuser;password=password";
            //Create an instance of SqlAzManStorage class
            IAzManStorage storage = new SqlAzManStorage(sqlConnectionString);

            //Open Storage Connection
            storage.OpenConnection();
            //Begin a new Transaction
            storage.BeginTransaction(AzManIsolationLevel.ReadUncommitted);
            //Create a new Store
            IAzManStore newStore = storage.CreateStore("My Store", "Store description");
            //Create a new Basic StoreGroup
            IAzManStoreGroup newStoreGroup = newStore.CreateStoreGroup(SqlAzManSID.NewSqlAzManSid(), "My Store Group", "Store Group Description", String.Empty, GroupType.Basic);
            //Retrieve current user SID
            IAzManSid mySid = new SqlAzManSID(((System.Threading.Thread.CurrentPrincipal.Identity as WindowsIdentity) ?? WindowsIdentity.GetCurrent()).User);
            //Add myself as sid of "My Store Group"
            IAzManStoreGroupMember storeGroupMember = newStoreGroup.CreateStoreGroupMember(mySid, WhereDefined.Local, true);
            //Create a new Application
            IAzManApplication newApp = newStore.CreateApplication("New Application", "Application description");
            //Create a new Role
            IAzManItem newRole = newApp.CreateItem("New Role", "Role description", ItemType.Role);
            //Create a new Task
            IAzManItem newTask = newApp.CreateItem("New Task", "Task description", ItemType.Task);
            //Create a new Operation
            IAzManItem newOp = newApp.CreateItem("New Operation", "Operation description", ItemType.Operation);

            //Add "New Operation" as a sid of "New Task"
            newTask.AddMember(newOp);
            //Add "New Task" as a sid of "New Role"
            newRole.AddMember(newTask);
            //Create an authorization for myself on "New Role"
            IAzManAuthorization auth = newRole.CreateAuthorization(mySid, WhereDefined.Local, mySid, WhereDefined.Local, AuthorizationType.AllowWithDelegation, null, null);
            //Create a custom attribute
            IAzManAttribute <IAzManAuthorization> attr = auth.CreateAttribute("New Key", "New Value");
            //Create an authorization for DB User "Andrea" on "New Role"
            IAzManAuthorization auth2 = newRole.CreateAuthorization(mySid, WhereDefined.Local, storage.GetDBUser("Andrea").CustomSid, WhereDefined.Local, AuthorizationType.AllowWithDelegation, null, null);

            //Commit transaction
            storage.CommitTransaction();
            //Close connection
            storage.CloseConnection();
        }
 /// <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);
         }
     }
 }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAttributeProperties frm = new frmAttributeProperties();
            DialogResult           dr  = frm.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                KeyValuePair <string, string>         keyValueToRemove       = this.FindAttribute(this.attributesToRemove, frm.key);
                KeyValuePair <string, string>         keyValue1              = this.FindAttribute(this.attributesToAdd, frm.key);
                IAzManAttribute <IAzManAuthorization> authorizationAttribute = this.FindAttribute(this.authorization.GetAttributes(), frm.key);
                if (keyValueToRemove.Key == null && keyValue1.Key == null && authorizationAttribute == null)
                {
                    KeyValuePair <string, string> keyValueTaAdd = new KeyValuePair <string, string>(frm.key, frm.value);
                    this.attributesToAdd.Add(keyValueTaAdd);
                    ListViewItem lvi = this.CreateAuthorizationAttributeListViewItem(keyValueTaAdd);
                    this.lsvAttributes.Items.Add(lvi);
                    lvi.Selected  = true;
                    this.modified = true;
                }
                else
                {
                    if (keyValueToRemove.Key == null)
                    {
                        this.ShowError(Globalization.MultilanguageResource.GetString("frmApplicationAttributes_Msg10"), Globalization.MultilanguageResource.GetString("frmApplicationAttributes_Tit10"));
                        return;
                    }
                    else
                    {
                        this.ShowError(Globalization.MultilanguageResource.GetString("frmApplicationAttributes_Msg20"), Globalization.MultilanguageResource.GetString("frmApplicationAttributes_Tit20"));
                        return;
                    }
                }
                this.modified         = true;
                this.btnApply.Enabled = true;
                this.lsvAttributes.Focus();
            }
            this.HourGlass(false);
        }
Exemplo n.º 11
0
 private ListViewItem CreateStoreAttributeListViewItem(IAzManAttribute<IAzManStore> Attribute)
 {
     ListViewItem lvi = new ListViewItem();
     lvi.Tag = Attribute;
     lvi.ImageIndex = 0;
     lvi.Text = Attribute.Key;
     lvi.SubItems.Add(Attribute.Value);
     return lvi;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Adds an IAzManAttribute publisher.
 /// </summary>
 /// <param name="publisher">The publisher.</param>
 internal void AddPublisher(IAzManAttribute<IAzManItem> publisher)
 {
     publisher.AttributeDeleted += new AttributeDeletedDelegate<IAzManItem>(delegate(IAzManItem owner, string key) { if (this.ItemAttributeDeleted != null) this.ItemAttributeDeleted(owner, key); });
     publisher.AttributeUpdated += new AttributeUpdatedDelegate<IAzManItem>(delegate(IAzManAttribute<IAzManItem> attribute, string oldKey, string oldValue) { if (this.ItemAttributeUpdated != null) this.ItemAttributeUpdated(attribute, oldKey, oldValue); });
 }
Exemplo n.º 13
0
 void SqlAzManENS_StoreAttributeCreated(IAzManStore owner, IAzManAttribute<IAzManStore> attributeCreated)
 {
     logging.WriteInfo(this, String.Format("ENS Event: {0}\r\n\r\nStore: {1}\r\nStore Attribute Created: {2}\r\n", "StoreAttributeCreated", owner.ToString(), attributeCreated.ToString()));
 }
Exemplo n.º 14
0
 void SqlAzManENS_StoreAttributeUpdated(IAzManAttribute<IAzManStore> attribute, string oldKey, string oldValue)
 {
     logging.WriteInfo(this, String.Format("ENS Event: {0}\r\n\r\nStore Attribute: {1}\r\nOld Key: {2}\r\nOld Value: {3}\r\n", "StoreAttributeUpdated", attribute.ToString(), oldKey, oldValue));
 }
Exemplo n.º 15
0
        /// <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
        }
 private IAzManAttribute<IAzManAuthorization> FindAttribute(IAzManAttribute<IAzManAuthorization>[] attributes, string key)
 {
     foreach (IAzManAttribute<IAzManAuthorization> a in attributes)
     {
         if (a.Key == key)
             return a;
     }
     return null;
 }
Exemplo n.º 17
0
 private void raiseItemAttributeCreated(IAzManItem owner, IAzManAttribute<IAzManItem> attributeCreated)
 {
     if (this.ItemAttributeCreated != null)
         this.ItemAttributeCreated(owner, attributeCreated);
 }
Exemplo n.º 18
0
 void SqlAzManENS_ItemAttributeCreated(IAzManItem owner, IAzManAttribute<IAzManItem> attributeCreated)
 {
     logging.WriteInfo(this, String.Format("ENS Event: {0}\r\n\r\nItem: {1}\r\nItem Attribute Created: {2}\r\n", "ItemAttributeCreated", owner.ToString(), attributeCreated.ToString()));
 }
Exemplo n.º 19
0
 private IAzManAttribute<IAzManStore> FindAttribute(IAzManAttribute<IAzManStore>[] attributes, string key)
 {
     foreach (IAzManAttribute<IAzManStore> a in attributes)
     {
         if (a.Key == key)
             return a;
     }
     return null;
 }
Exemplo n.º 20
0
 private void raiseApplicationAttributeCreated(IAzManApplication owner, IAzManAttribute<IAzManApplication> attributeCreated)
 {
     if (this.ApplicationAttributeCreated != null)
         this.ApplicationAttributeCreated(owner, attributeCreated);
 }
Exemplo n.º 21
0
 void SqlAzManENS_AuthorizationAttributeCreated(IAzManAuthorization owner, IAzManAttribute<IAzManAuthorization> attributeCreated)
 {
     logging.WriteInfo(this, String.Format("ENS Event: {0}\r\n\r\nAuthorization: {1}\r\nAuthorization Attribute Created: {2}\r\n", "AuthorizationAttributeCreated", owner.ToString(), attributeCreated.ToString()));
 }