Coder Social home page Coder Social logo

audit's Introduction

audit

一个通用的 Audit (审计)框架。如果要接入4A审计时,特别方便哟,同时也高度定制化。

maven

教程 : https://fangjinuo.gitee.io/docs/index.html

Features

  1. 操作定义支持多种方式
    • @Operation 注解方式
    • 在 yaml 配置文件配置方法全名的方式
    • 在 yaml 配置文件配置 URL template 的方式
    • 允许自定义
  2. 操作资源获取支持多种方式
    • 在 yaml 配置方法参数名称的方式
    • 支持注解方式
    • 支持List, Map, Entity解析等
    • 支持自定义
  3. 支持 JDK6+
  4. 支持 Java, Web应用

Example

给一个SpringBoot应用快速加上审计功能,也可以直接去参考 audit-examples-springmvcdemo

第一步:引入相关Jar包

    <dependency>
        <groupId>com.github.fangjinuo.audit</groupId>
        <artifactId>audit-spring-boot-starter</artifactId>
        <version>${audit.version}</version>
    </dependency>

第二步:在application.yml中配置审计功能

audit:
  enabled: true     # 开关
  async-mode: false # 异步模式执行,还是同步模式执行,对于 web应用目前暂时强制采用同步模式
  topics: [DEFAULT, LOGIN_LOGOUT]
  topic-configs:
    - name: DEFAULT
      ring-buffer-size: 1024
      producer-type: MULTI
    - name: LOGIN_LOGOUT      # topic的name
      ring-buffer-size: 512   # topic的 ring buffer size ,强制要求是 pow(2)
      producer-type: SINGLE   # 生产者是单线程,还是多线程,可选值是 SINGLE,MULTI
  http-interceptor-patterns:  # Spring MVC HandlerInterceptor的拦截 pathPatterns
    - /consumers/**
    - /users/**

第三步:设置操作定义 参考 audit-examples-springmvcdemo 下的 operation.yml文件

第四步:在application.yml中配置定义文件位置

operation:
  definition:                           # 操作定义
    location: classpath:/operation.yml  # 目前只内置了 yml风格的配置文件
    reload-interval-in-seconds: 60      # 如果值 >0 则会定时的重新加载,在开发环境下有很有用

只需上述4步,然后访问应用就会有相应的日志产生。 如果想把审计日志写入数据库,或者需要自定义审计日志消费者,只需要实现 com.jn.audit.mq.Consumer接口并订阅响应的topic即可。 可以参考:audit-examples/audit-examples-springmvcdemo 中的AuditConfig.java

import com.jn.audit.core.Auditor;
import com.jn.audit.examples.springmvcdemo.service.DbService;
import com.jn.audit.mq.MessageTopicDispatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AuditConfig {

    private DbService dbService;

    public DbService getDbService() {
        return dbService;
    }

    /**
     * 这是一个自定义的写入数据库的 Consumer
     */
    @Autowired
    public void setDbService(Auditor auditor, DbService dbService) {
        this.dbService = dbService;
        MessageTopicDispatcher dispatcher = auditor.getMessageTopicDispatcher();
        dispatcher.subscribe("DEFAULT", dbService);
    }

}

推广

  • langx 系列
    • langx-js:TypeScript, JavaScript tools
    • langx-java: Java tools ,可以替换guava, apache commons-lang,io, hu-tool等
  • easyjson: 一个通用的JSON库门面,可以无缝的在各个JSON库之间切换,就像slf4j那样。
  • sqlhelper: SQL工具套件(通用分页、DDL Dump、SQLParser、URL Parser、批量操作工具等)。
  • esmvc: ElasticSearch 通用客户端,就像MyBatis Mapper那样顺滑
  • redisclient: 基于Spring RestTemplate提供的客户端
  • audit:通用的Java应用审计框架

鸣谢

最后,感谢 Jetbrains 提供免费License,方便了开源项目的发展。

Jetbrains

audit's People

Contributors

bes2008 avatar dependabot[bot] avatar smallgray avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.