コード例 #1
0
ファイル: Access_auth.cs プロジェクト: wangweinjcn/msgp
 public BlockControllers addNew(string roleid)
 {
     if (blocks.Keys.Contains(roleid, StringComparer.CurrentCultureIgnoreCase))
     {
         return(blocks[roleid]);
     }
     else
     {
         BlockControllers obj = new BlockControllers();
         blocks.Add(roleid, obj);
         return(obj);
     }
 }
コード例 #2
0
ファイル: Access_auth.cs プロジェクト: wangweinjcn/msgp
        public bool IsAllowed(string roleidlist, string str_controller, string str_action,
                              string httpmethod, string jsonParam, string areacode = "-1", bool isdevice = false)
        {
            string prefix = null;

            if (isdevice)
            {
                prefix = devicePrefix;
            }
            else
            {
                prefix = userPrefix;
            }
            string areakey = prefix + areacode;

            var roleBlockControllers = Access_ht.getRoleBlockControllers(areakey);

            if (roleBlockControllers == null)
            {
                return(false);
            }
            string[] rolelist = roleidlist.Split(',');
            foreach (string str_roleid in rolelist)
            {
                if (string.IsNullOrEmpty(str_roleid))
                {
                    continue;
                }
                if (roleBlockControllers.containRoleid(str_roleid))
                {
                    BlockControllers objcontrollerht = roleBlockControllers.GetBlockControllers(str_roleid);
                    if (objcontrollerht.contain(str_controller, str_action, httpmethod, jsonParam))
                    {
                        return(true);
                    }
                }
            }
            return(this._defaultallow);
        }
コード例 #3
0
ファイル: Access_auth.cs プロジェクト: wangweinjcn/msgp
        public bool AnonymousAllowed(string controllername, string actionname,
                                     string httpmethod, string jsonParam, string areacode = "-1", bool isdevice = false)
        {
            string prefix = null;

            if (isdevice)
            {
                prefix = devicePrefix;
            }
            else
            {
                prefix = userPrefix;
            }
            string areakey = prefix + areacode;

            var roleBlockControllers = Access_ht.getRoleBlockControllers(areakey);

            if (roleBlockControllers == null)
            {
                return(_defaultallow);
            }
            BlockControllers objcontrollerht = null;

            if (roleBlockControllers.containRoleid("*"))
            {
                objcontrollerht = roleBlockControllers.GetBlockControllers("*");
            }
            if (objcontrollerht != null && objcontrollerht.contain(controllername, actionname, httpmethod))
            {
                return(true);
            }
            else
            {
                return(this._defaultallow);
            }
        }
コード例 #4
0
ファイル: Access_auth.cs プロジェクト: wangweinjcn/msgp
        private void processOneBlockCotrollers(XmlNodeList alllist, string areaPrefix)
        {
            string xpathstr2 = "./authitem";
            string xpathstr3 = "./Access";
            roleBlockControllers roleBControllers;

            foreach (XmlNode node in alllist)
            {
                string areaKey = xmlTools.GetXmlAttr(node, "key").ToLower();
                if (string.IsNullOrEmpty(areaKey))
                {
                    areaKey = "-1";
                }
                areaKey          = areaPrefix + areaKey;
                roleBControllers = Access_ht.addNew(areaKey);
                var alllist2 = xmlTools.SelectXmlNodes(node, xpathstr2);
                //processOneBlockCotrollers(roleBControllers, alllist2);

                foreach (XmlNode x in alllist2)
                {
                    string strRoleIdList = xmlTools.GetXmlAttr(x, "roleid").ToLower();
                    if (string.IsNullOrEmpty(strRoleIdList))
                    {
                        continue;
                    }
                    string str_controller = xmlTools.GetXmlAttr(x, "controller").ToLower();
                    if (string.IsNullOrEmpty(str_controller))
                    {
                        continue;
                    }
                    string      str_action = xmlTools.GetXmlAttr(x, "action").ToLower();
                    string      httpmethod = xmlTools.GetXmlAttr(x, "http").ToLower();
                    XmlNodeList paramlist  = x.SelectNodes("param");
                    if (string.IsNullOrEmpty(str_action))
                    {
                        str_action = "*";
                    }

                    var allroleid = strRoleIdList.Split(',');
                    foreach (var strRoleId in allroleid)
                    {
                        action_info currActionInfo = null;
                        if (roleBControllers.containRoleid(strRoleId))
                        {
                            BlockControllers obj = roleBControllers.GetBlockControllers(strRoleId);
                            if (obj.contain(str_controller, str_action, httpmethod))
                            {
                                continue;
                            }
                            else
                            {
                                currActionInfo = obj.add(str_controller, str_action, httpmethod);
                            }
                        }
                        else
                        {
                            BlockControllers obj = roleBControllers.addNew(strRoleId);
                            currActionInfo = obj.add(str_controller, str_action, httpmethod);
                        }
                        foreach (XmlNode paramNode in paramlist)
                        {
                            currActionInfo.addparm(xmlTools.GetXmlAttr(paramNode, "name"), xmlTools.GetXmlAttr(paramNode, "value"));
                        }
                    }
                }
                var    ipacccessNode = xmlTools.SelectXmlNode(node, xpathstr3);
                string accessmode    = xmlTools.GetXmlAttr(ipacccessNode, "Model").ToLower();
                if (string.IsNullOrEmpty(accessmode))
                {
                    continue;
                }
                roleBControllers.setAccessModel(string.Equals("black", accessmode));
                var alllist3 = xmlTools.SelectXmlNodes(ipacccessNode, "./ip");
                foreach (XmlNode ipnode in alllist3)
                {
                    roleBControllers.addIP(ipnode.Value);
                }
            }
        }