ABP框架系列之十二:(Audit-Logging-审计日志)
Introduction
Wikipedia: "An audit trail (also called audit log) is a security-relevant chronological record, set of records, and/or destination and source of records that provide documentary evidence of the sequence of activities that have affected at any time a specific operation, procedure, or event".
维基百科:“审计跟踪(又称审计日志)是一个与安全有关的时间记录、记录集和/或目的地和记录来源,它们提供随时影响特定操作、程序或事件的活动序列的书面证据。”。
ASP.NET Boilerplate provides an infrastructure to automatically log all interactions with the application. It can record intended method calls with caller info and arguments.
Basically, saved fields are: Related tenant id, caller user id, called service name (the class of the called method), called method name, execution parameters (serialized into JSON), execution time, execution duration(as milliseconds), client IP address, client's computer name and the exception (if method throws an exception).
Wtih these informations, we not just know who did the operation, also can measure performance of the application and observe exceptions thrown. Even more, you can get statistics about usage of your application.
Auditing system uses IAbpSessionto get current UserId and TenantId.
Application service, MVC Controller, Web API and ASP.NET Core methods are automatically audited by default.
ASP.NET样板提供了一个基础,记录所有的交互的应用程序自动。它可以用调用者的信息和参数记录预定的方法调用。
基本上,保存的字段是:相关的租户ID、调用方用户ID、被调用的服务名称(被调用方法的类)、方法名、执行参数(序列化为JSON)、执行时间、执行时间(如毫秒)、客户机IP地址、客户端计算机名和异常(如果方法抛出异常)。
使用这些信息,我们不知道谁做的操作,也可以测量的应用性能和观察中引发的异常。更甚者,您可以获得有关应用程序使用情况的统计数据。
审计系统采用iabpsession获取当前用户名和tenantid。
应用服务,MVC控制器,Web API和ASP.NET的核心方法是自动审核,默认。
About IAuditingStore
Auditing system uses IAuditingStore to save audit informations. While you can implement it in your own way, it's fully implemented in module-zero project. If you don't implement it, SimpleLogAuditingStore is used and it writes audit informations to the log.
审计系统采用iauditingstore保存审计信息。虽然可以以自己的方式实现它,但它完全在模块为零的项目中实现。如果你不执行它,SimpleLogAuditingStore用它写审计信息的日志。
Configuration
To configure auditing, you can use Configuration.Auditing property in your module's PreInitialize method. Auditing is enabled by default. You can disable it as shown below.
配置审计,你可以使用配置。在你的模块的属性审计分发方法。默认情况下启用审核。您可以禁用它,如下所示。
public class MyModule : AbpModule
{
public override void PreInitialize()
{
Configuration.Auditing.IsEnabled = false;
} //...
}
Here, a list of auditing configuration properties:
- IsEnabled: Used to enable/disable auditing system completely. Default: true.
- IsEnabledForAnonymousUsers: If this is set to true, audit logs are saved also for users those are not logged in to the system. Default: false.
- Selectors: Used to select other classes to save audit logs.
下面是审核配置属性的列表:
是否启用:用于启用/禁用审计系统完全。默认值:true。
isenabledforanonymoususers:如果设置为true,审计日志的保存也为用户未登录到系统中。默认值:false。
选择器:用于选择其他类以保存审计日志。
Selectors is a list of predicates to select other types to save audit logs. A selector has a unique name and a predicate. The only default selector in this list is used to select application service classes. It's defined as shown below:
选择器是一个谓词列表,用于选择其他类型以保存审计日志。选择器有唯一的名称和谓词。此列表中惟一的默认选择器用于选择应用程序服务类。它的定义如下所示:
Configuration.Auditing.Selectors.Add(
new NamedTypeSelector(
"Abp.ApplicationServices",
type => typeof (IApplicationService).IsAssignableFrom(type)
)
);
You can add your selectors in your module's PreInitialize method. Also, you can remove the selector above by name if you don't like to save audit logs for application services. That's why it has a unique name (Use simple LINQ to find the selector in Selectors and remove it if you want).
Note: In addition to standard audit configuration, MVC and ASP.NET Core modules define configuration to enable/disable audit logging for actions.
你可以在你的模块的添加您选择分发方法。此外,如果不希望为应用程序服务保存审核日志,则可以按名称删除上面的选择器。这就是为什么它有一个唯一的名称(使用简单的LINQ to找到选择器选择器和如果你想删除它)。
注:除了标准的审计结构、MVC和ASP.NET核心模块定义配置启用/禁用活动的日志审计。
Enable/Disable by attributes
While you can select auditing classes by configuration, you can use Audited and DisableAuditing attributes for a single class, a single method. An example:
虽然你可以选择审计类的配置,您可以使用审核和disableauditing属性为一个类,一个单一的方法。一个例子:
[Audited]
public class MyClass
{
public void MyMethod1(int a)
{
//...
} [DisableAuditing]
public void MyMethod2(string b)
{
//...
} public void MyMethod3(int a, int b)
{
//...
}
}
All methods of MyClass are audited except MyMethod2 since it's explicitly disabled. Audited attribute can be used for a method to just save audits for the desired method.
DisableAuditing can also be used for or a single property of a DTO. Thus, you can hide sensitive data in audit logs, such as passwords for example.
所有的方法除了mymethod2 MyClass审计因为它明确禁用。已审核的属性可用于只保存所需方法的审核的方法。
disableauditing也可以用于单个属性或一个DTO。因此,可以将敏感数据隐藏在审计日志中,例如密码。
Notes(注意)
- A method must be public in order to saving audit logs. Private and protected methods are ignored.
- A method must be virtual if it's called over class reference. This is not needed if it's injected using it's interface (like injecting IPersonService interface to use PersonService class). This is needed since ASP.NET Boilerplate uses dynamic proxying and interception. This is not true for MVC Controller actions. They may not be virtual.
为了节省审计日志,必须公开一种方法。私有和受保护的方法被忽略。
如果在类引用上调用它,则方法必须是虚拟的。这是不需要的如果是注射使用的接口(如注射ipersonservice接口使用人的服务类)。这是自ASP.NET样板使用动态代理和拦截需要。MVC控制器的操作不是这样的。它们可能不是虚拟的。
ABP框架系列之十二:(Audit-Logging-审计日志)的更多相关文章
- ABP框架系列之三十二:(Logging-登录)
Server Side(服务端) ASP.NET Boilerplate uses Castle Windsor's logging facility. It can work with differ ...
- ABP框架系列之四十二:(Object-To-Object-Mapping-对象映射)
Introduction It's a common to map a similar object to another object. It's also tedious and repeatin ...
- ABP框架系列之五十二:(Validating-Data-Transfer-Objects-验证数据传输对象)
Introduction to validation Inputs of an application should be validated first. This input can be sen ...
- ABP框架系列之三十九:(NLayer-Architecture-多层架构)
Introduction Layering of an application's codebase is a widely accepted technique to help reduce com ...
- ABP框架系列之三十五:(MVC-Controllers-MVC控制器)
Introduction ASP.NET Boilerplate is integrated to ASP.NET MVC Controllers via Abp.Web.Mvc nuget pack ...
- ABP框架系列之三十四:(Multi-Tenancy-多租户)
What Is Multi Tenancy? "Software Multitenancy refers to a software architecture in which a sing ...
- ABP框架系列之五十四:(XSRF-CSRF-Protection-跨站请求伪造保护)
Introduction "Cross-Site Request Forgery (CSRF) is a type of attack that occurs when a maliciou ...
- ABP框架系列之四十九:(Startup-Configuration-启动配置)
ASP.NET Boilerplate provides an infrastructure and a model to configure it and modules on startup. A ...
- ABP框架系列之十:(Application-Services-应用服务)
Application Services are used to expose domain logic to the presentation layer. An Application Servi ...
随机推荐
- 数据访问安全--数据库遮罩及断词 Data Masking & Tokenization
现在大数据时代几乎无隐私,各政府部门各公司都要求实名制(动不动手机认证,身份证号码认证),但又无力确保数据安全,称为乱象. 其实在2011年,我们就接触过数据库遮罩断词产品,一个澳大利亚公司产品. 简 ...
- SAS 评分卡开发模型变量统计及输出
以下代码实现功能: 1.获取10个模型分别使用哪些变量 2.变量所模型使用的次数 3.把上表格输出到EXCEL中 %INCLUDE '00@HEADER.SAS'; %let dir=..\04@Mo ...
- (整理)MySQL_REHL6.5 MySQL5.5 中文支持问题
1 查看字符集命令 SHOW VARIABLES LIKE ‘character%’; 2 修改my.cnf文件中来实现中文支持 2.1 复制my.cnf 安装结束后,etc目录下并没有my.cnf文 ...
- HashMap与Hashtable
1. 1) Hashtable继承自Dictionary类,HashMap是map接口的一个实现类(继承自AbstractMap抽象类) 2) 在HashMap中,null可以 ...
- Alpha阶段项目规划
Alpha阶段任务 概述 我们团队采访学长并听从学长的意见之后,决定根据第一版的phylab项目进行重构.但由于第一版的phylab项目在github上的代码仅仅只有alpha版本,我们接手之后进行了 ...
- day29单例模式的4种实现模式
单例模式的四种实现模式单例模式实现方式一: import settings class MySQL: __instance=None def __init__(self, ip, port): ...
- attr 和 prop 的区别
在高版本的jquery引入prop方法后,什么时候该用prop?什么时候用attr?它们两个之间有什么区别?这些问题就出现了. 关于它们两个的区别,网上的答案很多.这里谈谈我的心得,我的心得很简单: ...
- 【Linux】【Selenium】安装Chrome和ChromeDriver的配置
转自:https://www.cnblogs.com/longronglang/p/8078898.html 1.安装chrome sudo apt-get install libxss1 libap ...
- 03 字符串常用操作方法及For 循环
字符串常用操作 s = 'alexWUsir' s1 = s.capitalize() #首字母大写 print(s1) #Alexwusir s2 = s.upper() #全部大写 print(s ...
- javascript中let和var的区别
let是es6中新增命令,也是用来声明变量的,可能很多小伙伴都像我一样,定义变量的时候都会用var而很少用到let,那么,let和var到底有什么区别呢? let和var的区别体现在作用域上.var的 ...