コード例 #1
0
 public void SaveAsync()
 {
     var logger = Substitute.For<ILogger<SimpleLogAuditingStore>>();
     var store = new SimpleLogAuditingStore(logger);
     var audit = new AuditInfo();
     var actionInfo = new AuditActionInfo();
     actionInfo.ExtraProperties.Add("Key", "Value");
     audit.Actions.Add(actionInfo);
     audit.Exceptions.Add(new Exception());
     audit.ExtraProperties.Add("Key", "Value");
     Should.NotThrow(() => store.SaveAsync(audit));
     logger.ReceivedWithAnyArgs(1).LogInformation(default);
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="implementationMethod"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public virtual AuditActionInfo CreateAuditAction(Type type, MethodInfo implementationMethod, IDictionary <string, object> parameters)
        {
            var actionInfo = new AuditActionInfo
            {
                ServiceName = type != null
                    ? type.FullName
                    : "",
                MethodName    = implementationMethod.Name,
                Parameters    = SerializeConvertArguments(parameters),
                ExecutionTime = Clock.Now
            };

            return(actionInfo);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="method"></param>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public virtual AuditActionInfo CreateAuditAction(Type type, MethodInfo method, IDictionary <string, object> arguments)
        {
            var actionInfo = new AuditActionInfo
            {
                ServiceName = type != null
                    ? type.FullName
                    : "",
                MethodName    = method.Name,
                Parameters    = SerializeConvertArguments(arguments),
                ExecutionTime = Clock.Now
            };

            //TODO Execute contributors

            return(actionInfo);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="audit"></param>
        /// <param name="auditAction"></param>
        /// <returns></returns>
        protected virtual bool ShouldIntercept(AspectContext context, out AuditInfo audit, out AuditActionInfo auditAction)
        {
            audit       = null;
            auditAction = null;
            if (_options.IsEnabled == false)
            {
                return(false);
            }
            if (!(_options.IsEnabledForAnonymousUsers || (_principalAccessor.Principal?.Identity?.IsAuthenticated ?? false)))
            {
                return(false);
            }
            if (CrossCuttingConcerns.IsApplied(context.Implementation, Concerns))
            {
                return(false);
            }

            if (context.ServiceMethod.AttributeExists <DisableAuditingAttribute>() || context.ImplementationMethod.AttributeExists <DisableAuditingAttribute>())
            {
                return(false);
            }

            var auditScope = _auditingManager.Current;

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

            if (!_auditingHelper.ShouldSaveAudit(context.ImplementationMethod, true) && !_auditingHelper.ShouldSaveAudit(context.ServiceMethod, true))
            {
                return(false);
            }

            audit       = auditScope.Info;
            auditAction = _auditingHelper.CreateAuditAction(
                context.Implementation.GetType(), context.ImplementationMethod, context.Parameters
                );

            return(true);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="audit"></param>
        /// <param name="auditAction"></param>
        /// <returns></returns>
        protected virtual bool ShouldIntercept(AspectContext context, out AuditInfo audit, out AuditActionInfo auditAction)
        {
            audit       = null;
            auditAction = null;

            if (CrossCuttingConcerns.IsApplied(context.Implementation, Concerns))
            {
                return(false);
            }
            if (context.ServiceMethod.AttributeExists <DisableAuditingAttribute>() || context.ImplementationMethod.AttributeExists <DisableAuditingAttribute>())
            {
                return(false);
            }
            var auditScope = _auditingManager.Current;

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

            if (!_auditingHelper.ShouldSaveAudit(context.ImplementationMethod, true) && !_auditingHelper.ShouldSaveAudit(context.ServiceMethod, true))
            {
                return(false);
            }

            audit       = auditScope.Info;
            auditAction = _auditingHelper.CreateAuditAction(
                context.Implementation.GetType(), context.ImplementationMethod, context.Parameters
                );

            return(true);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="audit"></param>
        /// <param name="auditAction"></param>
        /// <returns></returns>
        protected virtual bool ShouldIntercept(IMethodInvocation context, out AuditInfo audit, out AuditActionInfo auditAction)
        {
            audit       = null;
            auditAction = null;
            if (!_options.IsEnabled)
            {
                return(false);
            }
            if (!(_options.IsEnabledForAnonymousUsers || (_principalAccessor.Principal?.Identity?.IsAuthenticated ?? false)))
            {
                return(false);
            }
            if (CrossCuttingConcerns.IsApplied(context.TargetObject, Concerns))
            {
                return(false);
            }
            if (context.Method.AttributeExists <AuditedAttribute>())
            {
                return(true);
            }
            if (context.Method.AttributeExists <DisableAuditingAttribute>())
            {
                return(false);
            }

            var auditScope = _auditingManager.Current;

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

            if (!_auditingHelper.ShouldSaveAudit(context.Method, true))
            {
                return(false);
            }

            audit       = auditScope.Info;
            auditAction = _auditingHelper.CreateAuditAction(
                context.TargetObject.GetType(), context.Method, context.Arguments
                );

            return(true);
        }