Ejemplo n.º 1
0
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            Console.WriteLine(exceptionContext.Error);

            //exceptionContext.Result = "Change the return value, nulls error";
            base.OnIncomingError(exceptionContext, invokerContext);
        }
 protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
 {
     #if DEBUG
     Debug.WriteLine("=> Invoking " + context.MethodDescriptor.Name + " on hub " + context.MethodDescriptor.Hub.Name);
     #endif
     return base.OnBeforeIncoming(context);
 }
        protected override object OnAfterIncoming(object result, IHubIncomingInvokerContext context)
        {
            var startedOn = (DateTime)context.StateTracker["ProfilingHubPipelineModule-Invocation-StartedOn"];
            var invocation = new InvocationModel
            {
                ConnectionId = context.Hub.Context.ConnectionId,
                Hub = context.MethodDescriptor.Hub.Name,
                Method = context.MethodDescriptor.Name,
                StartedOn = startedOn,
                EndedOn = DateTime.Now,
                Result = new InvocationResultModel
                    {
                        Value = result,
                        Type = context.MethodDescriptor.ReturnType
                    },
                Arguments = context.Args.Count > 0 ? context.Args
                    .Select((t, i) => new InvocationArgumentModel
                    {
                        Value = t,
                        Name = context.MethodDescriptor.Parameters[i].Name,
                        Type = context.MethodDescriptor.Parameters[i].ParameterType
                    })
                    .ToList() : null
            };

            PluginSettings.StoreInvocation(invocation);
            return base.OnAfterIncoming(result, context);
        }
Ejemplo n.º 4
0
        public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
        {
            if (string.IsNullOrWhiteSpace(AuthToken))
                return false;

            return hubIncomingInvokerContext.Hub.Context.Headers[AuthTokenProvider.AuthTokenKey] == AuthToken;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 数据传到Hub之前进行数据解密
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
 {
     //_canCrypto = CanCrypto(context.Hub.Context);
     //if (!_canCrypto)
     //{
     //    return base.OnBeforeIncoming(context);
     //}
     //数据解密
     string facePublicKey = context.Hub.Context.Headers.Get(HttpHeaderNames.OSharpClientPublicKey);
     if (string.IsNullOrEmpty(facePublicKey))
     {
         return false;
     }
     _cryptor = new CommunicationCryptor(_ownPrivateKey, facePublicKey, _hashType);
     if (context.Args.Count == 1)
     {
         string encrypt = (string)context.Args[0];
         string json = _cryptor.DecryptAndVerifyData(encrypt);
         IList<object> args = JsonConvert.DeserializeObject<IList<object>>(json);
         context.Args.Clear();
         IList<object> values = context.MethodDescriptor.Parameters.Zip(args, (desc, arg) => ResolveParameter(desc, arg)).ToList();
         foreach (object arg in values)
         {
             context.Args.Add(arg);
         }
     }
     return base.OnBeforeIncoming(context);
 }
 protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
 {
     if (log.IsDebugEnabled)
     {
         log.DebugFormat(string.Format("Invoking {0} on hub {1}", context.MethodDescriptor.Name, context.MethodDescriptor.Hub.Name));
     }
     return base.OnBeforeIncoming(context);
 }
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext context)
 {
     if (log.IsErrorEnabled)
     {
         log.ErrorFormat("Exception while invoking {0} on hub {1}: {2}", context.MethodDescriptor.Name, context.MethodDescriptor.Hub.Name, exceptionContext.Error.Message);
     }
     base.OnIncomingError(exceptionContext, context);
 }
 protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
 {
     if (Log.IsDebugEnabled)
     {
         Log.DebugFormat("=> Invoking " + context.MethodDescriptor.Name + " on hub " + context.MethodDescriptor.Hub.Name);
     }
     return base.OnBeforeIncoming(context);
 }
Ejemplo n.º 9
0
 protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
 {
     if (string.IsNullOrWhiteSpace(context.MethodDescriptor.Name))
     {
         Console.WriteLine("Error");
     }
     Console.WriteLine("=> Invoking " + context.MethodDescriptor.Name + " on hub " + context.MethodDescriptor.Hub.Name);
     return(base.OnBeforeIncoming(context));
 }
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     ChatLog.Debug("=> Exception " + exceptionContext.Error.Message + " " + exceptionContext.Error.StackTrace);
     if (exceptionContext.Error.InnerException != null)
     {
         ChatLog.Debug("=> Inner Exception " + exceptionContext.Error.InnerException.Message + " " + exceptionContext.Error.InnerException.StackTrace);
     }
     base.OnIncomingError(exceptionContext, invokerContext);
 }
 protected override void OnIncomingError(ExceptionContext ex, IHubIncomingInvokerContext context)
 {
     _slabLogger.Log(HubType.HubServerVerbose, "=> Exception " + ex.Error + " " + ex.Result);
     if (ex.Error.InnerException != null)
     {
         _slabLogger.Log(HubType.HubServerVerbose, "=> Inner Exception " + ex.Error.InnerException.Message);
     }
     base.OnIncomingError(ex, context);
 }
