Ejemplo n.º 1
0
        private void BuildAuthRoleTree(XmlElement current_element, Dictionary <string, AuthRole> roles, string current_name)
        {
            AuthRole current_role = roles[current_name];

            foreach (XmlElement child_element in current_element.ChildNodes)
            {
                if (child_element.Name.Equals("AuthItems"))
                {
                    foreach (XmlElement child_element2 in child_element.ChildNodes)
                    {
                        if (child_element2.Name.Equals("AuthItem"))
                        {
                            string   authitem_name = child_element2.Attributes["ItemName"].Value.ToString();
                            AuthItem item          = RepositoryMgr.AuthItemMgr.FindById(authitem_name);
                            if (item != null)
                            {
                                current_role.ForbiddenItems.Add(item);
                            }
                        }
                    }
                }
                else if (child_element.Name.Equals("Children"))
                {
                    foreach (XmlElement child_element2 in child_element.ChildNodes)
                    {
                        if (child_element2.Name.Equals("AuthRole"))
                        {
                            string child_role_name = child_element2.Attributes["RoleName"].Value.ToString();
                            current_role.Children.Add(roles[child_role_name]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public bool CheckAccess(string action)
        {
            AuthItem item = RepositoryMgr.AuthItemMgr.FindById(action);

            if (item == null)
            {
                return(true);
            }
            return(CheckAccess(item));
        }
Ejemplo n.º 3
0
 public bool ForbidItem(AuthItem _item)
 {
     foreach (AuthItem item in ForbiddenItems)
     {
         if (item.Equals(_item))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
 public override bool Equals(object obj)
 {
     if (obj is AuthItem)
     {
         AuthItem _obj = obj as AuthItem;
         if (_obj.ItemName.Equals(ItemName))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        public bool CheckAccess(AuthItem item_to_chk)
        {
            if (FullControl.Equals("1"))
            {
                return(true);
            }

            foreach (AuthRole child_role in Children)
            {
                if (child_role.CheckAccess(item_to_chk))
                {
                    return(true);
                }
            }

            foreach (AuthItem item in ForbiddenItems)
            {
                if (item.Equals(item_to_chk))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
        protected override object GetDbProperty(AuthRole _obj, string property_name)
        {
            if (property_name.Equals("Children"))
            {
                List <int>        child_role_ids = new List <int>();
                DbSelectStatement clause         = DbMgr.CreateSelectClause();
                clause
                .SelectColumn("AuthRoleRole", "ChildRoleID")
                .From("AuthRoleRole")
                .Criteria
                .IsEqual("AuthRoleRole", "ParentRoleID", _obj.RoleID);

                DbCommand    cmd     = DbMgr.CreateDbCommand(clause);
                DbDataReader _reader = cmd.ExecuteReader();
                while (_reader.Read())
                {
                    int?child_role_id = GetInt32(_reader, "ChildRoleID");
                    if (child_role_id != null)
                    {
                        child_role_ids.Add(child_role_id.Value);
                    }
                }
                _reader.Close();
                cmd.Dispose();

                List <AuthRole> child_roles = new List <AuthRole>();
                foreach (int child_role_id in child_role_ids)
                {
                    AuthRole child_role = RepositoryMgr.AuthRoleMgr.FindByRoleID(child_role_id);
                    if (child_role != null)
                    {
                        child_roles.Add(child_role);
                    }
                }
                return(child_roles);
            }
            else if (property_name.Equals("Items"))
            {
                List <int>        item_ids = new List <int>();
                DbSelectStatement clause   = DbMgr.CreateSelectClause();
                clause
                .SelectColumn("AuthRoleItem", "ItemID")
                .From("AuthRoleItem")
                .Criteria
                .IsEqual("AuthRoleItem", "RoleID", _obj.RoleID);

                DbCommand    cmd     = DbMgr.CreateDbCommand(clause);
                DbDataReader _reader = cmd.ExecuteReader();
                while (_reader.Read())
                {
                    int?item_id = GetInt32(_reader, "ItemID");
                    if (item_id != null)
                    {
                        item_ids.Add(item_id.Value);
                    }
                }
                _reader.Close();
                cmd.Dispose();

                List <AuthItem> items = new List <AuthItem>();
                foreach (int item_id in item_ids)
                {
                    AuthItem item = RepositoryMgr.AuthItemMgr.FindById(item_id);
                    if (item != null)
                    {
                        items.Add(item);
                    }
                }
                return(items);
            }
            return(null);
        }