Ejemplo n.º 1
0
        private void loadPermissionCats()
        {
            FileStream         fs = new FileStream(ConfigurationHelper.PermissionCategoryFile, FileMode.Open);
            BinaryReader       r  = new BinaryReader(fs);
            int                id;
            int                parentId;
            string             name;
            PermissionCategory cat;

            while (fs.Position < fs.Length)
            {
                id       = r.ReadInt32();
                parentId = r.ReadInt32();
                name     = r.ReadString();
                cat      = new PermissionCategory(id, parentId, name);
                cats.Add(id, cat);
                if (parentId == NO_PARENT)
                {
                    catArrays.Add(id, new ArrayList());
                    topCats.Add(cat);
                }
                else
                {
                    ArrayList catList = (ArrayList)catArrays[parentId];
                    catList.Add(cat);
                    permArrays.Add(id, new ArrayList());
                }
            }
            r.Close();
            fs.Close();
        }
Ejemplo n.º 2
0
 private void rptTopCats_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
     {
         cc.PermissionCategory cat       = (cc.PermissionCategory)e.Item.DataItem;
         HyperLink             lnkTopCat = (HyperLink)e.Item.FindControl("lnkTopCat");
         lnkTopCat.Text        = cat.Name;
         lnkTopCat.NavigateUrl = "rolePermissions.aspx?RoleId=" + roleId + "&CatId=" + cat.Id;
         if (cat.Id == catId)
         {
             lnkTopCat.Style.Add("font-weight", "bold");
         }
     }
 }
Ejemplo n.º 3
0
        private void BindData()
        {
            arrExistingPermIds    = roleData.GetPermissions(roleId); //must reload
            rptTopCats.DataSource = permissionData.TopCategories;
            rptTopCats.DataBind();

            if (catId > 0)
            {
                d.Role role = new d.Role(roleId);
                cc.PermissionCategory cat = permissionData.GetCategory(catId);
                pnlPermissions.Visible  = true;
                ltrPermissionTitle.Text = "Select <b>" + cat.Name + "</b> permissions for the <b>" + role.Name + "</b> role:";
                rptCats.DataSource      = permissionData.GetCategories(catId);
                rptCats.DataBind();
            }
            else
            {
                pnlPermissions.Visible = false;
            }
        }
Ejemplo n.º 4
0
        private void rptCats_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
            {
                cc.PermissionCategory cat = (cc.PermissionCategory)e.Item.DataItem;
                Label lblCat = (Label)e.Item.FindControl("lblCat");
                lblCat.Text = cat.Name;
                ArrayList      arrPerms = permissionData.GetPermissions(cat.Id);
                Panel          pnlPerms = (Panel)e.Item.FindControl("pnlPerms");
                LiteralControl ltrNone  = new LiteralControl();
                pnlPerms.Controls.Add(ltrNone);
                string selected = "";
                bool   exists   = false;

                foreach (cc.Permission perm in arrPerms)
                {
                    if (arrExistingPermIds.Contains(perm.Id))
                    {
                        selected = "checked";
                        exists   = true;
                    }
                    else
                    {
                        selected = "";
                    }

                    string radio = "<input type='radio' name='radPerm_" + cat.Id + "' value='" + perm.Id + "' " + selected + ">";
                    pnlPerms.Controls.Add(new LiteralControl(radio + perm.Name + "<br>"));
                }
                if (!exists)
                {
                    selected = "checked";
                }

                ltrNone.Text = "<input type='radio' name='radPerm_" + cat.Id + "' value='0' " + selected + ">none<br>";
            }
        }
Ejemplo n.º 5
0
        private void loadPermissions()
        {
            FileStream   fs = File.OpenRead(ConfigurationHelper.PermissionSourceFile);
            StreamReader r  = new StreamReader(fs, System.Text.Encoding.ASCII);

            string patternCat  = @"\s*(?<id>c\d+)\s+(?<parentid>c-?\d+)\s+""(?<name>[^""]+)""";
            string patternPerm = @"\s*(?<id>\d+)\s+(?<parentid>c\d+)\s+(?<type>(and)|(or))\s+""(?<name>[^""]+)""\s+""(?<code>\w+)""";

            Regex regexPerm = new Regex(patternPerm, RegexOptions.IgnoreCase | RegexOptions.Compiled);
            Regex regexCat  = new Regex(patternCat, RegexOptions.IgnoreCase | RegexOptions.Compiled);

            MatchCollection mc;

            string line;
            int    id;
            int    parentId;
            string type;
            string name;
            string code;

            cc.Permission         perm;
            cc.PermissionCategory cat;
            cc.PermissionCategory parentCat;
            int counter = 0;

            while ((line = r.ReadLine()) != null)
            {
                counter++;
                if (line != "" && !line.StartsWith("//"))
                {
                    if (line.StartsWith("c"))
                    {
                        mc = regexCat.Matches(line);
                        if (mc.Count != 1)
                        {
                            throw new Exception("Invalid format in permissions file -- line " + counter);
                        }

                        id       = Convert.ToInt32(mc[0].Groups["id"].ToString().Substring(1));
                        parentId = Convert.ToInt32(mc[0].Groups["parentid"].ToString().Substring(1));
                        name     = mc[0].Groups["name"].ToString();

                        if (parentId != cc.PermissionData.NO_PARENT)
                        {
                            if (!catsHash.ContainsKey(parentId))
                            {
                                throw new Exception("Nonexistant category as parentId -- line " + counter);
                            }

                            parentCat = (cc.PermissionCategory)catsHash[parentId];
                            if (parentCat.ParentId != cc.PermissionData.NO_PARENT)
                            {
                                throw new Exception("A category's parent must be a first-level category -- line " + counter);
                            }
                        }
                        cat = new cc.PermissionCategory(id, parentId, name);
                        catsHash.Add(id, cat);
                        orderedCats.Add(cat);
                    }
                    else
                    {
                        mc = regexPerm.Matches(line);
                        if (mc.Count != 1)
                        {
                            throw new Exception("Invalid format in permissions file -- line " + counter);
                        }

                        id       = Convert.ToInt32(mc[0].Groups["id"].ToString());
                        parentId = Convert.ToInt32(mc[0].Groups["parentid"].ToString().Substring(1));
                        type     = mc[0].Groups["type"].ToString();
                        name     = mc[0].Groups["name"].ToString();
                        code     = mc[0].Groups["code"].ToString();

                        if (!catsHash.ContainsKey(parentId))
                        {
                            throw new Exception("Nonexistant category as parentId -- line " + counter);
                        }

                        parentCat = (cc.PermissionCategory)catsHash[parentId];
                        if (parentCat.ParentId == cc.PermissionData.NO_PARENT)
                        {
                            throw new Exception("A permission's parent must be a second-level category -- line " + counter);
                        }

                        perm = new cc.Permission(id, parentId, type, name, code);
                        permsHash.Add(id, perm);
                        orderedPerms.Add(perm);
                    }
                }
            }
            r.Close();
            fs.Close();
        }