コード例 #1
0
        public bool CheckPermission(string funcCode, UserPermission up)
        {
            var authFunctionDict = _rootFuncs.GetOrAdd(funcCode, (code) =>
            {
                var authService = new AuthAppService();
                var function    = authService.GetFunctionByCode(this._appCode, code);
                var funcList    = authService.GetAllAuthFunctionList(this._appCode, function.FuncCode);
                return(funcList.ToDictionary(s => s.FuncCode));
            });

            foreach (var item in up.Permissions)
            {
                if (authFunctionDict.ContainsKey(item.PermissionCode))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        public void Initialize()
        {
            cacheManager = new MemcachedManager(AuthServiceCacheFactory.CacheKeyFormat);
            var authService = new AuthAppService();

            this._appCode = AppInfo.AppCode;
            if (string.IsNullOrEmpty(this._appCode))
            {
                throw new AuthException("应用标识未配置");
            }
            var appRootFuncList = authService.GetAuthAppRootFunctionList(this._appCode);

            foreach (var item in appRootFuncList)
            {
                var allFuncList = authService.GetAllAuthFunctionList(this._appCode, item.FuncCode);
                allFuncList.Add(item);
                _rootFuncs.AddOrUpdate(item.FuncCode, allFuncList.ToDictionary(s => s.FuncCode), (key, func) => func);
            }

            if (SubscriptionManager.IsSubscriberContextInitialize)
            {
                SubscriptionManager.Subscriber.RegisterConsumerType(typeof(IkAuthorization));
            }
        }