Exemple #1
0
        /// <summary>
        /// 某个角色是否有相应的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleId">角色主键</param>
        /// <param name="permissionItemCode">权限编号</param>
        /// <returns>是否有权限</returns>
        public bool IsAuthorizedByRole(BaseUserInfo userInfo, string roleId, string permissionItemCode)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            bool returnValue = false;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    // 是超级管理员,就不用继续判断权限了
                    returnValue = roleId.Equals("Administrators");
                    if (returnValue)
                    {
                        return(returnValue);
                    }
                    BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo);
                    returnValue = permissionManager.CheckPermissionByRole(roleId, permissionItemCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_IsAuthorizedByRole, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(returnValue);
        }
Exemple #2
0
        /// <summary>
        /// 某个角色是否有相应的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleId">角色主键</param>
        /// <param name="permissionCode">权限编号</param>
        /// <returns>是否有权限</returns>
        public bool CheckPermissionByRole(BaseUserInfo userInfo, string roleId, string permissionCode)
        {
            bool result = false;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // 是超级管理员,就不用继续判断权限了
                result = roleId.Equals("Administrators");
                if (!result)
                {
                    var manager = new BasePermissionManager(dbHelper, userInfo);
                    result      = manager.CheckPermissionByRole(userInfo.SystemCode, roleId, permissionCode);
                }
            });

            return(result);
        }