Ejemplo n.º 1
0
        /// <summary>
        /// IP地址过滤
        /// </summary>
        /// <returns></returns>
        public bool FilterIP()
        {
            //缓存key
            string black_cacheKey = "blackIPList_" + OperatorProvider.Provider.Current().UserId;
            //缓存key
            string white_cacheKey = "whiteIPList_" + OperatorProvider.Provider.Current().UserId;
            //取得用户对象关系Id
            string objectId = OperatorProvider.Provider.Current().ObjectId;
            //取得当前角色的黑名单IP段
            IEnumerable <FilterIPEntity> blackIPList = null;
            var black_cacheList = CacheFactory.Cache().GetCache <IEnumerable <FilterIPEntity> >(black_cacheKey);

            if (black_cacheList == null)
            {
                blackIPList = InstanceDAL.GetAllList(objectId, 0);
                CacheFactory.Cache().WriteCache(blackIPList, black_cacheKey, DateTime.Now.AddMinutes(1));
            }
            else
            {
                blackIPList = black_cacheList;
            }
            bool isBlack = false;

            //如果有设置黑名单就进行黑名单判断
            if (blackIPList.Count() > 0)
            {
                isBlack = CheckArea(blackIPList);
            }
            //当前IP在黑名单中直接拒绝
            if (isBlack)
            {
                return(false);
            }

            //当前角色的白名单IP段
            IEnumerable <FilterIPEntity> whiteIPList = null;
            var white_cacheList = CacheFactory.Cache().GetCache <IEnumerable <FilterIPEntity> >(white_cacheKey);

            if (white_cacheList == null)
            {
                whiteIPList = InstanceDAL.GetAllList(objectId, 1);
                CacheFactory.Cache().WriteCache(whiteIPList, black_cacheKey, DateTime.Now.AddMinutes(1));
            }
            else
            {
                whiteIPList = white_cacheList;
            }
            bool isWhite = true;

            if (whiteIPList.Count() > 0)
            {
                isWhite = CheckArea(whiteIPList);
            }
            //如果有设置白名单,但是当前用户IP不在白名单中直接拒绝
            if (!isWhite)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 角色列表all
 /// </summary>
 /// <returns></returns>
 public List <RoleEntity> GetAllList()
 {
     return(InstanceDAL.GetAllList().ToList());
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 过滤IP列表
 /// </summary>
 /// <param name="objectId">对象Id,用逗号分隔</param>
 /// <param name="visitType">访问:0-拒绝,1-允许</param>
 /// <returns></returns>
 public IEnumerable <FilterIPEntity> GetAllList(string objectId, int visitType)
 {
     return(InstanceDAL.GetAllList(objectId, visitType));
 }