Ejemplo n.º 12
0
        public new bool OnBeforeIncoming(IHubIncomingInvokerContext context)
        {
            lock (_locker)
            {
                Events.Add(new Tuple <string, object>("OnBeforeIncoming", context));
            }

            return(base.OnBeforeIncoming(context));
        }
Ejemplo n.º 13
0
        public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
        {
            if (string.IsNullOrWhiteSpace(AuthToken))
            {
                return(false);
            }

            return(hubIncomingInvokerContext.Hub.Context.Headers[AuthTokenProvider.AuthTokenKey] == AuthToken);
        }
Ejemplo n.º 14
0
        public new void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            lock (_locker)
            {
                Events.Add(new Tuple <string, object>("OnIncomingError", exceptionContext));
            }

            base.OnIncomingError(exceptionContext, invokerContext);
        }
Ejemplo n.º 15
0
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     Debug.WriteLine("=> Exception " + exceptionContext.Error.Message);
     if (exceptionContext.Error.InnerException != null)
     {
         Debug.WriteLine("=> Inner Exception " + exceptionContext.Error.InnerException.Message);
     }
     base.OnIncomingError(exceptionContext, invokerContext);
 }
Ejemplo n.º 16
0
 protected override void OnIncomingError(ExceptionContext ex, IHubIncomingInvokerContext context)
 {
     _slabLogger.Error("ErrorHandlingPipelineModule.OnIncomingError", "=> Exception " + ex.Error + " " + ex.Result);
     if (ex.Error.InnerException != null)
     {
         _slabLogger.Error("ErrorHandlingPipelineModule.OnIncomingError", "=> Inner Exception " + ex.Error.InnerException.Message);
     }
     base.OnIncomingError(ex, context);
 }
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     File.WriteAllText("D:\\signalr.txt", "=> Exception " + exceptionContext.Error.Message);
     if (exceptionContext.Error.InnerException != null)
     {
         File.WriteAllText("D:\\signalr.txt", "=> Inner Exception " + exceptionContext.Error.InnerException.Message);
     }
     base.OnIncomingError(exceptionContext, invokerContext);
 }
Ejemplo n.º 18
0
        public new object OnAfterIncoming(object result, IHubIncomingInvokerContext context)
        {
            lock (_locker)
            {
                Events.Add(new Tuple <string, object>("OnAfterIncoming", context));
            }

            return(base.OnAfterIncoming(result, context));
        }
Ejemplo n.º 19
0
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     Debug.WriteLine("=> Exception " + exceptionContext.Error.Message);
     if (exceptionContext.Error.InnerException != null)
     {
         Debug.WriteLine("=> Inner Exception " + exceptionContext.Error.InnerException.Message);
     }
     base.OnIncomingError(exceptionContext, invokerContext);
 }
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     ChatLog.Debug("=> Exception " + exceptionContext.Error.Message + " " + exceptionContext.Error.StackTrace);
     if (exceptionContext.Error.InnerException != null)
     {
         ChatLog.Debug("=> Inner Exception " + exceptionContext.Error.InnerException.Message + " " + exceptionContext.Error.InnerException.StackTrace);
     }
     base.OnIncomingError(exceptionContext, invokerContext);
 }
 public override bool AuthorizeHubMethodInvocation(
     IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
 {
     if (hubIncomingInvokerContext.Hub.Context.User is ClaimsPrincipal user &&
         _allowedAuthenticationTypes.Any(type => user.HasClaim("AuthorizationType", type)))
     {
         return(base.AuthorizeHubMethodInvocation(hubIncomingInvokerContext, appliesToMethod));
     }
     return(false);
 }
        protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
        {
            var id = HttpContext.Current.User.Identity.IsAuthenticated
                ? "fred"
                : string.Empty;

            context.Hub.Groups.Add(context.Hub.Context.ConnectionId, id);

            return base.OnBeforeIncoming(context);
        }
Ejemplo n.º 23
0
        protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
        {
            var id = HttpContext.Current.User.Identity.IsAuthenticated
                ? "fred"
                : string.Empty;

            context.Hub.Groups.Add(context.Hub.Context.ConnectionId, id);

            return(base.OnBeforeIncoming(context));
        }
Ejemplo n.º 24
0
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            base.OnIncomingError(exceptionContext, invokerContext);
            //todo:记录到Log4Net或分布式日志服务器中


            dynamic caller = invokerContext.Hub.Clients.Caller;

            caller.onServerError(exceptionContext.Error.Message);
        }
        public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
        {
            string token = hubIncomingInvokerContext.Hub.Context.Headers["authtoken"];

            if (token == AuthToken)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 26
0
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            //异常信息
            //exceptionContext.Error;

            dynamic caller = invokerContext.Hub.Clients.Caller;

            caller.onException("发送错误");
            base.OnIncomingError(exceptionContext, invokerContext);
        }
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext) {
     _logger.Error()
         .Exception(exceptionContext.Error)
         .MarkUnhandled("ErrorHandlingPipelineModule")
         .Message("Unhandled: {0}", exceptionContext.Error.Message)
         .Tag("SignalR")
         .Write();
     
     base.OnIncomingError(exceptionContext, invokerContext);
 }
