public void Intercept(IInvocation invocation) { if (invocation == null) { return; } MethodInfo methodInfo = invocation.MethodInvocationTarget; if (methodInfo == null) { methodInfo = invocation.Method; } AuthInterceptorCallHandlerAttribute authInterceptor = methodInfo.GetCustomAttributes <AuthInterceptorCallHandlerAttribute>(true).FirstOrDefault(); if (authInterceptor != null) { _log.Info($"Method:[{invocation.Method.Name}] Param[{string.Join(",", invocation.Arguments.Select(a => a ?? "").ToString())}]"); //adminToken if (invocation.Arguments != null && invocation.Arguments.Count() > 0 && invocation.Arguments[0].ToString().Equals("ABC")) { _log.Info($"[{authInterceptor.ObjID}] Token is right!"); invocation.Proceed(); _log.Info($"Method:[{invocation.Method.Name}] is done!"); } else { _log.Info($"You can't use this Method[{invocation.Method.Name}]"); } } else { invocation.Proceed(); } }
public void Intercept(IInvocation invocation) { if (invocation == null) { return; } MethodInfo methodInfo = invocation.MethodInvocationTarget; if (methodInfo == null) { methodInfo = invocation.Method; } AuthInterceptorCallHandlerAttribute authInterceptor = methodInfo.GetCustomAttributes <AuthInterceptorCallHandlerAttribute>(true).FirstOrDefault(); if (authInterceptor != null) { UserEntity user = null; using (var scope = _root.BeginLifetimeScope()) { user = scope.ResolveOptional <ICache>().User; } //adminToken if (user != null && user.Role.Equals(authInterceptor.Role) && user.Password.Equals("admin123")) { _log.Info($"[{authInterceptor.ObjID}] Token is right!"); invocation.Proceed(); _log.Info($"Method:[{invocation.Method.Name}] is done!"); } else { invocation.ReturnValue = authInterceptor.DefaultReturnValue; } } else { invocation.Proceed(); } }