示例#1
0
        public int Add(string moduleId, string permissionItemId)
        {
            int returnValue = 0;

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseModuleEntity.TableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, moduleId));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionItemId, permissionItemId));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldDeletionStateCode, 0));

            // 检查记录是否重复
            if (!this.Exists(parameters))
            {
                BasePermissionEntity permissionEntity = new BasePermissionEntity();
                permissionEntity.ResourceId        = moduleId;
                permissionEntity.ResourceCategory  = BaseModuleEntity.TableName;
                permissionEntity.Enabled           = 1;
                permissionEntity.DeletionStateCode = 0;
                permissionEntity.PermissionId      = int.Parse(permissionItemId);
                BasePermissionManager permissionManager = new BasePermissionManager(this.DbHelper, this.UserInfo, this.CurrentTableName);
                permissionManager.AddEntity(permissionEntity);
                returnValue++;
            }
            return(returnValue);
        }
        /// <summary>
        /// 多个角色,都有啥权限?单个角色都有啥权限的循环获取?
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="roleIds">角色主键数组</param>
        /// <returns>权限数组</returns>
        public static string[] GetPermissionIdsByCache(string systemCode, string[] roleIds)
        {
            string[] result = null;

            var key    = string.Empty;
            var roleId = string.Empty;

            string[] permissionIds = null;

            key = "Permission:" + systemCode + ":Role:" + roleId;
            var hs = new HashSet <string>();

            result = CacheUtil.Cache(key, () =>
            {
                for (var i = 0; i < roleIds.Length; i++)
                {
                    permissionIds = new BasePermissionManager().GetPermissionIds(systemCode, roleIds[i], "Role");
                    foreach (var permissionId in permissionIds)
                    {
                        hs.Add(permissionId);
                    }
                }

                return(hs.ToArray());
            }, true);

            return(result);
        }
示例#3
0
        /// <summary>
        /// 授予资源的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="resourceCategory">资源分类</param>
        /// <param name="resourceId">资源主键</param>
        /// <param name="grantPermissionIds">权限主键</param>
        /// <returns>影响的行数</returns>
        public int GrantResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceId, string[] grantPermissionIds)
        {
            var result = 0;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseRoleScopeManager(dbHelper, userInfo);
                // 小心异常,检查一下参数的有效性
                if (grantPermissionIds != null)
                {
                    var permissionManager = new BasePermissionManager(dbHelper, userInfo);
                    for (var i = 0; i < grantPermissionIds.Length; i++)
                    {
                        var resourcePermissionEntity = new BasePermissionEntity
                        {
                            ResourceCategory = resourceCategory,
                            ResourceId       = resourceId,
                            PermissionId     = grantPermissionIds[i],
                            Enabled          = 1,
                            Deleted          = 0
                        };
                        permissionManager.Add(resourcePermissionEntity);
                        result++;
                    }
                }
            });
            return(result);
        }
示例#4
0
        /// <summary>
        /// 缓存预热,强制重新缓存
        /// 2016-02-26 每个角色的权限也进行缓存起来
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <returns>影响行数</returns>
        public static int CachePreheating(string systemCode)
        {
            var result = 0;

            // 把所有的组织机构都缓存起来的代码
            var manager = new BaseRoleManager
            {
                CurrentTableName = systemCode + "Role"
            };
            var dataReader = manager.ExecuteReader();

            if (dataReader != null && !dataReader.IsClosed)
            {
                while (dataReader.Read())
                {
                    var entity = BaseEntity.Create <BaseRoleEntity>(dataReader, false);
                    if (entity != null)
                    {
                        // 设置角色本身的缓存
                        SetCache(systemCode, entity);
                        // 重置权限缓存数据
                        BasePermissionManager.ResetPermissionByCache(systemCode, null, entity.Id.ToString());
                        result++;
                        System.Console.WriteLine(result + " : " + entity.Name);
                    }
                }

                dataReader.Close();
            }

            return(result);
        }