Ejemplo n.º 28
0
 protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     // HARD-CODED constant
     Tracer.Instance.TraceEvent(TraceEventType.Verbose, 0, "=> Invoking [" + context.MethodDescriptor.Name + "] on hub [" + context.MethodDescriptor.Hub.Name + "]");
     return(base.OnBeforeIncoming(context));
 }
Ejemplo n.º 29
0
 public static void SignalRError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     try {
         var context = invokerContext.Hub.Context;
         var method  = $"/{invokerContext.MethodDescriptor.Hub.Name}/{invokerContext.MethodDescriptor.Name}";
         var logHead = new NetHelper.HttpInfo(context.Request.GetHttpContext().Request, context.RequestCookies).LogHeadNoPath;
         var msg     = $"ERROR = {JsonConvert.SerializeObject(new {ErrorMessage = exceptionContext.Error.Message})}";
         SignalRServerLog.Error($"{logHead}{method}	{msg}", exceptionContext.Error);
     } catch (Exception e) { Error(LogTag.LoggingError, e, new { source = "SignalRError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)" }); }
 }
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            MethodDescriptor method = invokerContext.MethodDescriptor;

            Debug.WriteLine("{0}.{1}({2}) threw the following uncaught exception: {3}",
                            method.Hub.Name,
                            method.Name,
                            String.Join(", ", invokerContext.Args),
                            exceptionContext.Error);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// This is called when an uncaught exception is thrown by a server-side hub method or the incoming component of a
        /// module added later to the <see cref="T:Microsoft.AspNet.SignalR.Hubs.IHubPipeline" />. Observing the exception using this method will not prevent
        /// it from bubbling up to other modules.
        /// </summary>
        /// <param name="exceptionContext">Represents the exception that was thrown during the server-side invocation.
        /// It is possible to change the error or set a result using this context.</param>
        /// <param name="invokerContext">A description of the server-side hub method invocation.</param>
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            var logEntry = new LogEntry(exceptionContext.Error.ToString(), DateTime.UtcNow, LogServerity.Error);

            Task.Factory.StartNew(async() => {
                await Logger.WriteLogEntry(logEntry);
            }).Wait();

            base.OnIncomingError(exceptionContext, invokerContext);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// This method is called after the incoming components of any modules added later to the <see cref="IHubPipeline"/>
        /// and the server-side hub method have completed execution.
        /// </summary>
        /// <param name="result">The return value of the server-side hub method</param>
        /// <param name="context">A description of the server-side hub method invocation.</param>
        /// <returns>The possibly new or updated return value of the server-side hub method</returns>
        protected override object OnAfterIncoming(object result, IHubIncomingInvokerContext context)
        {
            var attributes = context.MethodDescriptor.Attributes.OfType <ActionFilterAttribute>();

            foreach (var attribute in attributes)
            {
                attribute.OnAfterIncoming(result, context);
            }
            return(base.OnAfterIncoming(result, context));
        }
