/// <summary>
        /// 事件处理
        /// </summary>
        /// <param name="eventData">事件源数据</param>
        public override void Handle(FunctionAuthCacheRefreshEventData eventData)
        {
            if (!_provider.InHttpRequest())
            {
                return;
            }
            IFunctionAuthCache cache = _provider.GetService <IFunctionAuthCache>();

            if (eventData.FunctionIds.Length > 0)
            {
                cache.RemoveFunctionCaches(eventData.FunctionIds);
                foreach (Guid functionId in eventData.FunctionIds)
                {
                    cache.GetFunctionRoles(functionId);
                }
            }
            if (eventData.UserNames.Length > 0)
            {
                cache.RemoveUserCaches(eventData.UserNames);
                foreach (string userName in eventData.UserNames)
                {
                    cache.GetUserFunctions(userName);
                }
            }
        }
        /// <summary>
        /// 应用模块服务
        /// </summary>
        /// <param name="provider">服务提供者</param>
        public override void UsePack(IServiceProvider provider)
        {
            IModuleHandler moduleHandler = provider.GetService <IModuleHandler>();

            moduleHandler.Initialize();

            //初始化各种缓存
            IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>();

            functionHandler.RefreshCache();

            IEntityInfoHandler entityInfoHandler = provider.GetService <IEntityInfoHandler>();

            entityInfoHandler.RefreshCache();

            IFunctionAuthCache functionAuthCache = provider.GetService <IFunctionAuthCache>();

            functionAuthCache.BuildRoleCaches();

            IDataAuthCache dataAuthCache = provider.GetService <IDataAuthCache>();

            dataAuthCache.BuildCaches();

            IsEnabled = true;
        }
Exemple #3
0
        /// <summary>
        /// 应用模块服务
        /// </summary>
        /// <param name="provider">服务提供者</param>
        public override void UsePack(IServiceProvider provider)
        {
            IEntityInfoHandler entityInfoHandler = provider.GetService <IEntityInfoHandler>();

            entityInfoHandler.RefreshCache();

            IFunctionAuthCache functionAuthCache = provider.GetService <IFunctionAuthCache>();

            functionAuthCache.BuildRoleCaches();

            IDataAuthCache dataAuthCache = provider.GetService <IDataAuthCache>();

            dataAuthCache.BuildCaches();

            IsEnabled = true;
        }
        /// <summary>
        /// 应用功能权限授权
        /// </summary>
        public static IApplicationBuilder UseFunctionAuthorization(this IApplicationBuilder app)
        {
            app.UseAuthorization();

            IServiceProvider provider = app.ApplicationServices;

            IModuleHandler moduleHandler = provider.GetService <IModuleHandler>();

            moduleHandler.Initialize();

            IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>();

            functionHandler.RefreshCache();

            IFunctionAuthCache functionAuthCache = provider.GetService <IFunctionAuthCache>();

            functionAuthCache.BuildRoleCaches();

            return(app);
        }
Exemple #5
0
 /// <summary>
 /// 初始化一个<see cref="FunctionAuthorizationBase"/>类型的新实例
 /// </summary>
 public FunctionAuthorization(IFunctionAuthCache functionAuthCache)
     : base(functionAuthCache)
 {
 }
 /// <summary>
 /// 初始化一个<see cref="FunctionAuthorizationBase"/>类型的新实例
 /// </summary>
 protected FunctionAuthorizationBase(IFunctionAuthCache functionAuthCache)
 {
     FunctionAuthCache = functionAuthCache;
     SuperRoleName     = "系统管理员";
 }