zoukankan      html  css  js  c++  java
  • 1.2AuthenticationHandlerProvider【AuthenticationHandlerProvider>IAuthenticationSchemeProvider】

    IAuthenticationHandlerProvider->AuthenticationHandlerProvider->IAuthenticationSchemeProvider
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Http;
    
    namespace Microsoft.AspNetCore.Authentication
    {
        /// <summary>
        /// Provides the appropriate IAuthenticationHandler instance for the authenticationScheme and request.
        /// </summary>
        public interface IAuthenticationHandlerProvider
        {
            /// <summary>
            /// Returns the handler instance that will be used.
            /// </summary>
            /// <param name="context">The <see cref="HttpContext"/>.</param>
            /// <param name="authenticationScheme">The name of the authentication scheme being handled.</param>
            /// <returns>The handler instance.</returns>
            Task<IAuthenticationHandler?> GetHandlerAsync(HttpContext context, string authenticationScheme);
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Http;
    using Microsoft.Extensions.DependencyInjection;
    
    namespace Microsoft.AspNetCore.Authentication
    {
        /// <summary>
        /// Implementation of <see cref="IAuthenticationHandlerProvider"/>.
        /// </summary>
        public class AuthenticationHandlerProvider : IAuthenticationHandlerProvider
        {
            /// <summary>
            /// Constructor.
            /// </summary>
            /// <param name="schemes">The <see cref="IAuthenticationHandlerProvider"/>.</param>
            public AuthenticationHandlerProvider(IAuthenticationSchemeProvider schemes)
            {
                Schemes = schemes;
            }
    
            /// <summary>
            /// The <see cref="IAuthenticationHandlerProvider"/>.
            /// </summary>
            public IAuthenticationSchemeProvider Schemes { get; }
    
            // handler instance cache, need to initialize once per request
            private readonly Dictionary<string, IAuthenticationHandler> _handlerMap = new Dictionary<string, IAuthenticationHandler>(StringComparer.Ordinal);
    
            /// <summary>
            /// Returns the handler instance that will be used.
            /// </summary>
            /// <param name="context">The context.</param>
            /// <param name="authenticationScheme">The name of the authentication scheme being handled.</param>
            /// <returns>The handler instance.</returns>
            public async Task<IAuthenticationHandler?> GetHandlerAsync(HttpContext context, string authenticationScheme)
            {
                if (_handlerMap.TryGetValue(authenticationScheme, out var value))
                {
                    return value;
                }
    
                var scheme = await Schemes.GetSchemeAsync(authenticationScheme);
                if (scheme == null)
                {
                    return null;
                }
                var handler = (context.RequestServices.GetService(scheme.HandlerType) ??
                    ActivatorUtilities.CreateInstance(context.RequestServices, scheme.HandlerType))
                    as IAuthenticationHandler;
                if (handler != null)
                {
                    await handler.InitializeAsync(scheme, context);
                    _handlerMap[authenticationScheme] = handler;
                }
                return handler;
            }
        }
    }
  • 相关阅读:
    SQLServer数据库中开启CDC导致“事务日志空间被占满,原因为REPLICATION”的原因分析和解决办法
    译:SQL Server的Missing index DMV的 bug可能会使你失去理智---慎重看待缺失索引DMV中的信息
    SQLServer中间接实现函数索引或者Hash索引
    MySQL缓存分类和配置
    MySQL系统变量配置基础
    MySQL索引统计信息更新相关的参数
    Sql Server优化---统计信息维护策略
    SQL Server 用角色(Role)管理数据库权限
    sp_executesql 或者 EXECUTE 执行动态sql的权限问题
    关于T-SQL重编译那点事,内联函数和表值函数在编译生成执行计划的区别
  • 原文地址:https://www.cnblogs.com/htlp/p/15256214.html
Copyright © 2011-2022 走看看