Ejemplo n.º 33
0
        public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
        {
            var connectionId = hubIncomingInvokerContext.Hub.Context.ConnectionId;
            var environment = hubIncomingInvokerContext.Hub.Context.Request.Environment;
            var principal = hubIncomingInvokerContext.Hub.Context.Request.Environment["server.User"] as IPrincipal;

            if (principal == null || !principal.Identity.IsAuthenticated) return false;
            hubIncomingInvokerContext.Hub.Context = new HubCallerContext(new ServerRequest(environment), connectionId);
            return true;
        }
Ejemplo n.º 34
0
        /// <summary>
        /// This is called when an uncaught exception is thrown by a server-side hub method or the incoming component of a
        /// module added later to the <see cref="IHubPipeline"/>. Observing the exception using this method will not prevent
        /// it from bubbling up to other modules.
        /// </summary>
        /// <param name="ex">The exception that was thrown during the server-side invocation.</param>
        /// <param name="context">A description of the server-side hub method invocation.</param>
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            var attributes = invokerContext.MethodDescriptor.Attributes.OfType <ActionFilterAttribute>();

            foreach (var attribute in attributes)
            {
                attribute.OnIncomingError(exceptionContext, invokerContext);
            }
            base.OnIncomingError(exceptionContext, invokerContext);
        }
Ejemplo n.º 35
0
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            _logger.Error(exceptionContext.Error.Message);

            if (exceptionContext.Error.InnerException != null)
            {
                _logger.Error(exceptionContext.Error.InnerException.Message);
            }

            base.OnIncomingError(exceptionContext, invokerContext);
        }
Ejemplo n.º 36
0
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            var connectionId = invokerContext.Hub.Context.ConnectionId;

            DataClassesManager.InsertLog("=> Exception " + exceptionContext.Error.Message, "SignalR", "OnIncomingError", connectionId);
            if (exceptionContext.Error.InnerException != null)
            {
                DataClassesManager.InsertLog("=> Inner Exception " + exceptionContext.Error.InnerException.Message, "SignalR", "OnIncomingError", connectionId);
            }
            base.OnIncomingError(exceptionContext, invokerContext);
        }
Ejemplo n.º 37
0
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            Logger.Error()
            .Exception(exceptionContext.Error)
            .MarkUnhandled("ErrorHandlingPipelineModule")
            .Message("Unhandled: {0}", exceptionContext.Error.Message)
            .Tag("SignalR")
            .Write();

            base.OnIncomingError(exceptionContext, invokerContext);
        }
Ejemplo n.º 38
0
 /// <summary>
 /// This is called when an uncaught exception is thrown by a server-side hub method or the incoming component of a
 /// module added later to the <see cref="IHubPipeline"/>. Observing the exception using this method will not prevent
 /// it from bubbling up to other modules.
 /// </summary>
 /// <param name="ex">The exception that was thrown during the server-side invocation.</param>
 /// <param name="context">A description of the server-side hub method invocation.</param>
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     if (this.onIncomingError == null)
     {
         base.OnIncomingError(exceptionContext, invokerContext);
     }
     else
     {
         this.onIncomingError(exceptionContext, invokerContext);
     }
 }
Ejemplo n.º 39
0
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            // if TableGamesException, convert to HubException to be exposed in clients
            var tableGamesException = getTableGamesException(exceptionContext.Error);

            if (tableGamesException != null)
            {
                exceptionContext.Error = new HubException(tableGamesException.Message);
            }
            base.OnIncomingError(exceptionContext, invokerContext);
        }
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     try
     {
         Log.Error(exceptionContext.Error, "Exception invoking {Method} on {Hub} with {Args}", invokerContext.MethodDescriptor.Name, invokerContext.Hub.GetType().Name, invokerContext.Args);
     }
     // ReSharper disable once UnusedVariable
     catch (Exception e)
     {
         if (Debugger.IsAttached) Debugger.Break();
     }
 }
 public bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext)
 {
     switch (Mode)
     {
         case AuthorizeMode.Both:
         case AuthorizeMode.Incoming:
             return UserAuthorized(hubIncomingInvokerContext.Hub.Context.User);
         default:
             Debug.Assert(Mode == AuthorizeMode.Outgoing); // Guard in case new values are added to the enum
             return true;
     }
 }
Ejemplo n.º 42
0
        public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
        {
            bool isConnect = hubIncomingInvokerContext.Hub.Context.Request.LocalPath == "/signalr/connect";

            return
                (IsLocalRequest(hubIncomingInvokerContext.Hub.Context) ||
                 isConnect ||
                 !appliesToMethod ||
                 ((HttpListener)hubIncomingInvokerContext.Hub.Context.Request.Environment["System.Net.HttpListener"]).AuthenticationSchemes == AuthenticationSchemes.Anonymous ||
                 hubIncomingInvokerContext.Hub.Context.User?.IsInRole("Traders") == true
                );//OnAuthorization(hubIncomingInvokerContext);
        }
