简体   繁体   English

如何在 Java/GWT Web 应用程序中实现 Log4j-audit

[英]How to implement Log4j-audit in Java/GWT web app

Currently working on implementing audit logging for a web app and would like to use log4j-audit.目前正在为 Web 应用程序实施审计日志记录,并希望使用 log4j-audit。 The app is written using OpenJDK 8 and GWT 2.7 hosted by Jboss 6.4 and built using Ant 1.10.5.该应用程序使用由 Jboss 6.4 托管的 OpenJDK 8 和 GWT 2.7 编写,并使用 Ant 1.10.5 构建。 My question is how does one implement the log4j-audit framework into our current structure?我的问题是如何将 log4j-audit 框架实现到我们当前的结构中? I have worked through the getting started section and read the documentation exhaustively but my lack of Maven experience is making it difficult transporting it to our stack.我已经完成了入门部分并详尽地阅读了文档,但由于我缺乏 Maven 经验,因此很难将其传输到我们的堆栈中。

My current understanding is that I need to create a request filter that instantiates a RequestContext object that stores variables in a ThreadContext map.我目前的理解是,我需要创建一个请求过滤器来实例化一个RequestContext对象,该对象在ThreadContext映射中存储变量。 What I need to know is how to use my catalog.json to generate the interfaces that I can reference in my code.我需要知道的是如何使用我的catalog.json来生成我可以在我的代码中引用的接口。

Thanks!谢谢!

EDIT:编辑:

Thanks to the info in section 1. of the marked answer below I was able to create a custom Ant task, with a POM similar to that in the sample app, that builds the audit-service-api.jar and reference the generated sources in my codebase.多亏了下面标记答案的第1.部分中的信息,我能够创建一个自定义 Ant 任务,其 POM 类似于示例应用程序中的 POM,它构建了 audit-service-api.jar 并在我的代码库。

The RequestContextFilter is an extension of the Log4j ThreadContext that allows you to convert headers passed in REST requests into ThreadContext attributes. RequestContextFilter 是 Log4j ThreadContext 的扩展,它允许您将 REST 请求中传递的标头转换为 ThreadContext 属性。 This is important for auditing so that you can pass the user's loginId, IP Address, account number, etc so that they can be included in all the audit events (as well as all the other logs).这对于审计很重要,以便您可以传递用户的 loginId、IP 地址、帐号等,以便它们可以包含在所有审计事件(以及所有其他日志)中。 Although not necessarily important for audit logging, including a requestId and "sessionId" is important for diagnostic and debug logs to correlate logs across services and servers.虽然对于审计日志不一定重要,但包含 requestId 和“sessionId”对于诊断和调试日志很重要,以便将服务和服务器之间的日志关联起来。

The catalog.json file is used to define the audit events and attributes. catalog.json 文件用于定义审计事件和属性。 Normally you would create a project similar to log4j-audit-sample .通常您会创建一个类似于log4j-audit-sample 的项目 This project contains 3 things:这个项目包含3件事:

  1. The Audit Service API - The catalog.json would reside in src/main/resources and contains the definitions of your events and attributes.审计服务 API - catalog.json 将驻留在 src/main/resources 中,并包含事件和属性的定义。 When you run "mvn clean package", "mvn clean install" or "mvn clean deploy" on this project it will read the catalog and generate all the Java interfaces for the events you have defined.当您在该项目上运行“mvn clean package”、“mvn clean install”或“mvn clean deploy”时,它将读取目录并为您定义的事件生成所有 Java 接口。 You would then include the jar constructed from this project in your applications along with the log4j-audit-api jar to log the events.然后,您可以将从此项目构建的 jar 与 log4j-audit-api jar 一起包含在您的应用程序中以记录事件。
  2. The Audit Service - A REST service that can be used to log events from non-Java applications.审计服务 - 一种 REST 服务,可用于记录来自非 Java 应用程序的事件。 The service will validate the events against your catalog.该服务将根据您的目录验证事件。

Log4j-audit comes with a Spring Boot app that can be used as an editor for the catalog as editing the JSON can be tedious and error prone. Log4j-audit 附带一个 Spring Boot 应用程序,可用作目录的编辑器,因为编辑 JSON 可能很乏味且容易出错。 That said, the Spring Boot app needs to be run as a single user desktop app, which is a little odd, so a desktop editor based on ElectronJS is being developed .也就是说,Spring Boot 应用程序需要作为单用户桌面应用程序运行,这有点奇怪,因此正在开发基于 ElectronJS 的桌面编辑器。

Log4j-audit currently supports two formats for the catalog; Log4j-audit 目前支持两种格式的目录; the catalog.json file stored in git or an RDMS catalog accessed via JPA.存储在 git 中的 catalog.json 文件或通过 JPA 访问的 RDMS 目录。 Normally, the catalog stored in git is used to generate the Java interfaces because those should be modified only normally during the normal development process and you would want to manage those definitions with a normal release cycle.通常,存储在 git 中的目录用于生成 Java 接口,因为这些接口只能在正常开发过程中正常修改,并且您希望在正常发布周期中管理这些定义。 The Spring Boot catalog editor reads the json catalog from git and then loads it into an in-memory database so that the editor can take advantage of the referential integrity the database provides. Spring Boot 目录编辑器从 git 读取 json 目录,然后将其加载到内存数据库中,以便编辑器可以利用数据库提供的引用完整性。 The Audit Service can be configured to use a database to store a "dynamic catalog".审计服务可以配置为使用数据库来存储“动态目录”。 No Java interfaces are available for these catalog entries and applications that want to perform auditing using these event definitions must do it through the audit service.这些目录条目没有可用的 Java 接口,想要使用这些事件定义执行审计的应用程序必须通过审计服务来完成。

Hopefully, that provides the information you are looking for but if you performed the steps in the Getting Started page and look at the sample application you should have an idea of what you need to do.希望这提供了您正在寻找的信息,但如果您执行了入门页面中的步骤并查看示例应用程序,您应该知道您需要做什么。 If not, please follow up with more questions.如果没有,请跟进更多问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM