Example #1
0
        /// <summary>
        /// Verify authorization
        /// </summary>
        /// <param name="authorizationOption">Authorization option</param>
        /// <returns>Return verify authorization reuslt</returns>
        public static async Task <VerifyAuthorizationResult> VerifyAuthorizeAsync(VerifyAuthorizationOption authorizationOption)
        {
            if (authorizationOption == null)
            {
                return(VerifyAuthorizationResult.ForbidResult());
            }
            if (!AuthorizationConfiguration.RemoteVerify)
            {
                if (AuthorizationVerifyProxy == null)
                {
                    throw new ArgumentNullException(nameof(AuthorizationVerifyProxy));
                }
                return(AuthorizationVerifyProxy(authorizationOption) ?? VerifyAuthorizationResult.ForbidResult());
            }
            string server = SelectRemoteVerifyServer();

            if (string.IsNullOrWhiteSpace(server))
            {
                throw new ArgumentNullException(nameof(AuthorizationConfiguration.Servers));
            }
            var result = await HttpHelper.PostJsonAsync(server, authorizationOption).ConfigureAwait(false);

            var stringValue = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

            VerifyAuthorizationResult verifyResult = JsonSerializeHelper.JsonToObject <VerifyAuthorizationResult>(stringValue);

            return(verifyResult ?? VerifyAuthorizationResult.ForbidResult());
        }
Example #2
0
        /// <summary>
        /// Configure display from json
        /// </summary>
        /// <param name="json">json data</param>
        public static void ConfigureByJson(string json)
        {
            if (string.IsNullOrWhiteSpace(json))
            {
                return;
            }
            DisplayConfigurationCollection typeConfigurationCollection = JsonSerializeHelper.JsonToObject <DisplayConfigurationCollection>(json);

            Configure(typeConfigurationCollection);
        }
Example #3
0
 /// <summary>
 /// Configure validation by json data
 /// </summary>
 /// <param name="jsonDatas">Json datas</param>
 public static void ConfigureByJson(params string[] jsonDatas)
 {
     if (jsonDatas.IsNullOrEmpty())
     {
         return;
     }
     foreach (var data in jsonDatas)
     {
         var ruleCollection = JsonSerializeHelper.JsonToObject <ValidationRuleCollection>(data);
         Configure(ruleCollection);
     }
 }
Example #4
0
        /// <summary>
        /// Configure data access through json data
        /// </summary>
        /// <param name="jsonConfiguration">Json value</param>
        public static void Configure(string jsonConfiguration)
        {
            if (string.IsNullOrWhiteSpace(jsonConfiguration))
            {
                return;
            }
            var dataConfig = JsonSerializeHelper.JsonToObject <DataConfiguration>(jsonConfiguration);

            if (dataConfig == null)
            {
                return;
            }
            Configure(dataConfig);
        }
Example #5
0
        /// <summary>
        /// 根据登陆账号身份编号获取session
        /// </summary>
        /// <param name="subject">身份编号</param>
        /// <returns></returns>
        public static async Task <AuthSession> GetSessionBySubjectAsync(string subject)
        {
            if (subject == null)
            {
                return(null);
            }
            string sessionValue = await CacheManager.String.GetAsync(subject, GetCacheObject()).ConfigureAwait(false);

            var session = JsonSerializeHelper.JsonToObject <AuthSession>(sessionValue);

            if (!(session?.AllowUse() ?? false))
            {
                session = null;
            }
            return(session);
        }
Example #6
0
        /// <summary>
        /// Upload by http request
        /// </summary>
        /// <param name="request">Http request</param>
        /// <returns>Return upload result</returns>
        public static async Task <UploadResult> UploadByRequestAsync(HttpRequest request)
        {
            if (request == null)
            {
                return(UploadResult.Empty);
            }
            var uploadParameter = JsonSerializeHelper.JsonToObject <RemoteParameter>(request.Form[RemoteParameter.RequestParameterName]);

            if (uploadParameter == null)
            {
                return(UploadResult.Empty);
            }
            Dictionary <string, byte[]> files = new Dictionary <string, byte[]>();

            if (!request.Form.Files.IsNullOrEmpty())
            {
                foreach (var file in request.Form.Files)
                {
                    files.Add(file.FileName, file.OpenReadStream().ToBytes());
                }
            }
            return(await UploadByConfigurationAsync(uploadParameter.Files, files, request.GetAllParameters()).ConfigureAwait(false));
        }