示例#5
0
        /// <summary>
        /// 某个用户是否有相应的操作权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionCode">权限编号</param>
        /// <param name="permissionName">权限名称</param>
        /// <returns>是否有权限</returns>
        public bool IsAuthorized(BaseUserInfo userInfo, string userId, string permissionCode, string permissionName = null)
        {
            bool result = false;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                if (string.IsNullOrEmpty(userId))
                {
                    userId = userInfo.Id;
                }
#if (!DEBUG)
                // 是超级管理员,就不用继续判断权限了
                // var userManager = new BaseUserManager(result);
                // result = userManager.IsAdministrator(userId);
#endif
                if (!result)
                {
                    var permissionManager = new BasePermissionManager(userInfo);
                    result = permissionManager.IsAuthorized(userInfo.SystemCode, userId, permissionCode, permissionName);
                    // BaseLogManager.Instance.Add(result, this.serviceName, AppMessage.PermissionService_IsAuthorized, MethodBase.GetCurrentMethod());
                }
            });

            return(result);
        }
示例#6
0
        //
        //  撤销权限的实现部分
        //

        #region private int Revoke(BasePermissionManager permissionManager, string systemCode, string organizeId, string result) 为了提高撤销的运行速度
        /// <summary>
        /// 为了提高撤销的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <param name="result">权限主键</param>
        /// <returns>影响行数</returns>
        private int Revoke(BasePermissionManager permissionManager, string systemCode, string organizeId, string permissionId)
        {
            int result = 0;

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseOrganizeEntity.TableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, organizeId));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionId, permissionId));
            result = permissionManager.Delete(parameters);

            // 2015-09-21 吉日嘎拉 这里增加变更日志
            string     tableName  = systemCode + ".Permission.Organize";
            SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper);

            sqlBuilder.BeginInsert(BaseModifyRecordEntity.TableName);
            sqlBuilder.SetValue(BaseModifyRecordEntity.FieldTableCode, tableName);
            sqlBuilder.SetFormula(BaseModifyRecordEntity.FieldId, "SEQ_" + BaseModifyRecordEntity.TableName + ".NEXTVAL");
            sqlBuilder.SetValue(BaseModifyRecordEntity.FieldRecordKey, organizeId);
            sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnCode, permissionId);
            sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnDescription, BaseModuleManager.GetNameByCache(systemCode, permissionId));
            sqlBuilder.SetValue(BaseModifyRecordEntity.FieldOldValue, "1");
            sqlBuilder.SetValue(BaseModifyRecordEntity.FieldNewValue, "撤销授权");
            sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateUserId, this.UserInfo.Id);
            sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateBy, this.UserInfo.RealName);
            sqlBuilder.SetDBNow(BaseModifyRecordEntity.FieldCreateOn);
            sqlBuilder.SetValue(BaseModifyRecordEntity.FieldIPAddress, this.UserInfo.IPAddress);
            sqlBuilder.EndInsert();

            return(result);
        }
示例#7
0
        /// <summary>
        /// 撤消资源的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="resourceCategory">资源分类</param>
        /// <param name="resourceId">资源主键</param>
        /// <param name="revokePermissionIds">权限主键</param>
        /// <returns>影响的行数</returns>
        public int RevokeResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceId, string[] revokePermissionIds)
        {
            var result = 0;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // BaseRoleScopeManager manager = new BaseRoleScopeManager(dbHelper, result);
                // 小心异常,检查一下参数的有效性
                if (revokePermissionIds != null)
                {
                    var permissionManager = new BasePermissionManager(dbHelper, userInfo);
                    for (var i = 0; i < revokePermissionIds.Length; i++)
                    {
                        var parameters = new List <KeyValuePair <string, object> >
                        {
                            new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, resourceCategory),
                            new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, resourceId),
                            new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionId, revokePermissionIds[i])
                        };
                        // result += permissionManager.SetDeleted(parameters);
                        result += permissionManager.Delete(parameters);
                    }
                }
            });
            return(result);
        }
        public static bool IsAuthorizedByCache(string systemCode, string userId, string permissionCode)
        {
            bool result = false;

            using (var redisReadOnlyClient = PooledRedisHelper.GetPermissionReadOnlyClient())
            {
                // 2016-02-18 吉日嘎拉 这样可以刷新用户权限时,可以把一个用户的权限全去掉。
                string hashId = "User:IsAuthorized:" + userId;
                string key    = systemCode + ":" + permissionCode;
                // 若是缓存里过期了?
                if (redisReadOnlyClient.HashContainsEntry(hashId, key))
                {
                    string isAuthorized = redisReadOnlyClient.GetValueFromHash(hashId, key);
                    result = isAuthorized.Equals(true.ToString());
                }
                else
                {
                    BasePermissionManager permissionManager = new BasePermissionManager();
                    result = permissionManager.IsAuthorized(systemCode, userId, permissionCode);
#if ReadOnlyRedis
                    using (var redisClient = PooledRedisHelper.GetPermissionClient())
                    {
                        redisClient.SetEntryInHash(hashId, key, result.ToString());
                        redisClient.ExpireEntryAt(hashId, DateTime.Now.AddMinutes(20));
                    }
#else
                    redisReadOnlyClient.SetEntryInHash(hashId, key, result.ToString());
                    redisReadOnlyClient.ExpireEntryAt(hashId, DateTime.Now.AddMinutes(20));
#endif
                }
            }

            return(result);
        }
