刘光辉
15 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package jnpf.dmsIntegration.audit;
 
import jnpf.audit.AuditConsts;
import jnpf.audit.model.AuditEventDTO;
import jnpf.audit.sdk.AuditClient;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Component;
 
@Component
public class DmsAuditAdapter {
    private final ObjectProvider<AuditClient> auditClient;
 
    public DmsAuditAdapter(ObjectProvider<AuditClient> auditClient) {
        this.auditClient = auditClient;
    }
 
    public void dataChange(String actionCode, String actionLabel, String table, String id,
                           String reason, String extra) {
        record(AuditConsts.TYPE_DATA_CHANGE, actionCode, actionLabel, table, id, reason, extra);
    }
 
    public void permissionDecision(boolean allowed, String actionLabel, String resourceId, String extra) {
        record(AuditConsts.TYPE_BIZ_ACTION, allowed ? "PERMISSION_ALLOW" : "PERMISSION_DENY",
                actionLabel, "dms_permission_resources", resourceId, null, extra);
    }
 
    private void record(String eventType, String actionCode, String actionLabel, String table, String id,
                        String reason, String extra) {
        auditClient.ifAvailable(client -> client.record(AuditEventDTO.builder()
                .eventType(eventType)
                .actionCode(actionCode)
                .actionLabel(actionLabel)
                .bizModule("DMS_PERMISSION")
                .bizType("DMS_PERMISSION")
                .targetTable(table)
                .targetId(id)
                .reason(reason)
                .extra(extra)
                .sourceLayer(3)
                .build()));
    }
}