WangHan
2025-04-02 a8ba678a3fe5a39da2c732014cebbb66e408e97c
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
package com.iplatform.core.config.enc;
 
import com.iplatform.core.util.AESUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.PropertySource;
 
public class PropertySourceWrapper<T> extends PropertySource<T> {
 
    protected final transient Logger logger = LoggerFactory.getLogger(getClass());
 
//    private final Encryptor encryptor;
 
    private final PropertySource<T> originalPropertySource;
    private final EncryptionWrapperDetector detector;
 
 
    public PropertySourceWrapper(PropertySource<T> originalPropertySource, EncryptionWrapperDetector detector) {
        super(originalPropertySource.getName(), originalPropertySource.getSource());
        this.originalPropertySource = originalPropertySource;
//        this.encryptor = encryptor;
        this.detector = detector;
    }
 
    @Override
    public Object getProperty(String name) {
        if (originalPropertySource.containsProperty(name)) {
            Object value = originalPropertySource.getProperty(name);
            if (value != null) {
                String property = value.toString();
                if (detector.detected(property)) {
//                    return encryptor.decrypt(detector.unWrapper(property));
                    logger.debug("找到加密配置:{}, value = {}", name, property);
                    return AESUtils.decryptStrAES(detector.unWrapper(property), AESUtils.KEY_16);
                }
            }
        }
        return originalPropertySource.getProperty(name);
    }
}