public static int RefreshCache(string userId)
        {
            int result = 0;

            // 刷新用户的缓存
            BaseUserEntity userEntity = BaseUserManager.GetObjectByCache(userId, true);

            if (userEntity != null)
            {
                // 刷新用户的登录限制
                BaseUserManager.ResetIPAddressByCache(userId);
                BaseUserManager.ResetMACAddressByCache(userId);
                // 刷新组织机构缓存
                BaseOrganizeManager.GetObjectByCache(userEntity.CompanyId, true);
                // 刷新部门缓存
                BaseDepartmentManager.GetObjectByCache(userEntity.DepartmentId, true);
                // 2016-02-18 吉日嘎拉 刷新拒绝权限(把用户的权限放在一起方便直接移除、刷新)
                string key = "User:IsAuthorized:" + userId;
                using (var redisClient = PooledRedisHelper.GetPermissionClient())
                {
                    redisClient.Remove(key);
                }
                // 每个子系统都可以循环一次
                string[] systemCodes = BaseSystemManager.GetSystemCodes();
                for (int i = 0; i < systemCodes.Length; i++)
                {
                    BaseUserPermissionManager.ResetPermissionByCache(systemCodes[i], userId);
                }
            }

            return(result);
        }
        /// <summary>
        /// 缓存预热,强制重新缓存
        /// </summary>
        /// <returns>影响行数</returns>
        public static int CachePreheating()
        {
            int result = 0;

            // 把所有的组织机构都缓存起来的代码
            BaseOrganizeManager manager = new BaseOrganizeManager();

            using (IDataReader dataReader = manager.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    BaseOrganizeEntity entity = BaseEntity.Create <BaseOrganizeEntity>(dataReader, false);
                    if (entity != null)
                    {
                        BaseOrganizeManager.SetCache(entity);
                        string[] systemCodes = BaseSystemManager.GetSystemCodes();
                        for (int i = 0; i < systemCodes.Length; i++)
                        {
                            // 重置权限缓存数据
                            BaseOrganizePermissionManager.ResetPermissionByCache(systemCodes[i], entity.Id);
                        }
                        result++;
                        System.Console.WriteLine(result.ToString() + " : " + entity.FullName);
                    }
                }
                dataReader.Close();
            }

            return(result);
        }
        /// <summary>
        /// 缓存预热,强制重新缓存
        /// </summary>
        /// <returns></returns>
        public static int CachePreheating()
        {
            int result = 0;

            string[] systemCodes = BaseSystemManager.GetSystemCodes();
            for (int i = 0; i < systemCodes.Length; i++)
            {
                GetEntitiesByCache(systemCodes[i], true);
                result += CachePreheating(systemCodes[i]);
            }

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 缓存预热,强制重新缓存
        /// </summary>
        /// <returns></returns>
        public static int CachePreheating()
        {
            var result = 0;

            var systemCodes = BaseSystemManager.GetSystemCodes();

            foreach (var entity in systemCodes)
            {
                GetEntitiesByCache(entity.ItemKey, true);
                result += CachePreheating(entity.ItemKey);
            }

            return(result);
        }
Exemple #5
0
        public static int RefreshCache(string organizeId)
        {
            int result = 0;

            // 2016-02-29 吉日嘎拉 强制刷新缓存
            BaseOrganizeEntity organizeEntity = BaseOrganizeManager.GetObjectByCache(organizeId, true);

            if (organizeEntity != null)
            {
                string[] systemCodes = BaseSystemManager.GetSystemCodes();
                for (int i = 0; i < systemCodes.Length; i++)
                {
                    BaseOrganizePermissionManager.ResetPermissionByCache(systemCodes[i], organizeId);
                }
            }

            return(result);
        }
Exemple #6
0
        /// <summary>
        /// 刷新缓存
        /// </summary>
        /// <param name="systemCode"></param>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public static int RefreshCache(string systemCode, string roleId)
        {
            var result = 0;

            // 2016-02-29 吉日嘎拉 强制刷新缓存
            var roleEntity = GetEntityByCache(systemCode, roleId, true);

            if (roleEntity != null)
            {
                var systemCodes = BaseSystemManager.GetSystemCodes();
                foreach (var entity in systemCodes)
                {
                    GetEntitiesByCache(entity.ItemKey, true);
                    result += CachePreheating(entity.ItemKey);
                }
            }

            return(result);
        }
Exemple #7
0
        /// <summary>
        /// 刷新缓存
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static int RefreshCache(string userId)
        {
            var result = 0;

            // 刷新用户的缓存
            var userEntity = GetEntityByCache(userId, true);

            if (userEntity != null)
            {
                // 刷新用户的登录限制 用户名的限制

                // 刷新用户的登录限制
                ResetIpAddressByCache(userId);
                ResetMacAddressByCache(userId);
                // 刷新组织机构缓存
                BaseOrganizationManager.GetEntityByCache(userEntity.CompanyId.ToString(), true);
                // 2016-02-18 吉日嘎拉 刷新拒绝权限(把用户的权限放在一起方便直接移除、刷新)
                var key = "User:IsAuthorized:" + userId;
                CacheUtil.Remove(key);

                // 2016-05-24 吉日嘎拉 解除登录限制的方法,防止一天都登录不上的问题发生
                //if (!string.IsNullOrEmpty(userEntity.NickName))
                //{
                //    key = "u:" + userEntity.NickName;
                //    PooledRedisHelper.CallLimitRemove(key);
                //}
                //if (!string.IsNullOrEmpty(userEntity.Code))
                //{
                //    key = "u:" + userEntity.Code;
                //    PooledRedisHelper.CallLimitRemove(key);
                //}

                // 每个子系统都可以循环一次
                var systemCodes = BaseSystemManager.GetSystemCodes();
                foreach (var entity in systemCodes)
                {
                    BasePermissionManager.ResetPermissionByCache(entity.ItemKey, userId, null);
                }
            }

            return(result);
        }
        /// <summary>
        /// 参数检查
        /// </summary>
        /// <param name="context">当前请求上下文</param>
        /// <param name="userInfo">用户信息</param>
        /// <param name="checkLocalIp">检查内网</param>
        /// <param name="permissionCode">权限菜单的Code</param>
        /// <returns></returns>
        public static BaseResult ValidateParameter(HttpContext context, ref BaseUserInfo userInfo, bool checkLocalIp = true, string permissionCode = null)
        {
            var result = new BaseResult();

            // 1:是否是有效的系统编号?
            if (context.Request["systemCode"] == null)
            {
                result.Status        = false;
                result.StatusCode    = Status.ParameterError.ToString();
                result.StatusMessage = "systemCode " + Status.ParameterError.ToDescription();
                return(result);
            }

            var systemCode = context.Request["systemCode"];

            if (!BaseSystemManager.CheckSystemCode(systemCode))
            {
                result.Status        = false;
                result.StatusCode    = Status.ParameterError.ToString();
                result.StatusMessage = "systemCode 不是有效的系统编号";
                return(result);
            }

            var ipAddress = Utils.GetIp();

            // 2016-08-22 已经正常登录的用户,也可以调用验证码函数,这样接口程序更灵活一些,更方便被调用
            if (context.Request["userInfo"] != null)
            {
                // 从当前使用的用户确定当前使用者
                userInfo = BaseUserInfo.Deserialize(context.Request["userInfo"]);
                if (userInfo == null)
                {
                    result.Status        = false;
                    result.StatusCode    = Status.Error.ToString();
                    result.StatusMessage = "userInfo " + Status.Error.ToDescription();
                    return(result);
                }

                // 防止伪造、判断用户的有效性
                if (!ServiceUtil.VerifySignature(userInfo))
                {
                    // LogUtil.WriteLine("userInfo.Signature:" + userInfo.Signature + " GetSignature(userInfo):" + ServiceUtil.GetSignature(userInfo));
                    result.Status        = false;
                    result.StatusCode    = Status.SignatureError.ToString();
                    result.StatusMessage = "userInfo " + Status.SignatureError.ToDescription();
                    return(result);
                }

                // 这里需要是已经登录的用户,不是已经被踢掉的用户
                if (!ValidateOpenId(userInfo.Id, userInfo.OpenId))
                {
                    result.Status        = false;
                    result.StatusCode    = Status.ParameterError.ToString();
                    result.StatusMessage = "OpenId " + Status.ParameterError.ToDescription();
                    return(result);
                }
            }
            else
            {
                // 2016-08-09 吉日嘎拉,必须保证是服务器调用的,外部不允许直接调用,方式被短信轰炸,有安全漏洞。
                // 检查是否为内部ip地址发送出去的手机短信
                // 2016-08-09 宋彪 不仅仅针对短信发送,用户中心接口也要考虑
                if (checkLocalIp)
                {
                    if (!IpUtil.IsLocalIp(ipAddress))
                    {
                        // 不是内网发出的, 也不是信任的ip列表里的,直接给拒绝发送出去
                        result.Status        = false;
                        result.StatusCode    = Status.ErrorIpAddress.ToString();
                        result.StatusMessage = ipAddress + " " + Status.ErrorIpAddress.ToDescription();
                        return(result);
                    }
                }

                // 应用唯一标识
                string appKey;
                if (context.Request["appKey"] == null)
                {
                    result.Status        = false;
                    result.StatusCode    = Status.ParameterError.ToString();
                    result.StatusMessage = "appKey " + Status.ParameterError.ToDescription();
                    return(result);
                }
                else
                {
                    appKey = context.Request["appKey"];
                }

                // 应用的签名密钥
                string appSecret;
                if (context.Request["appSecret"] == null)
                {
                    result.Status        = false;
                    result.StatusCode    = Status.ParameterError.ToString();
                    result.StatusMessage = "appSecret " + Status.ParameterError.ToDescription();
                    return(result);
                }
                else
                {
                    appSecret = context.Request["appSecret"];
                }

                // 检查服务的有效性,是否调用限制到了?是否有相应的权限
                //result = BaseServicesLicenseManager.CheckService(appKey, appSecret, false, 0, 0, systemCode, permissionCode);
                //if (!result.Status)
                //{
                //    return result;
                //}

                // 从接口确定当前调用者
                var userEntity = BaseUserManager.GetEntityByCodeByCache(appKey);
                if (userEntity != null)
                {
                    userInfo = new BaseUserInfo
                    {
                        Id          = userEntity.Id.ToString(),
                        UserId      = userEntity.Id,
                        Code        = userEntity.Code,
                        UserName    = userEntity.UserName,
                        NickName    = userEntity.NickName,
                        RealName    = userEntity.RealName,
                        CompanyId   = userEntity.CompanyId.ToString(),
                        CompanyCode = userEntity.CompanyCode,
                        CompanyName = userEntity.CompanyName,
                        IpAddress   = ipAddress
                    };
                }
            }

            result.Status = true;
            return(result);
        }