public async Task <bool> AuthorizeAsync(RightAuthorizeContext context) { if (string.IsNullOrWhiteSpace(context.ModuleKey)) { throw new ArgumentNullException(nameof(context.ModuleKey)); } if (string.IsNullOrWhiteSpace(context.Operate)) { throw new ArgumentNullException(nameof(context.Operate)); } RightAuthorizeResult result = null; foreach (var handler in Handlers.OrderBy(p => p.Option.Order)) { result = await handler.AuthorizeAsync(context); if (result.Failed != null) { return(false); } } return(true); }
public async Task<RightAuthorizeResult> AuthorizeAsync(RightAuthorizeContext context) { var loggerFactory = context.HttpContext.ApplicationServices.GetService<ILoggerFactory>(); var logger = loggerFactory.CreateLogger(nameof(RightHandler<TOption>.AuthorizeAsync)); var result = RightAuthorizeResult.Skip(); if (Option.Scheme == RightOption.AUTOMIC_SCHEME || Option.Scheme.Split(',').Contains(context.ModuleKey)) { result = await Authorize(context); if (result.Successed) { logger.LogVerbose($"scheme is {context.ModuleKey} Right Authorization Success"); await AuthorizeSuccess(context); } else if (result.Failed != null) { logger.LogVerbose($"scheme is {context.ModuleKey} Right Authorization Failed"); await AuthorizeFail(context, result.Failed); } else { logger.LogVerbose($"scheme is {context.ModuleKey} Right Authorization Skip"); } } return result; }