示例#9
0
        //
        //  撤销权限的实现部分
        //

        #region private int Revoke(BasePermissionManager permissionManager, string userId, string permissionItemId) 为了提高撤销的运行速度
        /// <summary>
        /// 为了提高撤销的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>影响行数</returns>
        private int Revoke(BasePermissionManager permissionManager, string userId, string permissionItemId)
        {
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseUserEntity.TableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, userId));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionItemId, permissionItemId));
            return(permissionManager.Delete(parameters));
        }
示例#10
0
        /// <summary>
        /// 撤销用户全部权限
        /// </summary>
        /// <param name="roleId">角色主键</param>
        /// <returns>影响行数</returns>
        public int RevokeAll(string userId)
        {
            BasePermissionManager permissionManager          = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseUserEntity.TableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, userId));
            return(permissionManager.Delete(parameters));
        }
示例#11
0
        /// <summary>
        /// 撤销角色全部权限
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="roleId">角色主键</param>
        /// <returns>影响行数</returns>
        public int RevokeAll(string systemCode, string roleId)
        {
            string tableName = systemCode + "Permission";
            BasePermissionManager permissionManager          = new BasePermissionManager(DbHelper, UserInfo, tableName);
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            tableName = systemCode + "Role";
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, tableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, roleId));
            return(permissionManager.Delete(parameters));
        }
        /// <summary>
        /// 授予资源的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="resourceCategory">资源分类</param>
        /// <param name="resourceId">资源主键</param>
        /// <param name="grantPermissionItemIds">权限主键</param>
        /// <returns>影响的行数</returns>
        public int GrantResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceId, string[] grantPermissionItemIds)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseRoleScopeManager roleScopeManager = new BaseRoleScopeManager(dbHelper, userInfo);
                    // 小心异常,检查一下参数的有效性
                    if (grantPermissionItemIds != null)
                    {
                        BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo);
                        for (int i = 0; i < grantPermissionItemIds.Length; i++)
                        {
                            BasePermissionEntity resourcePermissionEntity = new BasePermissionEntity();
                            resourcePermissionEntity.ResourceCategory  = resourceCategory;
                            resourcePermissionEntity.ResourceId        = resourceId;
                            resourcePermissionEntity.PermissionId      = int.Parse(grantPermissionItemIds[i]);
                            resourcePermissionEntity.Enabled           = 1;
                            resourcePermissionEntity.DeletionStateCode = 0;
                            permissionManager.Add(resourcePermissionEntity);
                            returnValue++;
                        }
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_GrantResourcePermission, 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);
        }
示例#13
0
        /// <summary>
        /// 某个用户是否有相应的操作权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionItemCode">权限编号</param>
        /// <param name="permissionItemName">权限名称</param>
        /// <returns>是否有权限</returns>
        public bool IsAuthorizedByUser(BaseUserInfo userInfo, string userId, string permissionItemCode, string permissionItemName = null)
        {
            // 写入调试信息
            #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);
                    if (string.IsNullOrEmpty(userId))
                    {
                        userId = userInfo.Id;
                    }
                    #if (!DEBUG)
                    // 是超级管理员,就不用继续判断权限了
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    returnValue = userManager.IsAdministrator(userId);
                    if (returnValue)
                    {
                        return(returnValue);
                    }
                    #endif

                    BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo);
                    returnValue = permissionManager.CheckPermissionByUser(userId, permissionItemCode, permissionItemName);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_IsAuthorizedByUser, 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);
        }
