public override Func<HubDescriptor, HttpRequest, bool> BuildAuthorizeConnect(Func<HubDescriptor, HttpRequest, bool> authorizeConnect)
{
return base.BuildAuthorizeConnect((hubDescriptor, request) =>
{
// Execute custom modules first and short circuit if any deny authorization.
if (!authorizeConnect(hubDescriptor, request))
{
return false;
}
// Execute the global hub connection authorizer if there is one next and short circuit if it denies authorization.
if (_globalConnectionAuthorizer != null && !_globalConnectionAuthorizer.AuthorizeHubConnection(hubDescriptor, request))
{
return false;
}
// Get hub attributes implementing IAuthorizeHubConnection from the cache
// If the attributes do not exist in the cache, retrieve them using reflection and add them to the cache
var attributeAuthorizers = _connectionAuthorizersCache.GetOrAdd(hubDescriptor.HubType,
hubType => hubType.GetTypeInfo().GetCustomAttributes().OfType<IAuthorizeHubConnection>());
// Every attribute (if any) implementing IAuthorizeHubConnection attached to the relevant hub MUST allow the connection
return attributeAuthorizers.All(a => a.AuthorizeHubConnection(hubDescriptor, request));
});
}