刘光辉
6 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
package jnpf.limsService.provider;
 
import jnpf.audit.sdk.AuditClient;
import jnpf.audit.sdk.AuditContextCollector;
import jnpf.audit.sdk.AuditEventPublisher;
import jnpf.audit.sdk.AuditRequestScopeFilter;
import jnpf.audit.sdk.aspect.AuditLogAspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
 
/** Adds ELN-origin auditing only for the new source module; the existing LIMS scope is unchanged. */
@Aspect
@Component
@Order(49)
@org.springframework.boot.autoconfigure.condition.ConditionalOnProperty(
        name = {"audit.enabled", "audit.layer2-enabled"}, matchIfMissing = true)
public class LimsElnSourceAuditAspect {
    private final AuditRequestScopeFilter scope = new AuditRequestScopeFilter(true, "ELN");
    private final AuditRequestScopeFilter existingScope;
    private final AuditLogAspect delegate;
 
    public LimsElnSourceAuditAspect(AuditContextCollector collector, AuditEventPublisher publisher,
            ApplicationContext context, AuditRequestScopeFilter existingScope,
            @Value("${audit.enabled:true}") boolean enabled) {
        this.existingScope = existingScope;
        delegate = new AuditLogAspect(new AuditClient(collector, publisher, enabled, scope), publisher, context);
    }
 
    @Around("@annotation(jnpf.audit.sdk.annotation.AuditLog) && within(jnpf.limsService.provider..*)")
    public Object record(ProceedingJoinPoint invocation) throws Throwable {
        return scope.acceptsCurrentRequest() && !existingScope.acceptsCurrentRequest()
                ? delegate.around(invocation) : invocation.proceed();
    }
}