예제 #1
0
 public AuditLogAction(Guid id, Guid auditLogId, AuditLogActionInfo actionInfo, Guid?tenantId = null)
 {
     Id                = id;
     TenantId          = tenantId;
     AuditLogId        = auditLogId;
     ExecutionTime     = actionInfo.ExecutionTime;
     ExecutionDuration = actionInfo.ExecutionDuration;
     ExtraProperties   = actionInfo.ExtraProperties.ToDictionary(pair => pair.Key, pair => pair.Value);
     ServiceName       = actionInfo.ServiceName.TruncateFromBeginning(AuditLogActionConsts.MaxServiceNameLength);
     MethodName        = actionInfo.MethodName.TruncateFromBeginning(AuditLogActionConsts.MaxMethodNameLength);
     Parameters        = actionInfo.Parameters.Length > AuditLogActionConsts.MaxParametersLength ? "" : actionInfo.Parameters;
 }
예제 #2
0
 public AuditLogAction(string id, string auditLogId, AuditLogActionInfo actionInfo, string tenantId = null)
 {
     Id                = id;
     TenantId          = tenantId;
     AuditLogId        = auditLogId;
     ExecutionTime     = actionInfo.ExecutionTime;
     ExecutionDuration = actionInfo.ExecutionDuration;
     ExtraProperties   = new ExtraPropertyDictionary(actionInfo.ExtraProperties);
     ServiceName       = actionInfo.ServiceName.TruncateFromBeginning(AuditLogActionConsts.MaxServiceNameLength);
     MethodName        = actionInfo.MethodName.TruncateFromBeginning(AuditLogActionConsts.MaxMethodNameLength);
     Parameters        = actionInfo.Parameters.Length > AuditLogActionConsts.MaxParametersLength ? "" : actionInfo.Parameters;
 }
예제 #3
0
        private bool ShouldSaveAudit(ActionExecutingContext context, out AuditLogInfo auditLog,
                                     out AuditLogActionInfo auditLogAction)
        {
            auditLog       = null;
            auditLogAction = null;
            var method = context.HttpContext.Request.Method;

            if (method.Equals(HttpMethod.Options.Method, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (!Options.IsEnabled)
            {
                return(false);
            }

            if (!context.ActionDescriptor.IsControllerAction())
            {
                return(false);
            }

            var auditLogScope = _auditingManager.Current;

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

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

            auditLog          = auditLogScope.Log;
            auditLog.UserId   = _currentUser?.Id;
            auditLog.UserName = _currentUser?.UserName;
            auditLogAction    = _auditingHelper.CreateAuditLogAction(
                auditLog,
                context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(),
                context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo,
                context.ActionArguments
                );

            return(true);
        }
예제 #4
0
    public virtual AuditLogActionInfo CreateAuditLogAction(
        AuditLogInfo auditLog,
        Type type,
        MethodInfo method,
        IDictionary <string, object> arguments)
    {
        var actionInfo = new AuditLogActionInfo
        {
            ServiceName = type != null
                ? type.FullName
                : "",
            MethodName    = method.Name,
            Parameters    = SerializeConvertArguments(arguments),
            ExecutionTime = Clock.Now
        };

        //TODO Execute contributors

        return(actionInfo);
    }
예제 #5
0
        private bool ShouldSaveAudit(ActionExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction)
        {
            auditLog       = null;
            auditLogAction = null;

            if (!Options.IsEnabled)
            {
                return(false);
            }

            if (!context.ActionDescriptor.IsControllerAction())
            {
                return(false);
            }

            var auditLogScope = _auditingManager.Current;

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

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

            auditLog       = auditLogScope.Log;
            auditLogAction = _auditingHelper.CreateAuditLogAction(
                auditLog,
                context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(),
                context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo,
                context.ActionArguments
                );

            return(true);
        }
예제 #6
0
        private bool ShouldSaveAudit(PageHandlerExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction)
        {
            auditLog       = null;
            auditLogAction = null;

            var options = context.GetRequiredService <IOptions <AbpAuditingOptions> >().Value;

            if (!options.IsEnabled)
            {
                return(false);
            }

            if (!context.ActionDescriptor.IsPageAction())
            {
                return(false);
            }

            var auditLogScope = context.GetRequiredService <IAuditingManager>().Current;

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

            var auditingHelper = context.GetRequiredService <IAuditingHelper>();

            if (!auditingHelper.ShouldSaveAudit(context.HandlerMethod.MethodInfo, true))
            {
                return(false);
            }

            auditLog       = auditLogScope.Log;
            auditLogAction = auditingHelper.CreateAuditLogAction(
                auditLog,
                context.HandlerMethod.MethodInfo.DeclaringType,
                context.HandlerMethod.MethodInfo,
                context.HandlerArguments
                );

            return(true);
        }
예제 #7
0
        private bool ShouldSaveAudit(PageHandlerExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction)
        {
            auditLog       = null;
            auditLogAction = null;

            if (!Options.IsEnabled)
            {
                return(false);
            }

            if (!context.ActionDescriptor.IsPageAction())
            {
                return(false);
            }

            var auditLogScope = _auditingManager.Current;

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

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

            auditLog       = auditLogScope.Log;
            auditLogAction = _auditingHelper.CreateAuditLogAction(
                auditLog,
                context.HandlerMethod.GetType(),
                context.HandlerMethod.MethodInfo,
                context.HandlerArguments
                );

            return(true);
        }
예제 #8
0
    /// <summary>
    /// 判断是否写日志
    /// </summary>
    /// <param name="context"></param>
    /// <param name="auditLog"></param>
    /// <param name="auditLogAction"></param>
    /// <returns></returns>
    private bool ShouldSaveAudit(ActionExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction)
    {
        auditLog       = null;
        auditLogAction = null;

        var options = context.GetRequiredService <IOptions <AuditingOptions> >().Value;

        if (!options.IsEnabled)
        {
            return(false);
        }

        if (!context.ActionDescriptor.IsControllerAction())
        {
            return(false);
        }

        var auditLogScope = context.GetService <IAuditingManager>()?.Current;

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

        var auditingFactory = context.GetRequiredService <IAuditingFactory>();

        if (!auditingFactory.ShouldSaveAudit(context.ActionDescriptor.GetMethodInfo(), true))
        {
            return(false);
        }

        auditLog       = auditLogScope.Log;
        auditLogAction = auditingFactory.CreateAuditLogAction(
            auditLog,
            context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(),
            context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo,
            context.ActionArguments
            );

        return(true);
    }
예제 #9
0
        private bool ShouldSaveAudit(ActionExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction)
        {
            auditLog       = null;
            auditLogAction = null;

            if (!Options.IsEnabled)
            {
                return(false);
            }

            if (!context.ActionDescriptor.IsControllerAction())
            {
                return(false);
            }

            var auditLogScope = _auditingManager.Current;

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

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

            //TODO: This is partially duplication of AuditHelper.ShouldSaveAudit method. Check why it does not work for controllers
            if (!AuditingInterceptorRegistrar.ShouldAuditTypeByDefault(context.Controller.GetType()))
            {
                return(false);
            }

            auditLog       = auditLogScope.Log;
            auditLogAction = _auditingHelper.CreateAuditLogAction(
                context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(),
                context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo,
                context.ActionArguments
                );

            return(true);
        }