Ejemplo n.º 1
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (!ShouldSaveAudit(context, out var auditLog, out var auditLogAction))
            {
                await next();

                return;
            }

            using (RocketCrossCuttingConcerns.Applying(context.Controller, RocketCrossCuttingConcerns.Auditing)) {
                var stopwatch = Stopwatch.StartNew();

                try {
                    var result = await next();

                    if (result.Exception != null && !result.ExceptionHandled)
                    {
                        auditLog.Exceptions.Add(result.Exception);
                    }
                } catch (Exception ex) {
                    auditLog.Exceptions.Add(ex);
                    throw;
                } finally {
                    stopwatch.Stop();
                    auditLogAction.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);
                    auditLog.Actions.Add(auditLogAction);
                }
            }
        }
Ejemplo n.º 2
0
        protected virtual bool ShouldIntercept(
            IRocketMethodInvocation invocation,
            out AuditLogInfo auditLog,
            out AuditLogActionInfo auditLogAction)
        {
            auditLog       = null;
            auditLogAction = null;

            if (RocketCrossCuttingConcerns.IsApplied(invocation.TargetObject, RocketCrossCuttingConcerns.Auditing))
            {
                return(false);
            }

            var auditLogScope = _auditingManager.Current;

            if (auditLogScope == null)
            {
                return(false);
            }

            if (!_auditingHelper.ShouldSaveAudit(invocation.Method))
            {
                return(false);
            }

            auditLog       = auditLogScope.Log;
            auditLogAction = _auditingHelper.CreateAuditLogAction(
                auditLog,
                invocation.TargetObject.GetType(),
                invocation.Method,
                invocation.Arguments
                );

            return(true);
        }
Ejemplo n.º 3
0
        public override async Task InterceptAsync(IRocketMethodInvocation invocation)
        {
            if (RocketCrossCuttingConcerns.IsApplied(invocation.TargetObject, RocketCrossCuttingConcerns.FeatureChecking))
            {
                await invocation.ProceedAsync();

                return;
            }

            await CheckFeaturesAsync(invocation);

            await invocation.ProceedAsync();
        }
Ejemplo n.º 4
0
        public async Task OnPageHandlerExecutionAsync (PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) {
            if (context.HandlerMethod == null || !context.ActionDescriptor.IsPageAction ()) {
                await next ();
                return;
            }

            var methodInfo = context.HandlerMethod.MethodInfo;

            using (RocketCrossCuttingConcerns.Applying (context.HandlerInstance, RocketCrossCuttingConcerns.FeatureChecking)) {
                await _methodInvocationAuthorizationService.CheckAsync (
                    new MethodInvocationFeatureCheckerContext (methodInfo)
                );

                await next ();
            }
        }
Ejemplo n.º 5
0
        public async Task OnActionExecutionAsync(
            ActionExecutingContext context,
            ActionExecutionDelegate next)
        {
            if (!context.ActionDescriptor.IsControllerAction())
            {
                await next();

                return;
            }

            var methodInfo = context.ActionDescriptor.GetMethodInfo();

            using (RocketCrossCuttingConcerns.Applying(context.Controller, RocketCrossCuttingConcerns.FeatureChecking)) {
                await _methodInvocationAuthorizationService.CheckAsync(
                    new MethodInvocationFeatureCheckerContext (methodInfo)
                    );

                await next();
            }
        }