示例#14
0
        public int Revoke(string[] userIds, string permissionItemId)
        {
            int returnValue = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < userIds.Length; i++)
            {
                returnValue += this.Revoke(permissionManager, userIds[i], permissionItemId);
            }
            return(returnValue);
        }
示例#15
0
        public int Revoke(string systemCode, string[] organizeIds, string permissionId)
        {
            int result = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < organizeIds.Length; i++)
            {
                result += this.Revoke(permissionManager, systemCode, organizeIds[i], permissionId);
            }
            return(result);
        }
示例#16
0
        //
        // 授予权限的实现部分
        //

        #region private string Grant(BasePermissionManager permissionManager, string id, string userId, string permissionItemId) 为了提高授权的运行速度
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="Id">主键</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>主键</returns>
        private string Grant(BasePermissionManager permissionManager, string id, string userId, string permissionItemId)
        {
            string returnValue = string.Empty;
            BasePermissionEntity resourcePermissionEntity = new BasePermissionEntity();

            resourcePermissionEntity.ResourceCategory = BaseUserEntity.TableName;
            resourcePermissionEntity.ResourceId       = userId;
            resourcePermissionEntity.PermissionId     = int.Parse(permissionItemId);
            resourcePermissionEntity.Enabled          = 1;
            return(permissionManager.Add(resourcePermissionEntity));
        }
        public int Grant(string[] organizeIds, string permissionItemId)
        {
            int returnValue = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < organizeIds.Length; i++)
            {
                this.Grant(permissionManager, organizeIds[i], permissionItemId);
                returnValue++;
            }
            return(returnValue);
        }
示例#18
0
        public int Grant(string systemCode, string organizeId, string[] permissionIds)
        {
            int result = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < permissionIds.Length; i++)
            {
                this.Grant(permissionManager, systemCode, organizeId, permissionIds[i]);
                result++;
            }
            return(result);
        }
        //
        // 授予权限的实现部分
        //

        #region private string Grant(BasePermissionManager permissionManager, string id, string organizeId, string permissionItemId) 为了提高授权的运行速度
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="Id">主键</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>主键</returns>
        private string Grant(BasePermissionManager permissionManager, string organizeId, string permissionItemId)
        {
            string returnValue = string.Empty;
            BasePermissionEntity resourcePermission = new BasePermissionEntity();

            resourcePermission.ResourceCategory = BaseOrganizeEntity.TableName;
            resourcePermission.ResourceId       = organizeId;
            resourcePermission.PermissionId     = int.Parse(permissionItemId);
            // 防止不允许为NULL的错误发生
            resourcePermission.Enabled = 1;
            return(permissionManager.Add(resourcePermission));
        }
        /// <summary>
        /// 撤消资源的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="resourceCategory">资源分类</param>
        /// <param name="resourceId">资源主键</param>
        /// <param name="revokePermissionItemIds">权限主键</param>
        /// <returns>影响的行数</returns>
        public int RevokeResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceId, string[] revokePermissionItemIds)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    // BaseRoleScopeManager manager = new BaseRoleScopeManager(dbHelper, userInfo);
                    // 小心异常,检查一下参数的有效性
                    if (revokePermissionItemIds != null)
                    {
                        BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo);
                        for (int i = 0; i < revokePermissionItemIds.Length; i++)
                        {
                            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, resourceCategory));
                            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, resourceId));
                            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionItemId, revokePermissionItemIds[i]));
                            // returnValue += permissionManager.SetDeleted(parameters);
                            returnValue += permissionManager.Delete(parameters);
                        }
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_RevokeResourcePermission, 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);
        }
        /// <summary>
        /// 给用户权限(分子系统)
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="systemCode">系统编号</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionCode">权限编号</param>
        /// <returns>主键</returns>
        public string GrantUserPermission(BaseUserInfo userInfo, string systemCode, string userId, string permissionCode)
        {
            var result = string.Empty;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (ServiceUtil.ProcessFun)((dbHelper) =>
            {
                var userPermissionManager = new BasePermissionManager((IDbHelper)dbHelper, (BaseUserInfo)userInfo);
                result = userPermissionManager.GrantByPermissionCode(systemCode, userId, permissionCode);
            }));
            return(result);
        }
