危化品全生命周期管理后端
kongzy
2024-08-22 0c73654f55844e34772732914af8cc1e247aab63
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
43
44
45
package com.gkhy.hazmat.framework.aspectj;
 
 
import com.gkhy.hazmat.common.annotation.DataDesensitization;
import com.gkhy.hazmat.common.utils.DesenseUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
 
/**
 * 数据脱密
 */
@Aspect
@Component
@Slf4j
public class DataDesensitizationAspect {
    @Autowired
    private HttpServletRequest request;
    @Pointcut("@annotation(com.gkhy.hazmat.common.annotation.DataDesensitization)")
    public void pointcut(){}
 
    @Around("pointcut()")
    public Object doaround(ProceedingJoinPoint point) throws Throwable {
        Object object=point.proceed();
        String uri = request.getRequestURI();
//        if(!uri.startsWith("/app/api")){
//            return object;
//        }
        MethodSignature signature = (MethodSignature) point.getSignature();
        Method method = signature.getMethod();
        if(!method.isAnnotationPresent(DataDesensitization.class)){
            return object;
        }
        DesenseUtil.assertResult(object);
        return object;
    }
}