コード例 #1
0
        /// <summary>
        /// 应该保存审计
        /// </summary>
        /// <param name="methodInfo">方法信息</param>
        /// <param name="configuration">审计配置</param>
        /// <param name="abpSession">Abp会话</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public static bool ShouldSaveAudit(MethodInfo methodInfo, IAuditingConfiguration configuration, IAbpSession abpSession, bool defaultValue = false)
        {
            //审计配置为null,或审计配置未启用,则返回false
            if (configuration == null || !configuration.IsEnabled)
            {
                return false;
            }

            //如果未启用匿名用户,并且AbpSession为null或用户Id为空,返回false
            if (!configuration.IsEnabledForAnonymousUsers && (abpSession == null || !abpSession.UserId.HasValue))
            {
                return false;
            }

            //如果方法信息为null
            if (methodInfo == null)
            {
                return false;
            }

            //如果方法信息不为公共方法
            if (!methodInfo.IsPublic)
            {
                return false;
            }

            //如果方法使用了AuditedAttribute审计自定义属性,则返回true
            if (methodInfo.IsDefined(typeof(AuditedAttribute)))
            {
                return true;
            }

            //如果方法使用了DisableAuditingAttribute禁用审计自定义属性,则返回false
            if (methodInfo.IsDefined(typeof(DisableAuditingAttribute)))
            {
                return false;
            }

            //获取声明该成员的类
            var classType = methodInfo.DeclaringType;
            if (classType != null)
            {
                if (classType.IsDefined(typeof(AuditedAttribute)))
                {
                    return true;
                }

                if (classType.IsDefined(typeof(DisableAuditingAttribute)))
                {
                    return false;
                }

                if (configuration.Selectors.Any(selector => selector.Predicate(classType)))
                {
                    return true;
                }
            }

            return defaultValue;
        }
コード例 #2
0
 public AuditingHelper(
     IAuditingConfiguration configuration,
     IAuditSerializer auditSerializer)
 {
     _configuration   = configuration;
     _auditSerializer = auditSerializer;
 }
コード例 #3
0
 public TestController(IServiceProvider serviceProvider)
 {
     _serviceProvider = serviceProvider;
     ILocalizationConfiguration LocalizationConfiguration = _serviceProvider.GetRequiredService <ILocalizationConfiguration>();
     IEmailSenderConfiguration  EmailSenderConfiguration  = _serviceProvider.GetRequiredService <IEmailSenderConfiguration>();
     IAuditingConfiguration     AuditingConfiguration     = _serviceProvider.GetRequiredService <IAuditingConfiguration>();
 }
コード例 #4
0
 public AbpApiAuditFilter(IAuditingHelper auditingHelper,
                          IAuditingConfiguration auditingConfiguration,
                          IAuditSerializer auditSerializer)
 {
     _auditingHelper        = auditingHelper;
     _auditingConfiguration = auditingConfiguration;
     _auditSerializer       = auditSerializer;
 }
コード例 #5
0
        public AbpAuditActionFilter(IAuditingConfiguration auditingConfiguration)
        {
            _auditingConfiguration = auditingConfiguration;

            AbpSession        = NullAbpSession.Instance;
            AuditingStore     = SimpleLogAuditingStore.Instance;
            AuditInfoProvider = NullAuditInfoProvider.Instance;
            Logger            = NullLogger.Instance;
        }
コード例 #6
0
        public AbpAuditActionFilter(IAuditingConfiguration auditingConfiguration)
        {
            _auditingConfiguration = auditingConfiguration;

            AbpSession = NullAbpSession.Instance;
            AuditingStore = SimpleLogAuditingStore.Instance;
            AuditInfoProvider = NullAuditInfoProvider.Instance;
            Logger = NullLogger.Instance;
        }
コード例 #7
0
 public AuditingInterceptor(IAuditingConfiguration configuration, IAuditInfoProvider auditInfoProvider)
 {
     _configuration = configuration;
     _auditInfoProvider = auditInfoProvider;
     
     AbpSession = NullAbpSession.Instance;
     Logger = NullLogger.Instance;
     AuditingStore = SimpleLogAuditingStore.Instance;
 }
コード例 #8
0
        public static bool ShouldSaveAudit <TTenantId, TUserId>(MethodInfo methodInfo,
                                                                IAuditingConfiguration configuration, IAbpSession <TTenantId, TUserId> abpSession, bool defaultValue = false)
            where TTenantId : struct
            where TUserId : struct
        {
            if (configuration == null || !configuration.IsEnabled)
            {
                return(false);
            }

            if (!configuration.IsEnabledForAnonymousUsers && (abpSession == null || !abpSession.UserId.HasValue))
            {
                return(false);
            }

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

            if (!methodInfo.IsPublic)
            {
                return(false);
            }

            if (methodInfo.IsDefined(typeof(AuditedAttribute)))
            {
                return(true);
            }

            if (methodInfo.IsDefined(typeof(DisableAuditingAttribute)))
            {
                return(false);
            }

            var classType = methodInfo.DeclaringType;

            if (classType != null)
            {
                if (classType.IsDefined(typeof(AuditedAttribute)))
                {
                    return(true);
                }

                if (classType.IsDefined(typeof(DisableAuditingAttribute)))
                {
                    return(false);
                }

                if (configuration.Selectors.Any(selector => selector.Predicate(classType)))
                {
                    return(true);
                }
            }

            return(defaultValue);
        }
コード例 #9
0
        public AuditingInterceptor(IAuditingConfiguration configuration, IAuditInfoProvider auditInfoProvider)
        {
            _configuration     = configuration;
            _auditInfoProvider = auditInfoProvider;

            AbpSession    = NullAbpSession.Instance;
            Logger        = NullLogger.Instance;
            AuditingStore = SimpleLogAuditingStore.Instance;
        }
コード例 #10
0
 public AuditingInterceptor(
     IAuditingHelper auditingHelper,
     IAuditingConfiguration auditingConfiguration,
     IAuditSerializer auditSerializer)
 {
     _auditingHelper        = auditingHelper;
     _auditingConfiguration = auditingConfiguration;
     _auditSerializer       = auditSerializer;
 }
コード例 #11
0
ファイル: AuditHelper.cs プロジェクト: wenpengpeng/April
 public AuditHelper(IAuditInfoProvider auditInfoProvider, IAuditingConfiguration configuration, IUnitOfWorkManager unitOfWorkManager, IAuditSerializer auditSerializer, IAuditingStore auditingStore)
 {
     _auditInfoProvider = auditInfoProvider;
     _configuration     = configuration;
     _unitOfWorkManager = unitOfWorkManager;
     _auditSerializer   = auditSerializer;
     _auditingStore     = auditingStore;
     Logger             = NullLogger.Instance;
 }
コード例 #12
0
 public AbpAuditPageFilter(IAbpAspNetCoreConfiguration configuration,
                           IAuditingHelper auditingHelper,
                           IAuditingConfiguration auditingConfiguration,
                           IAuditSerializer auditSerializer)
 {
     _configuration         = configuration;
     _auditingHelper        = auditingHelper;
     _auditingConfiguration = auditingConfiguration;
     _auditSerializer       = auditSerializer;
 }
コード例 #13
0
        public AuditingInterceptor(IAuditingConfiguration configuration, IAuditInfoProvider auditInfoProvider, IUnitOfWorkManager unitOfWorkManager)
        {
            _configuration     = configuration;
            _auditInfoProvider = auditInfoProvider;
            _unitOfWorkManager = unitOfWorkManager;

            HozaruSession = NullHozaruSession.Instance;
            Logger        = NullLogger.Instance;
            AuditingStore = SimpleLogAuditingStore.Instance;
        }
コード例 #14
0
ファイル: AuditingHelper.cs プロジェクト: llenroc/Movie
        public AuditingHelper(IAuditInfoProvider auditInfoProvider, IAuditingConfiguration configuration, IUnitOfWorkManager unitOfWorkManager)
        {
            _auditInfoProvider = auditInfoProvider;
            _configuration     = configuration;
            _unitOfWorkManager = unitOfWorkManager;

            Session       = NullInfrastructureSession.Instance;
            Logger        = NullLogger.Instance;
            AuditingStore = SimpleLogAuditingStore.Instance;
        }
