Ejemplo n.º 1
0
        // GET: Manager/AccessDefinition/Edit/5
        public ActionResult Edit(int?id)
        {
            AccessDefinitionsViewModel adVM   = new AccessDefinitionsViewModel();
            CFAccessDefinition         access = new CFAccessDefinition();

            if (id != null)
            {
                CFAccessDefinition accessDef = AccessDefinitionService.GetAccessDefinitionById(id.Value);

                adVM = UpdateAccessDefinitionViewModel(accessDef, adVM);
            }
            else
            {
                //get all available AccessMode enum
                int i = 0;
                foreach (AccessMode am in Enum.GetValues(typeof(AccessMode)))
                {
                    if (i > 0) //skip the first one -- None
                    {
                        adVM.AccessModes.Add(new AccessCheckBox {
                            Text = am.ToString(), Value = ((int)am)
                        });
                    }
                    i++;
                }
            }

            return(View(adVM));
        }
Ejemplo n.º 2
0
        private List <AccessCheckBox> PopulateAccessModesView(CFAccessDefinition accessDef)
        {
            List <AccessCheckBox> AccessModes = new List <AccessCheckBox>();
            int i = 0;

            foreach (AccessMode am in Enum.GetValues(typeof(AccessMode)))
            {
                if (i > 0) //skip the first one -- None
                {
                    if (accessDef.HasMode(am))
                    {
                        AccessModes.Add(new AccessCheckBox {
                            Text = am.ToString(), Value = ((int)am), Checked = true
                        });
                    }
                    else
                    {
                        AccessModes.Add(new AccessCheckBox {
                            Text = am.ToString(), Value = ((int)am)
                        });
                    }
                }
                i++;
            }
            return(AccessModes);
        }
Ejemplo n.º 3
0
        public CFAccessDefinition UpdateAccessDefinition(AccessDefinitionsViewModel accessDefVM, string[] selectedModes)
        {
            CFAccessDefinition accessDef = new CFAccessDefinition();

            if (accessDefVM.Id != null)
            {
                accessDef = AccessDefinitionService.GetAccessDefinitionById(accessDefVM.Id.Value);

                foreach (string am in selectedModes.ToList())
                {
                    AccessMode selectedMode = (AccessMode)Enum.Parse(typeof(AccessMode), am);
                    accessDef.AccessModes |= selectedMode;
                }
            }
            else
            {
                foreach (string am in selectedModes.ToList())
                {
                    AccessMode selectedMode = (AccessMode)Enum.Parse(typeof(AccessMode), am);
                    accessDef.AccessModes |= selectedMode;
                }
            }
            accessDef.Name = accessDefVM.Name;
            return(accessDef);
        }
Ejemplo n.º 4
0
        public AccessDefinitionsViewModel UpdateAccessDefinitionViewModel(CFAccessDefinition accessDef, AccessDefinitionsViewModel adVM)
        {
            adVM.Name = accessDef.Name;
            //  List<AccessMode> selectedModes = accessDef.AccessModesList;

            adVM.AccessModes = PopulateAccessModesView(accessDef);
            return(adVM);
        }
