예제 #1
0
        /// <summary>
        /// Determines whether client is authorized to invoke the <see cref="T:Microsoft.AspNet.SignalR.Hubs.IHub" /> method.
        /// </summary>
        /// <param name="hubIncomingInvokerContext">An <see cref="T:Microsoft.AspNet.SignalR.Hubs.IHubIncomingInvokerContext" /> providing details regarding the <see cref="T:Microsoft.AspNet.SignalR.Hubs.IHub" /> method invocation.</param>
        /// <param name="appliesToMethod">Indicates whether the interface instance is an attribute applied directly to a method.</param>
        /// <returns>
        /// true if the caller is authorized to invoke the <see cref="T:Microsoft.AspNet.SignalR.Hubs.IHub" /> method; otherwise, false.
        /// </returns>
        public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
        {
            if (IsAnonymousEnabled)
            {
                return(true);
            }

            if (!base.AuthorizeHubMethodInvocation(hubIncomingInvokerContext, appliesToMethod))
            {
                return(false);
            }

            if (appliesToMethod)
            {
                if (_authorizer == null)
                {
                    return(true);
                }

                IPrincipal           user = hubIncomingInvokerContext.Hub.Context.User;
                IEnumerable <string> keys = GetResourceKeys(hubIncomingInvokerContext);

                return(!keys.Any((key) => Blacklist.Contains(key)) && keys.All((key) =>
                                                                               WhiteList.Contains(key) || _authorizer.HasClaim(
                                                                                   new AuthorizationContext(user, key, PermissionType))));
            }

            return(true);
        }