コード例 #15
0
        public AuditingInterceptor(IAuditingConfiguration configuration, IAuditInfoProvider auditInfoProvider, IUnitOfWorkManager unitOfWorkManager)
        {
            _configuration = configuration;
            _auditInfoProvider = auditInfoProvider;
            _unitOfWorkManager = unitOfWorkManager;

            OwSession = NullOwSession.Instance;
            Logger = NullLogger.Instance;
            AuditingStore = SimpleLogAuditingStore.Instance;
        }
コード例 #16
0
 public AbpMvcAuditFilter(IAbpMvcConfiguration configuration,
                          IAuditingHelper auditingHelper,
                          IAuditingConfiguration auditingConfiguration,
                          IAuditSerializer auditSerializer)
 {
     _configuration         = configuration;
     _auditingHelper        = auditingHelper;
     _auditingConfiguration = auditingConfiguration;
     _auditSerializer       = auditSerializer;
 }
コード例 #17
0
        public static void Initialize(IIocManager iocManager)
        {
            _auditingConfiguration = iocManager.Resolve<IAuditingConfiguration>();

            if (!_auditingConfiguration.IsEnabled)
            {
                return;
            }

            iocManager.IocContainer.Kernel.ComponentRegistered += Kernel_ComponentRegistered;
        }
コード例 #18
0
        public AuditingInterceptor(IAuditingConfiguration configuration, IAuditInfoProvider auditInfoProvider,
                                   IUnitOfWorkManager <TTenantId, TUserId> unitOfWorkManager)
        {
            _configuration     = configuration;
            _auditInfoProvider = auditInfoProvider;
            _unitOfWorkManager = unitOfWorkManager;

            AbpSession    = NullAbpSession <TTenantId, TUserId> .Instance;
            Logger        = NullLogger.Instance;
            AuditingStore = SimpleLogAuditingStore <TTenantId, TUserId> .Instance;
        }
コード例 #19
0
        public static void Initialize(IIocManager iocManager)
        {
            _auditingConfiguration = iocManager.Resolve <IAuditingConfiguration>();

            if (!_auditingConfiguration.IsEnabled)
            {
                return;
            }

            iocManager.IocContainer.Kernel.ComponentRegistered += Kernel_ComponentRegistered;
        }
コード例 #20
0
ファイル: AuditingHelper.cs プロジェクト: dazyzsy/ZBP
        public static bool ShouldSaveAudit(MethodInfo methodInfo, IAuditingConfiguration configuration, IZbpSession abpSession, bool defaultValue = false)
        {
            if (configuration == null || !configuration.IsEnabled)
            {
                return false;
            }

            if (!configuration.IsEnabledForAnonymousUsers && (abpSession == null || !abpSession.UserId.HasValue))
            {
                return false;
            }

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

            if (!methodInfo.IsPublic)
            {
                return false;
            }

            if (methodInfo.IsDefined(typeof(AuditedAttribute)))
            {
                return true;
            }

            if (methodInfo.IsDefined(typeof(DisableAuditingAttribute)))
            {
                return false;
            }

            var classType = methodInfo.DeclaringType;
            if (classType != null)
            {
                if (classType.IsDefined(typeof(AuditedAttribute)))
                {
                    return true;
                }

                if (classType.IsDefined(typeof(DisableAuditingAttribute)))
                {
                    return false;
                }

                if (configuration.Selectors.Any(selector => selector.Predicate(classType)))
                {
                    return true;
                }
            }

            return defaultValue;
        }
コード例 #21
0
        public AuditingHelper(
            IAuditInfoProvider auditInfoProvider, 
            IAuditingConfiguration configuration, 
            IUnitOfWorkManager unitOfWorkManager)
        {
            _auditInfoProvider = auditInfoProvider;
            _configuration = configuration;
            _unitOfWorkManager = unitOfWorkManager;

            AbpSession = NullAbpSession.Instance;
            Logger = NullLogger.Instance;
            AuditingStore = SimpleLogAuditingStore.Instance;
        }