Ejemplo n.º 5
0
        public void TestDenyInheritanceFlag()
        {
            SecurityServiceBase srv = new TestSecurityService(Db);

            string itemName       = "TestUserIsAdminItem";
            string itemDesciption = "Test item description";


            AccessMode defaultAccess = GetDefaultPermissions();

            CFAccessDefinition ad1 = new CFAccessDefinition()
            {
                Name        = "Test 1",
                AccessModes = AccessMode.Read | AccessMode.Write
            };

            CFAccessDefinition ad2 = new CFAccessDefinition()
            {
                Name        = "Test 2",
                AccessModes = AccessMode.Control | AccessMode.Append
            };

            int    entityType = mDh.Ets.GetEntityTypes(CFEntityType.eTarget.Items).FirstOrDefault().Id;
            CFItem i1         = mDh.CreateItem(mDh.Is, entityType, itemName, itemDesciption, true);

            List <CFAccessGroup> groups = new List <CFAccessGroup>()
            {
                new CFAccessGroup()
                {
                    AccessGuids = new List <Guid>()
                    {
                        Guid.Parse(Groups[0])
                    }, AccessDefinition = ad1
                },
                new CFAccessGroup()
                {
                    AccessGuids = new List <Guid>()
                    {
                        Guid.Parse(Users[1].Guid)
                    }, AccessDefinition = ad2
                }
            };

            i1.AccessGroups     = groups;
            i1.BlockInheritance = true;
            i1.Serialize();
            Db.SaveChanges();

            AccessMode modes1 = srv.GetPermissions(Users[0].Guid, i1);
            AccessMode modes2 = srv.GetPermissions(Users[1].Guid, i1);
            AccessMode modes3 = srv.GetPermissions(Users[2].Guid, i1);
            AccessMode modes4 = srv.GetPermissions(Users[3].Guid, i1);

            Assert.AreEqual(ad1.AccessModes, modes1);
            Assert.AreEqual(ad1.AccessModes | ad2.AccessModes, modes2);
            Assert.AreEqual(AccessMode.None, modes3);
            Assert.AreEqual(AccessMode.None, modes4);
        }
Ejemplo n.º 6
0
        public CFAccessDefinition EditAccessDefinition(CFAccessDefinition accessDefinition)
        {
            if (accessDefinition.Id > 0)
            {
                //edit
                Db.Entry(accessDefinition).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                //add new
                Db.AccessDefinitions.Add(accessDefinition);
            }

            return(accessDefinition);
        }
Ejemplo n.º 7
0
        public void DeleteAccessDefinition(int id)
        {
            CFAccessDefinition model = null;

            if (id > 0)
            {
                model = Db.AccessDefinitions.Where(et => et.Id == id).FirstOrDefault();
                if (model != null)
                {
                    Db.Entry(model).State = System.Data.Entity.EntityState.Deleted;
                }
                else
                {
                    throw new ArgumentException(string.Format("Access Definitions {0} not found.", id));
                }
            }
            else
            {
                throw new ArgumentException(string.Format("Invalid Access Definitions id {0}.", id));
            }
        }
Ejemplo n.º 8
0
        public ActionResult Edit(AccessDefinitionsViewModel accessDefVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    CFAccessDefinition accessDefinition = new CFAccessDefinition();
                    string[]           selectedModes    = Request.Form["SelectedAccessModes"].Split(',');
                    accessDefinition = UpdateAccessDefinition(accessDefVM, selectedModes);
                    accessDefinition = AccessDefinitionService.EditAccessDefinition(accessDefinition);
                    accessDefinition.Serialize();
                    Db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //return View();
        }