Ejemplo n.º 43
0
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            var logger = new NLogLogger("SignalR");

            logger.Log(Logger.LoggerLevels.Error, "=> Exception " + exceptionContext.Error.Message);
            logger.Log(Logger.LoggerLevels.Error, exceptionContext.Error.ToString());
            if (exceptionContext.Error.InnerException != null)
            {
                logger.Log(Logger.LoggerLevels.Error, "=> Inner Exception " + exceptionContext.Error.InnerException.Message);
            }
            base.OnIncomingError(exceptionContext, invokerContext);
        }
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            string message = string.Format("=> Exception {0}", exceptionContext.Error.Message);

            if (exceptionContext.Error.InnerException != null)
            {
                message += "\n\t=> Inner Exception " + exceptionContext.Error.InnerException.Message;
            }

            WindowsEventLog.WriteErrorLog(message);

            base.OnIncomingError(exceptionContext, invokerContext);
        }
        protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            string message = string.Format("=> Exception {0}", exceptionContext.Error.Message);

            if (exceptionContext.Error.InnerException != null)
            {
                message += "\n\t=> Inner Exception " + exceptionContext.Error.InnerException.Message;
            }

            WindowsEventLog.WriteErrorLog(message);

            base.OnIncomingError(exceptionContext, invokerContext);
        }
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     if (exceptionContext == null)
     {
         throw new ArgumentNullException(nameof(exceptionContext));
     }
     Tracer.Instance.TraceEvent(TraceEventType.Error, 0, "=> Exception " + exceptionContext.Error.Message);
     if (exceptionContext.Error.InnerException != null)
     {
         Tracer.Instance.TraceEvent(TraceEventType.Error, 0, "=> Inner Exception " + exceptionContext.Error.InnerException.Message);
     }
     base.OnIncomingError(exceptionContext, invokerContext);
 }
Ejemplo n.º 47
0
        public bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext)
        {
            switch (Mode)
            {
            case AuthorizeMode.Both:
            case AuthorizeMode.Incoming:
                return(UserAuthorized(hubIncomingInvokerContext.Hub.Context.User));

            default:
                Debug.Assert(Mode == AuthorizeMode.Outgoing);     // Guard in case new values are added to the enum
                return(true);
            }
        }
    protected override void OnIncomingError(ExceptionContext exceptionContext,
        IHubIncomingInvokerContext invokerContext)
    {

      Log.Error("Error accessing hub " + exceptionContext.Error.Message, this);


      if (exceptionContext.Error.InnerException != null)
      {
        Log.Error("=> Inner Exception " + exceptionContext.Error.InnerException.Message, this);
      }

      base.OnIncomingError(exceptionContext, invokerContext);

    }
 protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
 {
     var onlyAttr = context.MethodDescriptor.Attributes.OfType<OnlyOnAttribute>().FirstOrDefault();
     if (onlyAttr != null)
     {
         var today = DateTime.Today.DayOfWeek;
         var todayIsValidDay = onlyAttr.Weekdays & (Weekday)(1 << (int)today);
         var canContinue = todayIsValidDay != 0;
         if (!canContinue)
         {
             Debug.WriteLine("Called " + context.MethodDescriptor.Name + "() on server, but today is not allowed");
         }
         return canContinue;
     }
     return true;
 }
Ejemplo n.º 50
0
        public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext invoker, bool appliesToMethod)
        {
            string connectionId = invoker.Hub.Context.ConnectionId;
            var environment = invoker.Hub.Context.Request.Environment;
            var principal = environment["server.User"] as ClaimsPrincipal;

            if(principal?.Identity != null &&
               principal.Identity.IsAuthenticated)
            {
                // create a new HubCallerContext instance with the principal generated from token
                // and replace the current context so that in hubs we can retrieve current user identity
                invoker.Hub.Context = new HubCallerContext(new ServerRequest(environment), connectionId);

                return true;
            }

            return false;
        }