コード例 #22
0
        private static bool ShouldIntercept(IAuditingConfiguration auditingConfiguration, Type type)
        {
            if (type.GetTypeInfo().IsDefined(typeof(AuditedAttribute), true))
            {
                return(true);
            }

            if (type.GetMethods().Any(m => m.IsDefined(typeof(AuditedAttribute), true)))
            {
                return(true);
            }

            return(false);
        }
コード例 #23
0
        public AuditingHelper(
            IAuditInfoProvider auditInfoProvider,
            IAuditingConfiguration configuration,
            IUnitOfWorkManager unitOfWorkManager,
            IAuditSerializer auditSerializer)
        {
            _auditInfoProvider = auditInfoProvider;
            _configuration     = configuration;
            _unitOfWorkManager = unitOfWorkManager;
            _auditSerializer   = auditSerializer;

            CodeZeroSession = NullCodeZeroSession.Instance;
            Logger          = NullLogger.Instance;
            AuditingStore   = SimpleLogAuditingStore.Instance;
        }
コード例 #24
0
ファイル: AuditingHelper.cs プロジェクト: war-man/HawaDNS
        public AuditingHelper(
            IAuditInfoProvider auditInfoProvider,
            IAuditingStore auditingStore,
            IAuditingConfiguration configuration,
            IBysSession bysSession,
            IAuditSerializer auditSerializer)
        {
            _auditInfoProvider = auditInfoProvider;
            _configuration     = configuration;
            _auditSerializer   = auditSerializer;

            BysSession    = bysSession;
            Logger        = NullLogger.Instance;
            AuditingStore = auditingStore;
        }
コード例 #25
0
        public AuditingHelper(
            IAuditInfoProvider auditInfoProvider,
            IAuditingConfiguration configuration,
            IUnitOfWorkManager unitOfWorkManager,
            IAuditSerializer auditSerializer)
        {
            this._auditInfoProvider = auditInfoProvider;
            this._configuration     = configuration;
            this._unitOfWorkManager = unitOfWorkManager;
            this._auditSerializer   = auditSerializer;

            this.AbpSession    = NullAbpSession.Instance;
            this.Logger        = NullLogger.Instance;
            this.AuditingStore = SimpleLogAuditingStore.Instance;
        }
コード例 #26
0
        public static bool ShouldSaveAudit(IAuditingConfiguration configuration, ClaimsPrincipal principal, IFunction function, MethodInfo methodInfo)
        {
            if (!configuration.IsEnabled)
            {
                return(false);
            }

            if (!configuration.IsEnabledForAnonymousUsers && (!(principal.Identity.IsAuthenticated && principal.Identity is ClaimsIdentity identity)))
            {
                return(false);
            }

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

            if (!methodInfo.IsPublic)
            {
                return(false);
            }

            if (methodInfo.IsDefined(typeof(AuditedAttribute), true))
            {
                return(true);
            }

            if (methodInfo.IsDefined(typeof(DisableAuditingAttribute), true))
            {
                return(false);
            }

            var classType = methodInfo.DeclaringType;

            if (classType != null)
            {
                if (classType.GetTypeInfo().IsDefined(typeof(AuditedAttribute), true))
                {
                    return(true);
                }

                if (classType.GetTypeInfo().IsDefined(typeof(DisableAuditingAttribute), true))
                {
                    return(false);
                }
            }
            return(function.AuditOperationEnabled);
        }
コード例 #27
0
        private static bool ShouldIntercept(IAuditingConfiguration auditingConfiguration, Type type)
        {
            if (auditingConfiguration.Selectors.Any(selector => selector.Predicate(type)))
            {
                return(true);
            }

            if (type.IsDefined(typeof(AuditedAttribute), true))
            {
                return(true);
            }

            if (type.GetMethods().Any(m => m.IsDefined(typeof(AuditedAttribute), true)))
            {
                return(true);
            }
            return(false);
        }
コード例 #28
0
        private static bool ShouldIntercept(IAuditingConfiguration auditingConfiguration, Type type)
        {
            if (auditingConfiguration.Selectors.Any(selector => selector.Predicate(type)))
            {
                return true;
            }

            if (type.IsDefined(typeof(AuditedAttribute), true))
            {
                return true;
            }

            if (type.GetMethods().Any(m => m.IsDefined(typeof(AuditedAttribute), true)))
            {
                return true;
            }

            return false;
        }
