/// <summary>
        /// 导入权限
        /// </summary>
        public async void ImportAuthorities()
        {
            this.Busy();

            await Task.Run(() =>
            {
                IAuthorizationContract authorizationContract = this._authorizationContract.Channel;
                Authority[] authorities = ExcelReader.ReadFile <Authority>(ExcelPath, "权限");
                var authorityGroups     = authorities.GroupBy(x => new
                {
                    x.信息系统编号,
                    x.应用程序类型
                });

                foreach (var authorityGroup in authorityGroups)
                {
                    IList <AuthorityParam> authorityParams = new List <AuthorityParam>();
                    foreach (Authority authority in authorityGroup)
                    {
                        AuthorityParam authorityParam = new AuthorityParam()
                        {
                            authorityName = authority.权限名称,
                            authorityPath = authority.权限路径
                        };
                        authorityParams.Add(authorityParam);
                    }

                    ApplicationType applicationType = (ApplicationType)Enum.Parse(typeof(ApplicationType), authorityGroup.Key.应用程序类型);
                    authorizationContract.CreateAuthorities(authorityGroup.Key.信息系统编号, applicationType, authorityParams);
                }
            });

            this.Idle();
            this.ToastSuccess("导入权限成功!");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化权限
        /// </summary>
        /// <param name="assemblyPath">程序集路径</param>
        /// <param name="infoSystemNo">信息系统编号</param>
        /// <param name="applicationType">应用程序类型</param>
        private async Task InitAuthorities(string assemblyPath, string infoSystemNo, ApplicationType applicationType)
        {
            //加载程序集、加载权限
            Assembly assembly = Assembly.LoadFrom(assemblyPath);

            Type[] types = assembly.GetTypes();

            //加载需认证的方法
            IEnumerable <MethodInfo> methodInfos = types.SelectMany(x => x.GetMethods()).Where(x => x.IsDefined(typeof(RequireAuthorizationAttribute), false));

            //构造权限参数模型集
            IList <AuthorityParam> authorityParams = new List <AuthorityParam>();

            foreach (MethodInfo methodInfo in methodInfos)
            {
                object[] attributes = methodInfo.GetCustomAttributes(typeof(RequireAuthorizationAttribute), false);
                RequireAuthorizationAttribute attribute = (RequireAuthorizationAttribute)(attributes[0]);
                AuthorityParam authorityParam           = new AuthorityParam
                {
                    authorityName = attribute.AuthorityPath,
                    authorityPath = attribute.AuthorityPath
                };
                authorityParams.Add(authorityParam);
            }

            await Task.Factory.StartNew(() => this._authorizationContract.CreateAuthorities(infoSystemNo, applicationType, authorityParams));
        }
        /// <summary>
        /// 修改权限
        /// </summary>
        /// <param name="authorityId">权限Id</param>
        /// <param name="authorityParam">权限参数模型</param>
        public void UpdateAuthority(Guid authorityId, AuthorityParam authorityParam)
        {
            Authority authority = this._unitOfWork.Resolve <Authority>(authorityId);

            authority.UpdateInfo(authorityParam.AuthorityName, authorityParam.EnglishName, authorityParam.Description, authorityParam.AssemblyName, authorityParam.Namespace, authorityParam.ClassName, authorityParam.MethodName);

            this._unitOfWork.RegisterSave(authority);
            this._unitOfWork.UnitedCommit();
        }
        public void UpdateAuthority(Guid authorityId, string authorityName, string englishName, string description, string assemblyName, string @namespace, string className, string methodName)
        {
            //构造参数模型
            AuthorityParam param = new AuthorityParam
            {
                AuthorityName = authorityName,
                EnglishName   = englishName,
                Description   = description,
                AssemblyName  = assemblyName,
                Namespace     = @namespace,
                ClassName     = className,
                MethodName    = methodName
            };

            this._authorizationContract.UpdateAuthority(authorityId, param);
        }
        public void CreateAuthority(string systemNo, string authorityName, string englishName, string description, string assemblyName, string @namespace, string className, string methodName)
        {
            //构造参数模型
            AuthorityParam param = new AuthorityParam
            {
                AuthorityName = authorityName,
                EnglishName   = englishName,
                Description   = description,
                AssemblyName  = assemblyName,
                Namespace     = @namespace,
                ClassName     = className,
                MethodName    = methodName
            };

            this._authorizationContract.CreateAuthorities(systemNo, new[] { param });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 初始化权限集
        /// </summary>
        /// <param name="assemblyPath">程序集路径</param>
        /// <param name="systemKindNo">信息系统类别编号</param>
        private void InitAuthorities(string assemblyPath, string systemKindNo)
        {
            //加载程序集、加载权限
            Assembly assembly = Assembly.LoadFrom(assemblyPath);

            Type[] types = assembly.GetTypes();

            //加载需认证的方法
            IEnumerable <MethodInfo> methodInfos = types.SelectMany(x => x.GetMethods()).Where(x => x.IsDefined(typeof(RequireAuthorizationAttribute)));

            //构造权限参数模型集
            IList <AuthorityParam> authorityParams = new List <AuthorityParam>();

            foreach (MethodInfo methodInfo in methodInfos)
            {
                RequireAuthorizationAttribute attribute = methodInfo.GetCustomAttribute <RequireAuthorizationAttribute>();

                AuthorityParam authorityParam = new AuthorityParam
                {
                    AssemblyName  = assembly.GetName().Name,
                    Namespace     = methodInfo.DeclaringType.Namespace,
                    ClassName     = methodInfo.DeclaringType.Name,
                    MethodName    = methodInfo.Name,
                    AuthorityName = attribute.AuthorityName,
                    EnglishName   = attribute.EnglishName,
                    Description   = attribute.Description
                };

                if (!this._authorizationContract.ExistsAuthority(authorityParam.AssemblyName, authorityParam.Namespace, authorityParam.ClassName, authorityParam.MethodName))
                {
                    authorityParams.Add(authorityParam);
                }
            }

            this._authorizationContract.CreateAuthorities(systemKindNo, authorityParams);
        }
 public async Task <IEnumerable <ApiScope> > GetApiScopesAsync(AuthorityParam param, CancellationToken cancellationToken)
 {
     return(await _repository.GetApiScopesAsync(param, cancellationToken));
 }
 public async Task <object> GetConfigurationAsync(AuthorityParam param, CancellationToken cancellationToken)
 {
     return(await _repository.GetConfigurationAsync(param, cancellationToken));
 }
        public async Task <IEnumerable <Client> > GetClientsAsync(AuthorityParam param, CancellationToken cancellationToken)
        {
            var config = await GetConfigDaoAsync(param.Authority, cancellationToken);

            return(config.Clients == null?Array.Empty <Client>() : config.Clients.ToArray());
        }
        // NEW API

        public async Task <object> GetConfigurationAsync(AuthorityParam param, CancellationToken cancellationToken)
        {
            return(await GetConfigDaoAsync(param.Authority, cancellationToken));
        }
        // api sope
        public async Task <IEnumerable <ApiScope> > GetApiScopesAsync(AuthorityParam param, CancellationToken cancellationToken)
        {
            var config = await GetConfigDaoAsync(param.Authority, cancellationToken);

            return(config.Apis);
        }