Esempio n. 1
0
        private void btn_rmRole_Save_Click(object sender, EventArgs e)
        {
            Program.ExitCode status;

            if (MessageBox.Show(this,
                            "Удалить роль?",
                            "Warning",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Warning) == DialogResult.No)
            {
                return;
            }

            //удалить роль после подтверждения:
            Role r = new Role
            {
                Id = Convert.ToInt32(cb_Name.SelectedValue),
                Name = cb_Name.Text,
                Cardinality = Convert.ToInt32(tb_Cardinality.Text),
                Policy_Id = Convert.ToInt32(cb_Policy.SelectedValue)
            };

            status = RBACManager.RmRole(r, mainForm.db);

            if (status == Program.ExitCode.Success)
            {
                MessageBox.Show(this,
                            "Роль удалена!",
                            "Success",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                this.Close();
                return;
            }
            if (status == Program.ExitCode.Error)
            {
                MessageBox.Show(this,
                            "Error while submitting deletion to the DataBase",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                return;
            }
        }
Esempio n. 2
0
 partial void InsertRole(Role instance);
Esempio n. 3
0
		private void detach_Role(Role entity)
		{
			this.SendPropertyChanging();
			entity.Policy = null;
		}
Esempio n. 4
0
		private void attach_Role(Role entity)
		{
			this.SendPropertyChanging();
			entity.Policy = this;
		}
Esempio n. 5
0
        private void btn_addRole_Save_Click(object sender, EventArgs e)
        {
            int i;
            Program.ExitCode status;

            if (tb_Name.Text != "" && tb_Cardinality.Text != "")
            {
                if (cb_Policy.Text != "")
                {
                    //Check Cardinality to be a number:
                    if (!Int32.TryParse(tb_Cardinality.Text, out i) || Convert.ToInt32(tb_Cardinality.Text) < -1){
                        MessageBox.Show(this,
                                        "Cardinality должно быть целым числом >= -1!\n'-1' обозн. бесконечность.",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }

                    Role r = new Role
                    {
                        Name = tb_Name.Text,
                        Cardinality = Convert.ToInt32(tb_Cardinality.Text),
                        Policy_Id = Convert.ToInt32(cb_Policy.SelectedValue)
                    };

                    status = RBACManager.AddRole(r, mainForm.db);
                    if (status == Program.ExitCode.Error)
                    {
                        MessageBox.Show(this,
                                            "Error while Submiting results in the DataBase!",
                                            "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        return;
                    }
                    if (status == Program.ExitCode.Success)
                    {
                        MessageBox.Show(this,
                                        "Роль добавлена!",
                                        "Success",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                        this.Close();
                        return;
                    }
                    if (status == Program.ExitCode.ElementExists)
                    {
                        if (MessageBox.Show(this,
                                    "Роль с такими 'Name' и 'Cardinality' уже существует!\nОбновить данные для этой роли?",
                                    "Warning",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            status = RBACManager.UpdateRole(r, mainForm.db);
                            if (status == Program.ExitCode.Error)
                            {
                                MessageBox.Show(this,
                                            "Error while Submiting results in the DataBase!",
                                            "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                                return;
                            }
                            if (status == Program.ExitCode.Success)
                            {
                                MessageBox.Show(this,
                                            "Данные для роли обновлены!",
                                            "Success",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                                this.Close();
                                return;
                            }
                        }
                        //MsgBox."NO" pressed => Ignore changes, return to add-Form
                        else
                        {
                            return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show(this,
                    "Выберите политику 'Policy'!",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(this,
                    "Вы не заполнили одно из полей 'Name' или 'Cardinality'!",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
Esempio n. 6
0
 private static void XMLWriteRH(Role role, XmlWriter xmlWriter)
 {
     // Create an entity only if a role has RH
     // Here Role1 <-> SeniorRole
     //      Role  <-> JuniorRole
     if (role.RoleHierarchy1.Count != 0)
     {
         xmlWriter.WriteStartElement("SeniorRole");
         xmlWriter.WriteAttributeString("name", role.Name);
         foreach (RoleHierarchy rh in role.RoleHierarchy1)
         {
             xmlWriter.WriteStartElement("JuniorRole");
             xmlWriter.WriteAttributeString("name", rh.Role.Name);
             xmlWriter.WriteEndElement();
         }
         xmlWriter.WriteEndElement();
     }
 }
Esempio n. 7
0
 public static Program.ExitCode UpdateRole(Role r, rbacLINQ2SQLDataContext db)
 {
     var query = from role in db.Role
                 where role.Name == r.Name && role.Policy_Id == r.Policy_Id
                 select role;
     query.First().Cardinality = r.Cardinality;
     try
     {
         db.SubmitChanges();
         return Program.ExitCode.Success;
     }
     catch (Exception exc)
     {
         return Program.ExitCode.Error;
     }
 }
Esempio n. 8
0
 public static void AddRole_noTryCatch(Role r, rbacLINQ2SQLDataContext db)
 {
     //check if the role exists
     var query = from role in db.Role
                 where role.Name == r.Name && role.Policy_Id == r.Policy_Id
                 select role;
     //if does not exist, add:
     if (query.Count() == 0)
     {
         db.Role.InsertOnSubmit(r);
         db.SubmitChanges();
         System.Diagnostics.Debug.WriteLine("Added Role: {0}", r.Name);
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Existing Role: {0}", r.Name);
     }
 }
Esempio n. 9
0
        // StaticSOD and DynamicSOD are not fully implemented
        // (with paying no attention to Role Hierarchy relations)
        public static Program.ExitCode AddStaticSOD(Role r1, Role r2, rbacLINQ2SQLDataContext db)
        {
            // Check if roles exist
            var role1 = from r in db.Role
                        where r.Name == r1.Name && r.Policy_Id == r1.Policy_Id
                        select r;
            var role2 = from r in db.Role
                        where r.Name == r2.Name && r.Policy_Id == r2.Policy_Id
                        select r;
            if (role1.Count() == 1 || role2.Count() == 1)
            {
                StaticSOD ssod1 = new StaticSOD()
                {
                    Role_Id = role1.First().Id,
                    ExclusiveRole_Id = role2.First().Id,
                };

                StaticSOD ssod2 = new StaticSOD()
                {
                    Role_Id = role2.First().Id,
                    ExclusiveRole_Id = role1.First().Id,
                };

                // Check if SSOD exists:
                var query1 = from t in db.StaticSOD
                             where t.Role_Id == ssod1.Role_Id && t.ExclusiveRole_Id == ssod1.ExclusiveRole_Id
                             select t;
                var query2 = from t in db.StaticSOD
                             where t.Role_Id == ssod2.Role_Id && t.ExclusiveRole_Id == ssod2.ExclusiveRole_Id
                             select t;
                if (query1.Count() == 1 && query2.Count() == 1)
                {
                    return Program.ExitCode.ElementExists;
                }
                try
                {
                    if (query1.Count() != 1)
                        db.StaticSOD.InsertOnSubmit(ssod1);
                    if (query2.Count() != 1)
                        db.StaticSOD.InsertOnSubmit(ssod2);
                    db.SubmitChanges();
                    return Program.ExitCode.Success;
                }
                catch
                {
                    return Program.ExitCode.Error;
                }
            }
            else
            {
                return Program.ExitCode.ElementDoesNotExists;
            }
        }
Esempio n. 10
0
        public static Program.ExitCode AddRH(Role senior, Role junior, rbacLINQ2SQLDataContext db)
        {
            // Check if roles exist
            var roleS = from r in db.Role
                        where r.Name == senior.Name && r.Policy_Id == senior.Policy_Id
                        select r;
            var roleJ = from r in db.Role
                        where r.Name == junior.Name && r.Policy_Id == junior.Policy_Id
                        select r;
            if (roleS.Count() == 1 && roleJ.Count() == 1)
            {
                RoleHierarchy rh = new RoleHierarchy()
                {
                    SeniorRole_Id = roleS.First().Id,
                    JuniorRole_Id = roleJ.First().Id,
                };

                // Check if RH exists:
                var query = from t in db.RoleHierarchy
                            where  t.SeniorRole_Id == rh.SeniorRole_Id
                                && t.JuniorRole_Id == rh.JuniorRole_Id
                            select t;
                if (query.Count() == 1)
                {
                    return Program.ExitCode.ElementExists;
                }
                try
                {
                    db.RoleHierarchy.InsertOnSubmit(rh);
                    db.SubmitChanges();
                    return Program.ExitCode.Success;
                }
                catch
                {
                    return Program.ExitCode.Error;
                }
            }
            else
            {
                return Program.ExitCode.ElementDoesNotExists;
            }
        }
Esempio n. 11
0
 public static Program.ExitCode AddRole(Role r, rbacLINQ2SQLDataContext db)
 {
     //check if the role exists
     var query = from role in db.Role
                 where role.Name == r.Name && role.Policy_Id == r.Policy_Id
                 select role;
     //if does not exist, add:
     if (query.Count() == 0)
     {
         db.Role.InsertOnSubmit(r);
         try
         {
             db.SubmitChanges();
             return Program.ExitCode.Success;
         }
         catch (Exception exc)
         {
             return Program.ExitCode.Error;
         }
     }
     //if exists, Ignore or Update:
     else
     {
         return Program.ExitCode.ElementExists;
     }
 }
Esempio n. 12
0
 private static void XMLWriteSSOD(Role role, XmlWriter xmlWriter)
 {
     // Create an entity only if a role has SSOD
     if (role.StaticSOD.Count != 0)
     {
         xmlWriter.WriteStartElement("Role");
         xmlWriter.WriteAttributeString("name", role.Name);
         foreach (StaticSOD ssod in role.StaticSOD)
         {
             xmlWriter.WriteStartElement("Exclusive_Role");
             xmlWriter.WriteAttributeString("name", ssod.Role1.Name);
             xmlWriter.WriteEndElement();
         }
         xmlWriter.WriteEndElement();
     }
 }
Esempio n. 13
0
 private static void XMLWriteRolePermissions(Role role, XmlWriter xmlWriter)
 {
     xmlWriter.WriteStartElement("Permissions");
     foreach (RolePermission rp in role.RolePermission)
     {
         xmlWriter.WriteStartElement("Permission");
         xmlWriter.WriteAttributeString("name", rp.Permission.Name);
         xmlWriter.WriteEndElement();
     }
     xmlWriter.WriteEndElement();
 }
Esempio n. 14
0
 private static void XMLWriteRole(Role role, XmlWriter xmlWriter)
 {
     xmlWriter.WriteStartElement("Role");
         xmlWriter.WriteAttributeString("name", role.Name);
         xmlWriter.WriteAttributeString("cardinality", role.Cardinality.ToString());
         XMLWriteRolePermissions(role, xmlWriter);
     xmlWriter.WriteEndElement();
 }
Esempio n. 15
0
 partial void UpdateRole(Role instance);
Esempio n. 16
0
        public static Program.ExitCode RmRole(Role r, rbacLINQ2SQLDataContext db, bool submitChanges = true)
        {
            try
            {
                Role role = db.Role.Single(r1 => (r1.Id == r.Id &&
                                                  r1.Policy_Id == r.Policy_Id));
                //Можем запрещать удалять Роли, которые привязаны к каким-то Юзерам
                //if (role.AuthUserRole.Count != 0)
                //{
                //    return Program.ExitCode.HasAssigned;
                //}

                //здесь не удаляется роль из SSOD, DSOD, RH
                db.ActiveRole.DeleteAllOnSubmit(role.ActiveRole);
                db.AuthUserRole.DeleteAllOnSubmit(role.AuthUserRole);
                db.RolePermission.DeleteAllOnSubmit(role.RolePermission);
                db.Role.DeleteOnSubmit(role);

                if (submitChanges)
                    db.SubmitChanges();

                return Program.ExitCode.Success;
            }
            catch (Exception exc)
            {
                return Program.ExitCode.Error;
            }
        }
Esempio n. 17
0
 partial void DeleteRole(Role instance);
Esempio n. 18
0
        private static bool XMLReadRole(XmlNode roleNode, int pid, rbacLINQ2SQLDataContext db)
        {
            Role role;
            Permission perm;
            RolePermission rp;

            int cardinality = 0;
            if (!Int32.TryParse(roleNode.Attributes["cardinality"].Value, out cardinality))
            {
                return false;
            };
            role = new Role()
            {
                Name = roleNode.Attributes["name"].Value,
                Cardinality = cardinality,
                Policy_Id = pid,
            };
            RBACManager.AddRole_noTryCatch(role, db);
            // Depending on our specification we could have to update an existing role
            //RBACManager.UpdateRole(role,db);

            // Get this role (just added to the database or existed in it
            role = db.Role.Single(x => x.Name == role.Name && x.Policy_Id == role.Policy_Id);

            // If there's no single Permissions block, error:
            if (roleNode.ChildNodes.Count != 1)
            {
                return false;
            }
            XmlNode permBlock = roleNode.ChildNodes.Item(0);
            foreach (XmlNode permNode in permBlock.ChildNodes)
            {
                perm = db.Permission.Single(x => x.Name == permNode.Attributes["name"].Value
                                                    && x.Policy_Id == pid);
                rp = new RolePermission()
                {
                    Permission_Id = perm.Id,
                    Role_Id = role.Id
                };
                RBACManager.AddRolePermission_noTryCatch(rp, db);
            }

            return true;
        }