コード例 #29
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            IServiceProvider provider = context.HttpContext.RequestServices;
            IFunction        function = context.GetExecuteFunction();

            if (function == null)
            {
                return;
            }
            ScopedDictionary dict = provider.GetService <ScopedDictionary>();

            dict.Function = function;
            // 数据权限有效角色,即有当前功能权限的角色
            IFunctionAuthorization functionAuthorization = provider.GetService <IFunctionAuthorization>();
            ClaimsPrincipal        principal             = context.HttpContext.User;

            string[] roleName = functionAuthorization.GetOkRoles(function, principal);
            dict.DataAuthValidRoleNames = roleName;
            IAuditingConfiguration configuration = provider.GetRequiredService <IAuditingConfiguration>();

            if (!AuditingHelper.ShouldSaveAudit(configuration, principal, function, context.ActionDescriptor.GetMethodInfo()))
            {
                return;
            }
            AuditOperationEntry operation = new AuditOperationEntry
            {
                FunctionName    = function.Name,
                ClientIpAddress = context.HttpContext.GetClientIp(),
                UserAgent       = context.HttpContext.Request.Headers["User-Agent"].FirstOrDefault(),
                CreatedTime     = DateTime.Now
            };

            if (principal.Identity.IsAuthenticated && principal.Identity is ClaimsIdentity identity)
            {
                operation.UserId   = identity.GetUserId();
                operation.UserName = identity.GetUserName();
                operation.NickName = identity.GetNickName();
            }

            dict.AuditOperation = operation;
        }
コード例 #30
0
        private static bool ShouldIntercept(IAuditingConfiguration auditingConfiguration, Type type)
        {
            // 如果这个类是auditingConfiguration.Selectors里面的类,那么应该截断记录审计日志
            if (auditingConfiguration.Selectors.Any(selector => selector.Predicate(type)))
            {
                return(true);
            }

            // 如果这个类被AuditedAttribute修饰了,那么应该截断记录审计日志
            if (type.IsDefined(typeof(AuditedAttribute), true))
            {
                return(true);
            }

            // 如果这个类有方法用AuditedAttribute修饰了得话,那么应该截断记录审计日志
            if (type.GetMethods().Any(m => m.IsDefined(typeof(AuditedAttribute), true)))
            {
                return(true);
            }

            return(false);
        }
コード例 #31
0
ファイル: AuditingHelper.cs プロジェクト: stwilson123/Blocks
        public AuditingHelper(
            IAuditInfoProvider auditInfoProvider,
            IAuditingConfiguration configuration,
            IUnitOfWorkManager unitOfWorkManager,
            IAuditSerializer auditSerializer,
            LocalzaionHelper localzaionHelper,
            IUserContext userContext,
            LocalizedSerializer localizedSerializer
            )
        {
            _auditInfoProvider   = auditInfoProvider;
            _configuration       = configuration;
            _unitOfWorkManager   = unitOfWorkManager;
            _auditSerializer     = auditSerializer;
            _localzaionHelper    = localzaionHelper;
            _userContext         = userContext;
            _localizedSerializer = localizedSerializer;

            AbpSession    = NullAbpSession.Instance;
            Logger        = NullLogger.Instance;
            AuditingStore = SimpleLogAuditingStore.Instance;
        }
コード例 #32
0
 public JsonNetAuditSerializer(IAuditingConfiguration configuration)
 {
     _configuration = configuration;
 }
コード例 #33
0
 private bool ShouldSaveAudit(ActionExecutingContext actionContext, IAuditingConfiguration configuration)
 {
     return(AuditingHelper.ShouldSaveAudit(configuration, actionContext.HttpContext.User, actionContext.GetExecuteFunction(), actionContext.ActionDescriptor.GetMethodInfo()));
 }
コード例 #34
0
 public AuditingInterceptorRegistrar(IAuditingConfiguration auditingConfiguration, IIocManager iocManager)
 {
     _auditingConfiguration = auditingConfiguration;
     _iocManager = iocManager;
 }