Ejemplo n.º 51
0
        public virtual bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
        {
            if (hubIncomingInvokerContext == null)
            {
                throw new ArgumentNullException("hubIncomingInvokerContext");
            }

            // It is impossible to require outgoing auth at the method level with SignalR's current design.
            // Even though this isn't the stage at which outgoing auth would be applied, we want to throw a runtime error
            // to indicate when the attribute is being used with obviously incorrect expectations.

            // We must explicitly check if _requireOutgoing is true since it is a Nullable type.
            if (appliesToMethod && (_requireOutgoing == true))
            {
                throw new ArgumentException(Resources.Error_MethodLevelOutgoingAuthorization);
            }

            return UserAuthorized(hubIncomingInvokerContext.Hub.Context.User);
        }
        public IEnumerable<ValidationError> ValidateHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext)
        {
            var errors = new List<ValidationError>();

            for (int i = 0; i < hubIncomingInvokerContext.Args.Count; ++i)
            {
                var arg = hubIncomingInvokerContext.Args[i];
                var ctx = new ValidationContext(arg, null, null);
                var results = new List<ValidationResult>();

                bool valid = Validator.TryValidateObject(arg, ctx, results, true);

                if (!valid)
                {
                    ValidationError ve = ValidationErrorsFactory.Buildup(hubIncomingInvokerContext.MethodDescriptor.Parameters[i].Name, arg, results);
                    errors.Add(ve);
                }
            }

            return errors;
        }
Ejemplo n.º 53
0
        public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
        {
            try
            {
                var connectionId = hubIncomingInvokerContext.Hub.Context.ConnectionId;

                var environment = hubIncomingInvokerContext.Hub.Context.Request.Environment;

                var principal = environment["server.User"] as GenericPrincipal;

                if (principal != null && principal.Identity.IsAuthenticated)
                {
                    hubIncomingInvokerContext.Hub.Context = new HubCallerContext(new ServerRequest(environment), connectionId);
                    return true;
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("AuthorizeHubMethodInvocation error: {0}, {1}, {2}", e, e.StackTrace, e.InnerException != null ? e.InnerException.Message : string.Empty);
                return false;
            }
            return false;
        }
        //static readonly ILog logger = LogManager.GetLogger(typeof(HubErrorLoggingPipelineModule));

        protected override void OnIncomingError(ExceptionContext exceptionContext,
            IHubIncomingInvokerContext invokerContext) {
            // Don't log user exceptions...
            var hubEx = exceptionContext.Error as HubException;
            if (hubEx != null) {
                var data = hubEx.ErrorData as UserException;
                if (data != null) {
                    MainLog.Logger.FormattedWarnException(data, "UserException catched in Hub Pipeline");
                    return;
                }

                var ex = hubEx.ErrorData as Exception;
                if (ex != null) {
                    MainLog.Logger.FormattedErrorException(ex,
                        "An error occurred on signalr hub: " + GetInvocationInfo(invokerContext));
                }
                return;
            }

            if (exceptionContext.Error is UserException || exceptionContext.Error.InnerException is UserException)
                return;
            MainLog.Logger.FormattedErrorException(exceptionContext.Error,
                "An error occurred on signalr hub: " + GetInvocationInfo(invokerContext));
        }
Ejemplo n.º 55
0
 protected override void OnIncomingError(Exception ex, IHubIncomingInvokerContext context)
 {
     _logger.LogError("{0}: Failure while invoking '{1}'.", context.Hub.Context.Request.User.GetUserId(), context.MethodDescriptor.Name);
     _logger.Log(ex);
 }
Ejemplo n.º 56
0
 protected override void OnIncomingError(Exception ex, IHubIncomingInvokerContext context)
 {
     Debug.WriteLine("Invoking method " + context.MethodDescriptor.Name + " on " + context.MethodDescriptor.Name + " gave error " + ex.GetBaseException());
     base.OnIncomingError(ex, context);
 }
Ejemplo n.º 57
0
 protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
 {
     Debug.WriteLine("Before method " + context.MethodDescriptor.Name + " on " + context.MethodDescriptor.Hub.Name);
     return base.OnBeforeIncoming(context);
 }
        protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
        {
            Debug.WriteLine("Loggin OnBeforeIncoming: {0}, {1}", context.Hub.Context.ConnectionId, context.MethodDescriptor.Name);

            return true;
        }
Ejemplo n.º 59
0
 public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
 {
     return true;
 }
Ejemplo n.º 60
0
 protected override object OnAfterIncoming(object result, IHubIncomingInvokerContext context)
 {
     Debug.WriteLine("After method " + context.MethodDescriptor.Name + " on " + context.MethodDescriptor.Hub.Name);
     return base.OnAfterIncoming(result, context);
 }