示例#22
0
        public int Delete(string moduleId, string permissionItemId)
        {
            int returnValue = 0;
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseModuleEntity.TableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, moduleId));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionItemId, permissionItemId));
            BasePermissionManager manager = new BasePermissionManager(this.DbHelper, this.UserInfo);

            returnValue = manager.Delete(parameters);
            return(returnValue);
        }
        /// <summary>
        /// 获取用户拥有的操作权限主键数组
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <returns>主键数组</returns>
        public string[] GetUserPermissionIds(BaseUserInfo userInfo, string userId)
        {
            string[] result = null;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (ServiceUtil.ProcessFun)((dbHelper) =>
            {
                var manager = new BasePermissionManager((IDbHelper)dbHelper, (BaseUserInfo)userInfo);
                result      = manager.GetPermissionIds(userInfo.SystemCode, userId);
            }));

            return(result);
        }
示例#24
0
        /// <summary>
        /// 获得某个用户的所有权限列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <param name="fromCache">是否从缓存读取</param>
        /// <returns>主键数组</returns>
        public string[] GetPermissionIds(BaseUserInfo userInfo, string systemCode, string userId, bool fromCache)
        {
            string[] result = null;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var permissionManager = new BasePermissionManager(dbHelper, userInfo);
                result = permissionManager.GetPermissionIdsByUser(systemCode, userId, string.Empty, true, fromCache);
            });

            return(result);
        }
示例#25
0
        /// <summary>
        /// 获得某个用户的所有权限列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <param name="companyId">公司主键</param>
        /// <param name="fromCache">是否从缓存读取</param>
        /// <returns>数据表</returns>
        public List <BaseModuleEntity> GetPermissionListByUser(BaseUserInfo userInfo, string systemCode, string userId, string companyId, bool fromCache)
        {
            List <BaseModuleEntity> result = new List <BaseModuleEntity>();

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var permissionManager = new BasePermissionManager(dbHelper, userInfo);
                result = permissionManager.GetPermissionListByUser(systemCode, userId, companyId, fromCache);
            });

            return(result);
        }
        public int Revoke(string[] organizeIds, string[] permissionItemIds)
        {
            int returnValue = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < organizeIds.Length; i++)
            {
                for (int j = 0; j < permissionItemIds.Length; j++)
                {
                    returnValue += this.Revoke(permissionManager, organizeIds[i], permissionItemIds[j]);
                }
            }
            return(returnValue);
        }
示例#27
0
        /// <summary>
        /// 获取角色权限主键数组
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleId">角色主键</param>
        /// <returns>主键数组</returns>
        public string[] GetRolePermissionIds(BaseUserInfo userInfo, string roleId)
        {
            string[] result = null;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BasePermissionManager(dbHelper, userInfo);
                result      = manager.GetPermissionIds(userInfo.SystemCode, roleId, "Role");
            });

            return(result);
        }
示例#28
0
        /// <summary>
        /// 获取角色主键数组
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="permissionId">操作权限主键</param>
        /// <returns>主键数组</returns>
        public string[] GetRoleIdsByPermission(BaseUserInfo userInfo, string permissionId)
        {
            string[] result = null;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BasePermissionManager(dbHelper, userInfo);
                result      = manager.GetRoleIds(userInfo.SystemCode, permissionId);
                // BaseLogManager.Instance.Add(result, this.serviceName, MethodBase.GetCurrentMethod());
            });

            return(result);
        }
        public int Grant(string[] roleIds, string[] permissionItemIds)
        {
            int returnValue = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < roleIds.Length; i++)
            {
                for (int j = 0; j < permissionItemIds.Length; j++)
                {
                    this.Grant(permissionManager, roleIds[i], permissionItemIds[j]);
                    returnValue++;
                }
            }
            return(returnValue);
        }
示例#30
0
        public int Grant(string[] userIds, string permissionItemId)
        {
            int returnValue = 0;
            BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper);

            string[] sequenceIds = sequenceManager.GetBatchSequence(BasePermissionEntity.TableName, userIds.Length);
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < userIds.Length; i++)
            {
                this.Grant(permissionManager, sequenceIds[i], userIds[i], permissionItemId);
                returnValue++;
            }
            return(returnValue);
        }