Ejemplo n.º 9
0
        public void TestCircularParents()
        {
            SecurityServiceBase srv = new TestSecurityService(Db);

            string collectionName       = "TestUserIsAdminCollection";
            string collectionDesciption = "Test collection description";
            string itemName             = "TestUserIsAdminItem";
            string itemDesciption       = "Test item description";

            AccessMode defaultAccess = GetDefaultPermissions();

            CFAccessDefinition ad1 = new CFAccessDefinition()
            {
                Name        = "Test 1",
                AccessModes = AccessMode.Write
            };

            CFAccessDefinition ad2 = new CFAccessDefinition()
            {
                Name        = "Test 2",
                AccessModes = AccessMode.Control | AccessMode.Append
            };

            CFAccessDefinition ad3 = new CFAccessDefinition()
            {
                Name        = "Test 3",
                AccessModes = AccessMode.Discover
            };

            int    entityType = mDh.Ets.GetEntityTypes(CFEntityType.eTarget.Items).FirstOrDefault().Id;
            CFItem i1         = mDh.CreateItem(mDh.Is, entityType, itemName, itemDesciption, true);

            entityType = mDh.Ets.GetEntityTypes(CFEntityType.eTarget.Collections).FirstOrDefault().Id;
            CFCollection c1 = mDh.CreateCollection(mDh.Cs, entityType, collectionName, collectionDesciption, true);

            entityType = mDh.Ets.GetEntityTypes(CFEntityType.eTarget.Items).FirstOrDefault().Id;
            CFItem i2 = mDh.CreateItem(mDh.Is, entityType, itemName, itemDesciption, true);

            List <CFAccessGroup> groups = new List <CFAccessGroup>()
            {
                new CFAccessGroup()
                {
                    AccessGuids = new List <Guid>()
                    {
                        Guid.Parse(Groups[0])
                    }, AccessDefinition = ad1
                },
            };

            c1.AccessGroups = groups;
            c1.Serialize();

            groups = new List <CFAccessGroup>()
            {
                new CFAccessGroup()
                {
                    AccessGuids = new List <Guid>()
                    {
                        Guid.Parse(Groups[1])
                    }, AccessDefinition = ad2
                },
                new CFAccessGroup()
                {
                    AccessGuids = new List <Guid>()
                    {
                        Guid.Parse(Groups[2])
                    }, AccessDefinition = ad3
                }
            };

            i2.AccessGroups = groups;
            i2.Serialize();

            i1.Serialize();

            c1.ChildMembers.Add(i1);
            c1.ChildMembers.Add(i2); //NOTE: Here is our circular relationship
            i2.ChildMembers.Add(i1);
            Db.SaveChanges();

            AccessMode modes1 = srv.GetPermissions(Users[0].Guid, i1);
            AccessMode modes2 = srv.GetPermissions(Users[1].Guid, i1);
            AccessMode modes3 = srv.GetPermissions(Users[2].Guid, i1);
            AccessMode modes4 = srv.GetPermissions(Users[3].Guid, i1);

            Assert.AreEqual(defaultAccess | ad1.AccessModes | ad3.AccessModes, modes1);
            Assert.AreEqual(defaultAccess | ad1.AccessModes | ad2.AccessModes, modes2);
            Assert.AreEqual(defaultAccess | ad2.AccessModes, modes3);
            Assert.AreEqual(defaultAccess | ad2.AccessModes | ad3.AccessModes, modes4);

            modes1 = srv.GetPermissions(Users[0].Guid, i2);
            modes2 = srv.GetPermissions(Users[1].Guid, i2);
            modes3 = srv.GetPermissions(Users[2].Guid, i2);
            modes4 = srv.GetPermissions(Users[3].Guid, i2);

            Assert.AreEqual(defaultAccess | ad1.AccessModes | ad3.AccessModes, modes1);
            Assert.AreEqual(defaultAccess | ad1.AccessModes | ad2.AccessModes, modes2);
            Assert.AreEqual(defaultAccess | ad2.AccessModes, modes3);
            Assert.AreEqual(defaultAccess | ad2.AccessModes | ad3.AccessModes, modes4);

            modes1 = srv.GetPermissions(Users[0].Guid, c1);
            modes2 = srv.GetPermissions(Users[1].Guid, c1);
            modes3 = srv.GetPermissions(Users[2].Guid, c1);
            modes4 = srv.GetPermissions(Users[3].Guid, c1);

            Assert.AreEqual(defaultAccess | ad1.AccessModes, modes1);
            Assert.AreEqual(defaultAccess | ad1.AccessModes, modes2);
            Assert.AreEqual(defaultAccess, modes3);
            Assert.AreEqual(defaultAccess, modes4);
        }
Ejemplo n.º 10
0
 public void Initialize()
 {
     AccessDefinition = new CFAccessDefinition();
 }
 protected override void OnSetup()
 {
     AccessDefinition = new CFAccessDefinition();
 }