public SessionMiddleware(
            [NotNull] RequestDelegate next,
            [NotNull] ILoggerFactory loggerFactory,
            [NotNull] IEnumerable <ISessionStore> sessionStore,
            [NotNull] IOptions <SessionOptions> options,
            [NotNull] ConfigureOptions <SessionOptions> configureOptions)
        {
            _next   = next;
            _logger = loggerFactory.Create <SessionMiddleware>();
            if (configureOptions != null)
            {
                _options = options.GetNamedOptions(configureOptions.Name);
                configureOptions.Configure(_options);
            }
            else
            {
                _options = options.Options;
            }

            if (_options.Store == null)
            {
                _options.Store = sessionStore.FirstOrDefault();
                if (_options.Store == null)
                {
                    throw new ArgumentException("ISessionStore must be specified.");
                }
            }

            _options.Store.Connect();
        }
        protected AuthenticationMiddleware(
            [NotNull] RequestDelegate next,
            [NotNull] IOptions <TOptions> options,
            [NotNull] ILoggerFactory loggerFactory,
            [NotNull] IUrlEncoder encoder,
            ConfigureOptions <TOptions> configureOptions)
        {
            if (configureOptions != null)
            {
                Options = options.GetNamedOptions(configureOptions.Name);
                configureOptions.Configure(Options, configureOptions.Name);
            }
            else
            {
                Options = options.Options;
            }
            Logger     = loggerFactory.CreateLogger(this.GetType().FullName);
            UrlEncoder = encoder;

            if (string.IsNullOrEmpty(Options.ClaimsIssuer))
            {
                // Default to something reasonable
                Options.ClaimsIssuer = Options.AuthenticationScheme;
            }

            _next = next;
        }
Ejemplo n.º 3
0
        public ThrottleService(
            ILoggerFactory loggerFactory,
            IEnumerable <IRequirementHandler> handlers,
            IEnumerable <IExclusionHandler> exclusionHandlers,
            ISystemClock clock,
            IThrottleCounterStore store,
            IOptions <ThrottleOptions> options,
            ConfigureOptions <ThrottleOptions> configureOptions = null)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (handlers == null)
            {
                throw new ArgumentNullException(nameof(handlers));
            }

            if (exclusionHandlers == null)
            {
                throw new ArgumentNullException(nameof(exclusionHandlers));
            }

            if (clock == null)
            {
                throw new ArgumentNullException(nameof(clock));
            }

            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options = options.Value;
            if (configureOptions != null)
            {
                configureOptions.Configure(_options);
            }

            _options.BuildPolicies();

            _handlers          = handlers.ToArray();
            _exclusionHandlers = exclusionHandlers.ToArray();
            _logger            = loggerFactory.CreateLogger <ThrottleService>();
            _clock             = clock;
            _store             = store;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Instantiates a new <see cref="T:ThrottleMiddleware" />.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline.</param>
        /// <param name="throttleService">An instance of <see cref="T:IThrottleService" />.</param>
        /// <param name="policy">An instance of the <see cref="T:ThrottlePolicy" /> which can be applied.</param>
        public ThrottleMiddleware(
            RequestDelegate next,
            ILoggerFactory loggerFactory,
            IThrottleService throttleService,
            IThrottleStrategyProvider strategyProvider,
            ISystemClock clock,
            IOptions <ThrottleOptions> options,
            ConfigureOptions <ThrottleOptions> configureOptions)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (throttleService == null)
            {
                throw new ArgumentNullException(nameof(throttleService));
            }

            if (strategyProvider == null)
            {
                throw new ArgumentNullException(nameof(strategyProvider));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (clock == null)
            {
                throw new ArgumentNullException(nameof(clock));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _next             = next;
            _logger           = loggerFactory.CreateLogger <ThrottleMiddleware>();
            _throttleService  = throttleService;
            _strategyProvider = strategyProvider;
            _clock            = clock;
            _options          = options.Value;

            if (configureOptions != null)
            {
                configureOptions.Configure(_options);
            }
        }
Ejemplo n.º 5
0
 protected AuthenticationMiddleware([NotNull] RequestDelegate next, [NotNull] IServiceProvider services, [NotNull] IOptions <TOptions> options, ConfigureOptions <TOptions> configureOptions)
 {
     if (configureOptions != null)
     {
         Options = options.GetNamedOptions(configureOptions.Name);
         configureOptions.Configure(Options, configureOptions.Name);
     }
     else
     {
         Options = options.Options;
     }
     _next     = next;
     _services = services;
 }
 public ClaimsTransformationMiddleware(
     [NotNull] RequestDelegate next,
     [NotNull] IOptions<ClaimsTransformationOptions> options,
     ConfigureOptions<ClaimsTransformationOptions> configureOptions)
 {
     if (configureOptions != null)
     {
         Options = options.GetNamedOptions(configureOptions.Name);
         configureOptions.Configure(Options, configureOptions.Name);
     }
     else
     {
         Options = options.Options;
     }
     _next = next;
 }
Ejemplo n.º 7
0
 public ClaimsTransformationMiddleware(
     [NotNull] RequestDelegate next,
     [NotNull] IOptions <ClaimsTransformationOptions> options,
     ConfigureOptions <ClaimsTransformationOptions> configureOptions)
 {
     if (configureOptions != null)
     {
         Options = options.GetNamedOptions(configureOptions.Name);
         configureOptions.Configure(Options, configureOptions.Name);
     }
     else
     {
         Options = options.Options;
     }
     _next = next;
 }