コード例 #35
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            IAuditingConfiguration configuration = _provider.GetRequiredService <IAuditingConfiguration>();

            if (!ShouldSaveAudit(context, configuration))
            {
                await next();

                return;
            }

            using (CrossCuttingConcerns.Applying(context.Controller, CrossCuttingConcerns.Auditing))
            {
                IAuditStore store    = _provider.GetService <IAuditStore>();
                IFunction   function = context.GetExecuteFunction();
                //var auditInfo = store.CreateAuditInfo(
                //    context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(),
                //    context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo,
                //    context.ActionArguments
                //);
                Type                type         = context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType();
                List <Type>         ignoredTypes = configuration.IgnoredTypes;
                AuditOperationEntry operation    = new AuditOperationEntry
                {
                    FunctionName    = function.Name,
                    ClientIpAddress = context.HttpContext.GetClientIp(),
                    UserAgent       = context.HttpContext.Request.Headers["User-Agent"].FirstOrDefault(),
                    CreatedTime     = DateTime.Now,
                    ServiceName     = type != null
                    ? type.FullName
                    : "",
                    Parameters = ConvertArgumentsToJson(context.ActionArguments, ignoredTypes),
                };
                if (context.HttpContext.User.Identity.IsAuthenticated && context.HttpContext.User.Identity is ClaimsIdentity identity)
                {
                    operation.UserId   = identity.GetUserId();
                    operation.UserName = identity.GetUserName();
                }

                var stopwatch = Stopwatch.StartNew();

                ActionExecutedContext result = null;
                try
                {
                    result = await next();

                    if (result.Exception != null && !result.ExceptionHandled)
                    {
                        operation.Exception = result.Exception;
                    }
                }
                catch (Exception ex)
                {
                    operation.Exception = ex;
                    throw;
                }
                finally
                {
                    stopwatch.Stop();
                    operation.Elapsed = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);

                    if (configuration.SaveReturnValues && result != null)
                    {
                        switch (result.Result)
                        {
                        case ObjectResult objectResult:
                            operation.ReturnValue = AuditingHelper.Serialize(objectResult.Value, ignoredTypes);
                            break;

                        case JsonResult jsonResult:
                            operation.ReturnValue = AuditingHelper.Serialize(jsonResult.Value, ignoredTypes);
                            break;

                        case ContentResult contentResult:
                            operation.ReturnValue = contentResult.Content;
                            break;

                        case AjaxResult ajaxResult:
                            operation.ReturnValue = ajaxResult.Content;
                            break;
                        }
                    }

                    await store.SaveAsync(operation);
                }
            }
        }
コード例 #36
0
 public AuditingInterceptorRegistrar(IIocManager iocManager)
 {
     _iocManager            = iocManager;
     _auditingConfiguration = _iocManager.Resolve <IAuditingConfiguration>();
 }
コード例 #37
0
 public AuditingInterceptorRegistrar(IIocManager iocManager)
 {
     _iocManager = iocManager;
     _auditingConfiguration = _iocManager.Resolve<IAuditingConfiguration>();
 }
コード例 #38
0
 public AbpAuditActionFilter(IAuditingConfiguration auditingConfiguration, IAuditingHelper auditingHelper)
 {
     _auditingConfiguration = auditingConfiguration;
     _auditingHelper        = auditingHelper;
 }
コード例 #39
0
 /// <summary>
 /// Auditing configuration
 /// </summary>
 public FluentApplicationBootstrapConfiguration AddAuditingConfiguration(IAuditingConfiguration auditingConfiguration)
 {
     AuditingConfiguration = auditingConfiguration;
     return(this);
 }
コード例 #40
0
 public AbpAuditActionFilter(IAuditingConfiguration auditingConfiguration, IAuditingHelper auditingHelper)
 {
     _auditingConfiguration = auditingConfiguration;
     _auditingHelper = auditingHelper;
 }
コード例 #41
0
 public AuditingInterceptorRegistrar(IAuditingConfiguration auditingConfiguration, IIocManager iocManager)
 {
     _auditingConfiguration = auditingConfiguration;
     _iocManager            = iocManager;
 }