Example #1
0
        /// <summary>
        /// Adds an <see cref="IHubFilter"/> type to the <see cref="HubOptions"/> that will be resolved via DI or type activated.
        /// </summary>
        /// <param name="options">The options to add a filter to.</param>
        /// <param name="filterType">The <see cref="IHubFilter"/> type that will be added to the options.</param>
        public static void AddFilter(this HubOptions options, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type filterType)
        {
            _ = options ?? throw new ArgumentNullException(nameof(options));
            _ = filterType ?? throw new ArgumentNullException(nameof(filterType));

            options.AddFilter(new HubFilterFactory(filterType));
        }
Example #2
0
        public static void AddFilter(this HubOptions options, Type filterType)
        {
            _ = options ?? throw new ArgumentNullException(nameof(options));
            _ = filterType ?? throw new ArgumentNullException(nameof(filterType));

            options.AddFilter(new HubFilterFactory(filterType));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HubConnectionHandler{THub}"/> class.
        /// </summary>
        /// <param name="lifetimeManager">The hub lifetime manager.</param>
        /// <param name="protocolResolver">The protocol resolver used to resolve the protocols between client and server.</param>
        /// <param name="globalHubOptions">The global options used to initialize hubs.</param>
        /// <param name="hubOptions">Hub specific options used to initialize hubs. These options override the global options.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="userIdProvider">The user ID provider used to get the user ID from a hub connection.</param>
        /// <param name="serviceScopeFactory">The service scope factory.</param>
        /// <remarks>This class is typically created via dependency injection.</remarks>
        public HubConnectionHandler(HubLifetimeManager <THub> lifetimeManager,
                                    IHubProtocolResolver protocolResolver,
                                    IOptions <HubOptions> globalHubOptions,
                                    IOptions <HubOptions <THub> > hubOptions,
                                    ILoggerFactory loggerFactory,
                                    IUserIdProvider userIdProvider,
                                    IServiceScopeFactory serviceScopeFactory
                                    )
        {
            _protocolResolver = protocolResolver;
            _lifetimeManager  = lifetimeManager;
            _loggerFactory    = loggerFactory;
            _hubOptions       = hubOptions.Value;
            _globalHubOptions = globalHubOptions.Value;
            _logger           = loggerFactory.CreateLogger <HubConnectionHandler <THub> >();
            _userIdProvider   = userIdProvider;

            _enableDetailedErrors = _hubOptions.EnableDetailedErrors ?? _globalHubOptions.EnableDetailedErrors ?? false;
            _maximumMessageSize   = _hubOptions.MaximumReceiveMessageSize ?? _globalHubOptions.MaximumReceiveMessageSize;

            _dispatcher = new DefaultHubDispatcher <THub>(
                serviceScopeFactory,
                new HubContext <THub>(lifetimeManager),
                hubOptions,
                globalHubOptions,
                new Logger <DefaultHubDispatcher <THub> >(loggerFactory));
        }
 public void Configure(HubOptions <THub> options)
 {
     options.SupportedProtocols = new List <string>(_hubOptions.SupportedProtocols.Count);
     foreach (var protocol in _hubOptions.SupportedProtocols)
     {
         options.SupportedProtocols.Add(protocol);
     }
     options.KeepAliveInterval = _hubOptions.KeepAliveInterval;
     options.HandshakeTimeout  = _hubOptions.HandshakeTimeout;
 }
        /// <summary>
        /// Requiring Authentication adds an <see cref="AuthorizeModule"/> to the <see cref="HubOptions" /> with <see cref="IAuthorizeHubConnection"/>
        /// and <see cref="IAuthorizeHubMethodInvocation"/> authorizers that will be applied globally to all hubs and hub methods.
        /// These authorizers require that the <see cref="System.Security.Principal.IPrincipal"/>'s <see cref="System.Security.Principal.IIdentity"/>
        /// IsAuthenticated for any clients that invoke server-side hub methods or receive client-side hub method invocations.
        /// </summary>
        /// <param name="options">The <see cref="HubOptions" /> to which the <see cref="AuthorizeModule" /> will be added.</param>
        public static void RequireAuthentication(this HubOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var authorizer = new AuthorizeAttribute();

            options.PipelineModules.Add(new AuthorizeModule(globalConnectionAuthorizer: authorizer, globalInvocationAuthorizer: authorizer));
        }
Example #6
0
        public static void AddFilter(this HubOptions options, IHubFilter hubFilter)
        {
            _ = options ?? throw new ArgumentNullException(nameof(options));
            _ = hubFilter ?? throw new ArgumentNullException(nameof(hubFilter));

            if (options.HubFilters == null)
            {
                options.HubFilters = new List <IHubFilter>();
            }

            options.HubFilters.Add(hubFilter);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HubConnectionHandler{THub}"/> class.
        /// </summary>
        /// <param name="lifetimeManager">The hub lifetime manager.</param>
        /// <param name="protocolResolver">The protocol resolver used to resolve the protocols between client and server.</param>
        /// <param name="globalHubOptions">The global options used to initialize hubs.</param>
        /// <param name="hubOptions">Hub specific options used to initialize hubs. These options override the global options.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="userIdProvider">The user ID provider used to get the user ID from a hub connection.</param>
        /// <param name="serviceScopeFactory">The service scope factory.</param>
        /// <remarks>This class is typically created via dependency injection.</remarks>
        public HubConnectionHandler(HubLifetimeManager <THub> lifetimeManager,
                                    IHubProtocolResolver protocolResolver,
                                    IOptions <HubOptions> globalHubOptions,
                                    IOptions <HubOptions <THub> > hubOptions,
                                    ILoggerFactory loggerFactory,
                                    IUserIdProvider userIdProvider,
                                    IServiceScopeFactory serviceScopeFactory
                                    )
        {
            _protocolResolver = protocolResolver;
            _lifetimeManager  = lifetimeManager;
            _loggerFactory    = loggerFactory;
            _hubOptions       = hubOptions.Value;
            _globalHubOptions = globalHubOptions.Value;
            _logger           = loggerFactory.CreateLogger <HubConnectionHandler <THub> >();
            _userIdProvider   = userIdProvider;

            _enableDetailedErrors = false;

            List <IHubFilter> hubFilters = null;

            if (_hubOptions.UserHasSetValues)
            {
                _maximumMessageSize   = _hubOptions.MaximumReceiveMessageSize;
                _enableDetailedErrors = _hubOptions.EnableDetailedErrors ?? _enableDetailedErrors;

                if (_hubOptions.HubFilters != null)
                {
                    hubFilters = new List <IHubFilter>();
                    hubFilters.AddRange(_hubOptions.HubFilters);
                }
            }
            else
            {
                _maximumMessageSize   = _globalHubOptions.MaximumReceiveMessageSize;
                _enableDetailedErrors = _globalHubOptions.EnableDetailedErrors ?? _enableDetailedErrors;

                if (_globalHubOptions.HubFilters != null)
                {
                    hubFilters = new List <IHubFilter>();
                    hubFilters.AddRange(_globalHubOptions.HubFilters);
                }
            }

            _dispatcher = new DefaultHubDispatcher <THub>(
                serviceScopeFactory,
                new HubContext <THub>(lifetimeManager),
                _enableDetailedErrors,
                new Logger <DefaultHubDispatcher <THub> >(loggerFactory),
                hubFilters);
        }
Example #8
0
 public HubEndPoint(HubLifetimeManager <THub> lifetimeManager,
                    IHubProtocolResolver protocolResolver,
                    IOptions <HubOptions> hubOptions,
                    ILoggerFactory loggerFactory,
                    IUserIdProvider userIdProvider,
                    IHubInvoker <THub> hubInvoker)
 {
     _protocolResolver = protocolResolver;
     _lifetimeManager  = lifetimeManager;
     _loggerFactory    = loggerFactory;
     _hubOptions       = hubOptions.Value;
     _logger           = loggerFactory.CreateLogger <HubEndPoint <THub> >();
     _userIdProvider   = userIdProvider;
     _hubInvoker       = hubInvoker;
 }
Example #9
0
 public HubEndPoint(HubLifetimeManager <THub> lifetimeManager,
                    IHubProtocolResolver protocolResolver,
                    IOptions <HubOptions> globalHubOptions,
                    IOptions <HubOptions <THub> > hubOptions,
                    ILoggerFactory loggerFactory,
                    IUserIdProvider userIdProvider,
                    HubDispatcher <THub> dispatcher)
 {
     _protocolResolver = protocolResolver;
     _lifetimeManager  = lifetimeManager;
     _loggerFactory    = loggerFactory;
     _hubOptions       = hubOptions.Value;
     _globalHubOptions = globalHubOptions.Value;
     _logger           = loggerFactory.CreateLogger <HubEndPoint <THub> >();
     _userIdProvider   = userIdProvider;
     _dispatcher       = dispatcher;
 }
        public void Configure(HubOptions <THub> options)
        {
            // Do a deep copy, otherwise users modifying the HubOptions<THub> list would be changing the global options list
            options.SupportedProtocols = new List <string>(_hubOptions.SupportedProtocols.Count);
            foreach (var protocol in _hubOptions.SupportedProtocols)
            {
                options.SupportedProtocols.Add(protocol);
            }
            options.KeepAliveInterval         = _hubOptions.KeepAliveInterval;
            options.HandshakeTimeout          = _hubOptions.HandshakeTimeout;
            options.ClientTimeoutInterval     = _hubOptions.ClientTimeoutInterval;
            options.EnableDetailedErrors      = _hubOptions.EnableDetailedErrors;
            options.MaximumReceiveMessageSize = _hubOptions.MaximumReceiveMessageSize;
            options.StreamBufferCapacity      = _hubOptions.StreamBufferCapacity;

            options.UserHasSetValues = true;
        }
Example #11
0
        public void Configure(HubOptions <THub> options)
        {
            // Do a deep copy, otherwise users modifying the HubOptions<THub> list would be changing the global options list
            options.SupportedProtocols        = new List <string>(_hubOptions.SupportedProtocols ?? Array.Empty <string>());
            options.KeepAliveInterval         = _hubOptions.KeepAliveInterval;
            options.HandshakeTimeout          = _hubOptions.HandshakeTimeout;
            options.ClientTimeoutInterval     = _hubOptions.ClientTimeoutInterval;
            options.EnableDetailedErrors      = _hubOptions.EnableDetailedErrors;
            options.MaximumReceiveMessageSize = _hubOptions.MaximumReceiveMessageSize;
            options.StreamBufferCapacity      = _hubOptions.StreamBufferCapacity;

            options.UserHasSetValues = true;

            if (_hubOptions.HubFilters != null)
            {
                options.HubFilters = new List <IHubFilter>(_hubOptions.HubFilters);
            }
        }
Example #12
0
        public HubEndPoint(HubLifetimeManager <THub> lifetimeManager,
                           IHubProtocolResolver protocolResolver,
                           IHubContext <THub> hubContext,
                           IOptions <HubOptions> hubOptions,
                           ILogger <HubEndPoint <THub> > logger,
                           IServiceScopeFactory serviceScopeFactory,
                           IUserIdProvider userIdProvider)
        {
            _protocolResolver    = protocolResolver;
            _lifetimeManager     = lifetimeManager;
            _hubContext          = hubContext;
            _hubOptions          = hubOptions.Value;
            _logger              = logger;
            _serviceScopeFactory = serviceScopeFactory;
            _userIdProvider      = userIdProvider;

            DiscoverHubMethods();
        }
Example #13
0
        public HubConnectionHandler(HubLifetimeManager <THub> lifetimeManager,
                                    IHubProtocolResolver protocolResolver,
                                    IOptions <HubOptions> globalHubOptions,
                                    IOptions <HubOptions <THub> > hubOptions,
                                    ILoggerFactory loggerFactory,
                                    IUserIdProvider userIdProvider,
                                    HubDispatcher <THub> dispatcher)
        {
            _protocolResolver = protocolResolver;
            _lifetimeManager  = lifetimeManager;
            _loggerFactory    = loggerFactory;
            _hubOptions       = hubOptions.Value;
            _globalHubOptions = globalHubOptions.Value;
            _logger           = loggerFactory.CreateLogger <HubConnectionHandler <THub> >();
            _userIdProvider   = userIdProvider;
            _dispatcher       = dispatcher;

            _enableDetailedErrors = _hubOptions.EnableDetailedErrors ?? _globalHubOptions.EnableDetailedErrors ?? false;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HubConnectionHandler{THub}"/> class.
        /// </summary>
        /// <param name="lifetimeManager">The hub lifetime manager.</param>
        /// <param name="protocolResolver">The protocol resolver used to resolve the protocols between client and server.</param>
        /// <param name="globalHubOptions">The global options used to initialize hubs.</param>
        /// <param name="hubOptions">Hub specific options used to initialize hubs. These options override the global options.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="userIdProvider">The user ID provider used to get the user ID from a hub connection.</param>
        /// <param name="dispatcher">The hub dispatcher used to dispatch incoming messages to hubs.</param>
        /// <remarks>This class is typically created via dependency injection.</remarks>
        public HubConnectionHandler(HubLifetimeManager <THub> lifetimeManager,
                                    IHubProtocolResolver protocolResolver,
                                    IOptions <HubOptions> globalHubOptions,
                                    IOptions <HubOptions <THub> > hubOptions,
                                    ILoggerFactory loggerFactory,
                                    IUserIdProvider userIdProvider,
#pragma warning disable PUB0001 // Pubternal type in public API
                                    HubDispatcher <THub> dispatcher
#pragma warning restore PUB0001
                                    )
        {
            _protocolResolver = protocolResolver;
            _lifetimeManager  = lifetimeManager;
            _loggerFactory    = loggerFactory;
            _hubOptions       = hubOptions.Value;
            _globalHubOptions = globalHubOptions.Value;
            _logger           = loggerFactory.CreateLogger <HubConnectionHandler <THub> >();
            _userIdProvider   = userIdProvider;
            _dispatcher       = dispatcher;

            _enableDetailedErrors = _hubOptions.EnableDetailedErrors ?? _globalHubOptions.EnableDetailedErrors ?? false;
        }
 public SignalROptions()
 {
     Hubs       = new HubOptions();
     MessageBus = new MessageBusOptions();
     Transports = new TransportOptions();
 }
Example #16
0
        public static void AddFilter <TFilter>(this HubOptions options) where TFilter : IHubFilter
        {
            _ = options ?? throw new ArgumentNullException(nameof(options));

            options.AddFilter(typeof(TFilter));
        }
Example #17
0
        /// <summary>
        /// Adds an <see cref="IHubFilter"/> type to the <see cref="HubOptions"/> that will be resolved via DI or type activated.
        /// </summary>
        /// <typeparam name="TFilter">The <see cref="IHubFilter"/> type that will be added to the options.</typeparam>
        /// <param name="options">The options to add a filter to.</param>
        public static void AddFilter <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TFilter>(this HubOptions options) where TFilter : IHubFilter
        {
            _ = options ?? throw new ArgumentNullException(nameof(options));

            options.AddFilter(typeof(TFilter));
        }
 public SignalROptions()
 {
     Hubs = new HubOptions();
     MessageBus = new MessageBusOptions();
     Transports = new TransportOptions();
 }
Example #19
0
 public void Configure(HubOptions <THub> options)
 {
     options.SupportedProtocols = _hubOptions.SupportedProtocols;
     options.KeepAliveInterval  = _hubOptions.KeepAliveInterval;
     options.HandshakeTimeout   = _hubOptions.HandshakeTimeout;
 }
Example #20
0
 public HubOptionsSetup(IOptions <HubOptions> options)
 {
     _hubOptions = options.Value;
 }