Пример #1
0
        private void btn_addPolicy_Save_Click(object sender, EventArgs e)
        {
            Program.ExitCode status;

            if (tb_Name.Text != "")
            {
                Policy p = new Policy
                {
                    Name = tb_Name.Text,
                };

                status = RBACManager.AddPolicy(p, 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)
                {
                    MessageBox.Show(this,
                                    "Такая политика уже существует!",
                                    "Warning",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    return;
                }
            }
            else
            {
                MessageBox.Show(this,
                            "Вы не заполнили поле 'Policy Name'!",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                return;
            }
        }
Пример #2
0
        private void btn_rmPolicy_Save_Click(object sender, EventArgs e)
        {
            Program.ExitCode status;

            if (MessageBox.Show(this,
                            "Удалить политику?\nУдаляются также все связанные с ней объекты (User, Role, Permission...)",
                            "Warning",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Warning) == DialogResult.No)
            {
                return;
            }

            //удалить политику после подтверждения:
            Policy p = new Policy
            {
                Id = Convert.ToInt32(cb_Policy.SelectedValue),
            };

            status = RBACManager.RmPolicy(p, 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;
            }
        }
Пример #3
0
 partial void DeletePolicy(Policy instance);
Пример #4
0
 partial void UpdatePolicy(Policy instance);
Пример #5
0
 partial void InsertPolicy(Policy instance);
Пример #6
0
        public static Program.ExitCode RmPolicy(Policy policy_in, rbacLINQ2SQLDataContext db)
        {
            Program.ExitCode status;

            //check if the policy exists
            var query = from policy in db.Policy
                        where policy.Id == policy_in.Id
                        select policy;
            //if does exist, remove:
            if (query.Count() != 0)
            {
                Policy p = query.First();

                foreach (User u in p.User)
                {
                    status = RmUser(u, db, false);
                    if (status != Program.ExitCode.Success)
                        return status;
                }
                foreach (Role r in p.Role)
                {
                    status = RmRole(r, db, false);
                    if (status != Program.ExitCode.Success)
                        return status;
                }
                foreach (Permission perm in p.Permission)
                {
                    status = RmPermission(perm, db, false);
                    if (status != Program.ExitCode.Success)
                        return status;
                }
                db.Policy.DeleteOnSubmit(p);
                try
                {
                    db.SubmitChanges();
                    return Program.ExitCode.Success;
                }
                catch (Exception exc)
                {
                    return Program.ExitCode.Error;
                }
            }
            //if doesn't exist:
            else
            {
                return Program.ExitCode.ElementDoesNotExists;
            }
        }
Пример #7
0
 public static void AddPolicy_noTryCatch(Policy p, rbacLINQ2SQLDataContext db)
 {
     //check if the role exists
     var query = from policy in db.Policy
                 where policy.Name == p.Name
                 select policy;
     //if does not exist, add:
     if (query.Count() == 0)
     {
         db.Policy.InsertOnSubmit(p);
         db.SubmitChanges();
         System.Diagnostics.Debug.WriteLine("Added Policy: {0}", p.Name);
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Existing Policy: {0}", p.Name);
     }
 }
Пример #8
0
 public static Program.ExitCode AddPolicy(Policy p, rbacLINQ2SQLDataContext db)
 {
     //check if the role exists
     var query = from policy in db.Policy
                 where policy.Name == p.Name
                 select policy;
     //if does not exist, add:
     if (query.Count() == 0)
     {
         db.Policy.InsertOnSubmit(p);
         try
         {
             db.SubmitChanges();
             return Program.ExitCode.Success;
         }
         catch (Exception exc)
         {
             return Program.ExitCode.Error;
         }
     }
     //if exists, Ignore or Update:
     else
     {
         return Program.ExitCode.ElementExists;
     }
 }
Пример #9
0
        private static void XMLWritePolicy(Policy policy, XmlWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("Policy");
            // Policy details
            xmlWriter.WriteAttributeString("name", policy.Name);
            // User block
            XMLWriteUserBlock(policy.User, xmlWriter);
            // Role block
            XMLWriteRoleBlock(policy.Role, xmlWriter);
            // Permission block
            XMLWritePermissionBlock(policy.Permission, xmlWriter);

            // not implemented in DataBase, but prepared for future here:
            // SSoD block
            XMLWriteSSODBlock(policy.Role, xmlWriter);
            // DSoD block
            XMLWriteDSODBlock(policy.Role, xmlWriter);
            // Role Hierarchy block
            XMLWriteRHBlock(policy.Role, xmlWriter);

            xmlWriter.WriteEndElement();
        }
Пример #10
0
        private static bool XMLReadPolicyNode(XmlNode policyNode, rbacLINQ2SQLDataContext db)
        {
            Policy policy = new Policy()
            {
                Name = policyNode.Attributes["name"].Value
            };
            RBACManager.AddPolicy_noTryCatch(policy, db);

            // Indices for node blocks:
            int iUSERS, iROLES, iPERMISSIONS, iSSOD, iDSOD, iROLEHIERARCHY;
            iUSERS = -1; iROLES = -1; iPERMISSIONS = -1; iSSOD = -1; iDSOD = -1; iROLEHIERARCHY = -1;
            int i = -1;
            foreach (XmlNode node in policyNode.ChildNodes)
            {
                i++;
                switch (node.Name)
                {
                    case "USERS":
                        iUSERS = i;
                        break;
                    case "ROLES":
                        iROLES = i;
                        break;
                    case "PERMISSIONS":
                        iPERMISSIONS = i;
                        break;
                    case "SSOD":
                        iSSOD = i;
                        break;
                    case "DSOD":
                        iDSOD = i;
                        break;
                    case "RoleHierarchy":
                        iROLEHIERARCHY = i;
                        break;
                }
            }
            // if there is a policy, it MUST have ALL inner blocks USER, ROLE, etc.
            if (iUSERS == -1 || iROLES == -1 || iPERMISSIONS == -1 ||
                iSSOD == -1 || iDSOD == -1 || iROLEHIERARCHY == -1 ||
                i > 5)// the last i>5 is for guarantee only one section for each of USER, ROLE,.. blocks
            {
                return false;
            }

            // Get policy_ID of the inserted [or existed, ofc] policy
            int policy_id = db.Policy.Single(x => x.Name == policy.Name).Id;
            // Order of operators below is IMPORTANT to guarantee correctness of DataBase filling
            XMLReadPermissionBlock(policyNode.ChildNodes.Item(iPERMISSIONS), policy_id, db);
            XMLReadRoleBlock(policyNode.ChildNodes.Item(iROLES), policy_id, db);
            XMLReadUserBlock(policyNode.ChildNodes.Item(iUSERS), policy_id, db);

            // Implemented "as is". Without paying attention to RH relation within SODs
            //XMLReadSSODBlock(policyNode.ChildNodes.Item(iSSOD), policy_id, db);
            //XMLReadDSODBlock(policyNode.ChildNodes.Item(iDSOD), policy_id, db);
            //XMLReadRHBlock(policyNode.ChildNodes.Item(iROLEHIERARCHY), policy_id, db);

            return true;
        }