/// <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; }
public AuditingHelper( IAuditingConfiguration configuration, IAuditSerializer auditSerializer) { _configuration = configuration; _auditSerializer = auditSerializer; }
public TestController(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; ILocalizationConfiguration LocalizationConfiguration = _serviceProvider.GetRequiredService <ILocalizationConfiguration>(); IEmailSenderConfiguration EmailSenderConfiguration = _serviceProvider.GetRequiredService <IEmailSenderConfiguration>(); IAuditingConfiguration AuditingConfiguration = _serviceProvider.GetRequiredService <IAuditingConfiguration>(); }
public AbpApiAuditFilter(IAuditingHelper auditingHelper, IAuditingConfiguration auditingConfiguration, IAuditSerializer auditSerializer) { _auditingHelper = auditingHelper; _auditingConfiguration = auditingConfiguration; _auditSerializer = auditSerializer; }
public AbpAuditActionFilter(IAuditingConfiguration auditingConfiguration) { _auditingConfiguration = auditingConfiguration; AbpSession = NullAbpSession.Instance; AuditingStore = SimpleLogAuditingStore.Instance; AuditInfoProvider = NullAuditInfoProvider.Instance; Logger = NullLogger.Instance; }
public AuditingInterceptor(IAuditingConfiguration configuration, IAuditInfoProvider auditInfoProvider) { _configuration = configuration; _auditInfoProvider = auditInfoProvider; AbpSession = NullAbpSession.Instance; Logger = NullLogger.Instance; AuditingStore = SimpleLogAuditingStore.Instance; }
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); }
public AuditingInterceptor( IAuditingHelper auditingHelper, IAuditingConfiguration auditingConfiguration, IAuditSerializer auditSerializer) { _auditingHelper = auditingHelper; _auditingConfiguration = auditingConfiguration; _auditSerializer = auditSerializer; }
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; }
public AbpAuditPageFilter(IAbpAspNetCoreConfiguration configuration, IAuditingHelper auditingHelper, IAuditingConfiguration auditingConfiguration, IAuditSerializer auditSerializer) { _configuration = configuration; _auditingHelper = auditingHelper; _auditingConfiguration = auditingConfiguration; _auditSerializer = auditSerializer; }
public AuditingInterceptor(IAuditingConfiguration configuration, IAuditInfoProvider auditInfoProvider, IUnitOfWorkManager unitOfWorkManager) { _configuration = configuration; _auditInfoProvider = auditInfoProvider; _unitOfWorkManager = unitOfWorkManager; HozaruSession = NullHozaruSession.Instance; Logger = NullLogger.Instance; AuditingStore = SimpleLogAuditingStore.Instance; }
public AuditingHelper(IAuditInfoProvider auditInfoProvider, IAuditingConfiguration configuration, IUnitOfWorkManager unitOfWorkManager) { _auditInfoProvider = auditInfoProvider; _configuration = configuration; _unitOfWorkManager = unitOfWorkManager; Session = NullInfrastructureSession.Instance; Logger = NullLogger.Instance; AuditingStore = SimpleLogAuditingStore.Instance; }
public AuditingInterceptor(IAuditingConfiguration configuration, IAuditInfoProvider auditInfoProvider, IUnitOfWorkManager unitOfWorkManager) { _configuration = configuration; _auditInfoProvider = auditInfoProvider; _unitOfWorkManager = unitOfWorkManager; OwSession = NullOwSession.Instance; Logger = NullLogger.Instance; AuditingStore = SimpleLogAuditingStore.Instance; }
public AbpMvcAuditFilter(IAbpMvcConfiguration configuration, IAuditingHelper auditingHelper, IAuditingConfiguration auditingConfiguration, IAuditSerializer auditSerializer) { _configuration = configuration; _auditingHelper = auditingHelper; _auditingConfiguration = auditingConfiguration; _auditSerializer = auditSerializer; }
public static void Initialize(IIocManager iocManager) { _auditingConfiguration = iocManager.Resolve<IAuditingConfiguration>(); if (!_auditingConfiguration.IsEnabled) { return; } iocManager.IocContainer.Kernel.ComponentRegistered += Kernel_ComponentRegistered; }
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; }
public static void Initialize(IIocManager iocManager) { _auditingConfiguration = iocManager.Resolve <IAuditingConfiguration>(); if (!_auditingConfiguration.IsEnabled) { return; } iocManager.IocContainer.Kernel.ComponentRegistered += Kernel_ComponentRegistered; }
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; }
public AuditingHelper( IAuditInfoProvider auditInfoProvider, IAuditingConfiguration configuration, IUnitOfWorkManager unitOfWorkManager) { _auditInfoProvider = auditInfoProvider; _configuration = configuration; _unitOfWorkManager = unitOfWorkManager; AbpSession = NullAbpSession.Instance; Logger = NullLogger.Instance; AuditingStore = SimpleLogAuditingStore.Instance; }
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); }
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; }
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; }
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; }
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); }
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); }
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; }
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; }
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); }
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; }
public JsonNetAuditSerializer(IAuditingConfiguration configuration) { _configuration = configuration; }
private bool ShouldSaveAudit(ActionExecutingContext actionContext, IAuditingConfiguration configuration) { return(AuditingHelper.ShouldSaveAudit(configuration, actionContext.HttpContext.User, actionContext.GetExecuteFunction(), actionContext.ActionDescriptor.GetMethodInfo())); }
public AuditingInterceptorRegistrar(IAuditingConfiguration auditingConfiguration, IIocManager iocManager) { _auditingConfiguration = auditingConfiguration; _iocManager = iocManager; }
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); } } }
public AuditingInterceptorRegistrar(IIocManager iocManager) { _iocManager = iocManager; _auditingConfiguration = _iocManager.Resolve <IAuditingConfiguration>(); }
public AuditingInterceptorRegistrar(IIocManager iocManager) { _iocManager = iocManager; _auditingConfiguration = _iocManager.Resolve<IAuditingConfiguration>(); }
public AbpAuditActionFilter(IAuditingConfiguration auditingConfiguration, IAuditingHelper auditingHelper) { _auditingConfiguration = auditingConfiguration; _auditingHelper = auditingHelper; }
/// <summary> /// Auditing configuration /// </summary> public FluentApplicationBootstrapConfiguration AddAuditingConfiguration(IAuditingConfiguration auditingConfiguration) { AuditingConfiguration = auditingConfiguration; return(this); }