diff options
| author | 李奉超 <[email protected]> | 2024-10-30 03:27:51 +0000 |
|---|---|---|
| committer | 李奉超 <[email protected]> | 2024-10-30 03:27:51 +0000 |
| commit | c938ead4c0c6c51cbb3403ef6e39b0634a78abba (patch) | |
| tree | 1a611b5c9c18b4fe9db71c26faec45a90c0ff014 | |
| parent | b7e308ad95b302fa581f52c063ef716606a81e5e (diff) | |
| parent | f6e4dca31d09e211d6892524b9ac4d8d481dda06 (diff) | |
Merge branch 'fix/udf-encrypt' into 'develop'
[fix][core] Encrypt函数适配网关动态获取加密字段接口
See merge request galaxy/platform/groot-stream!125
| -rw-r--r-- | groot-bootstrap/src/main/java/com/geedgenetworks/bootstrap/command/AESShade.java | 2 | ||||
| -rw-r--r-- | groot-core/src/main/java/com/geedgenetworks/core/udf/Encrypt.java | 7 | ||||
| -rw-r--r-- | groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES128GCM96.java (renamed from groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES128GCM96Algorithm.java) | 4 | ||||
| -rw-r--r-- | groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES256GCM96.java (renamed from groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES256GCM96Algorithm.java) | 4 | ||||
| -rw-r--r-- | groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/SM4GCM96.java (renamed from groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/SM4GCM96Algorithm.java) | 4 | ||||
| -rw-r--r-- | groot-core/src/main/java/com/geedgenetworks/core/utils/EncryptionAlgorithmUtils.java | 12 | ||||
| -rw-r--r-- | groot-core/src/test/java/com/geedgenetworks/core/udf/test/simple/EncryptFunctionTest.java | 2 |
7 files changed, 19 insertions, 16 deletions
diff --git a/groot-bootstrap/src/main/java/com/geedgenetworks/bootstrap/command/AESShade.java b/groot-bootstrap/src/main/java/com/geedgenetworks/bootstrap/command/AESShade.java index 37a8e5b..91e05d0 100644 --- a/groot-bootstrap/src/main/java/com/geedgenetworks/bootstrap/command/AESShade.java +++ b/groot-bootstrap/src/main/java/com/geedgenetworks/bootstrap/command/AESShade.java @@ -10,7 +10,7 @@ public class AESShade implements CryptoShade { private static final String IDENTIFIER = "aes"; private static final byte[] SECURITY_KEY = - SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(), ".geedgenetworks.".getBytes(StandardCharsets.UTF_8)).getEncoded() ; + SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(), ".geedgenetworks.".getBytes(StandardCharsets.UTF_8)).getEncoded(); private static final String[] SENSITIVE_OPTIONS = new String[] {"connection.user", "connection.password", "kafka.sasl.jaas.config","kafka.ssl.keystore.password","kafka.ssl.truststore.password","kafka.ssl.key.password"}; diff --git a/groot-core/src/main/java/com/geedgenetworks/core/udf/Encrypt.java b/groot-core/src/main/java/com/geedgenetworks/core/udf/Encrypt.java index b20ff18..7fdbfa0 100644 --- a/groot-core/src/main/java/com/geedgenetworks/core/udf/Encrypt.java +++ b/groot-core/src/main/java/com/geedgenetworks/core/udf/Encrypt.java @@ -17,6 +17,9 @@ import com.geedgenetworks.common.udf.UDFContext; import com.geedgenetworks.core.pojo.KmsKey; import com.geedgenetworks.core.udf.encrypt.EncryptionAlgorithm; import com.geedgenetworks.core.utils.*; +import com.geedgenetworks.shaded.org.apache.http.HttpHeaders; +import com.geedgenetworks.shaded.org.apache.http.HttpStatus; +import com.geedgenetworks.shaded.org.apache.http.message.BasicHeader; import com.geedgenetworks.utils.StringUtil; import lombok.extern.slf4j.Slf4j; import org.apache.flink.api.common.functions.RuntimeContext; @@ -149,9 +152,9 @@ public class Encrypt implements ScalarFunction { public Set<String> getSensitiveFields(String url) throws IOException { Set<String> sensitiveFieldsSet; - String sensitiveFieldsStr = HttpClientPoolUtil.getInstance().httpGet(URI.create(URLUtil.normalize(url))); + String sensitiveFieldsStr = HttpClientPoolUtil.getInstance().httpGet(URI.create(URLUtil.normalize(url)), new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded")); JSONObject sensitiveFieldsJson = JSONUtil.parseObj(sensitiveFieldsStr); - if (sensitiveFieldsJson.getInt("status", 500) == 200) { + if (sensitiveFieldsJson.getInt("status", HttpStatus.SC_INTERNAL_SERVER_ERROR) == HttpStatus.SC_OK) { JSONArray sensitiveFieldsJsonArr = sensitiveFieldsJson.getJSONArray("data"); sensitiveFieldsSet = IntStream.range(0, sensitiveFieldsJsonArr.size()) .mapToObj(sensitiveFieldsJsonArr::getStr) diff --git a/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES128GCM96Algorithm.java b/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES128GCM96.java index db4369e..90669b3 100644 --- a/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES128GCM96Algorithm.java +++ b/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES128GCM96.java @@ -8,7 +8,7 @@ import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.util.Base64; -public class AES128GCM96Algorithm implements EncryptionAlgorithm { +public class AES128GCM96 implements EncryptionAlgorithm { private static final String IDENTIFIER = "aes-128-gcm96"; private static final String ALGORITHM = "AES"; private static final String TRANSFORMATION = "AES/GCM/NoPadding"; @@ -20,7 +20,7 @@ public class AES128GCM96Algorithm implements EncryptionAlgorithm { private final Cipher cipher; private KmsKey kmsKey; - public AES128GCM96Algorithm() throws Exception { + public AES128GCM96() throws Exception { this.cipher = Cipher.getInstance(TRANSFORMATION); this.kmsKey = new KmsKey(DEFAULT_SECRET_KEY, 1); } diff --git a/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES256GCM96Algorithm.java b/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES256GCM96.java index dec7e01..0306616 100644 --- a/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES256GCM96Algorithm.java +++ b/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/AES256GCM96.java @@ -8,7 +8,7 @@ import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.util.Base64; -public class AES256GCM96Algorithm implements EncryptionAlgorithm { +public class AES256GCM96 implements EncryptionAlgorithm { private static final String IDENTIFIER = "aes-256-gcm96"; private static final String ALGORITHM = "AES"; private static final String TRANSFORMATION = "AES/GCM/NoPadding"; @@ -20,7 +20,7 @@ public class AES256GCM96Algorithm implements EncryptionAlgorithm { private final Cipher cipher; private KmsKey kmsKey; - public AES256GCM96Algorithm() throws Exception { + public AES256GCM96() throws Exception { this.cipher = Cipher.getInstance(TRANSFORMATION); this.kmsKey = new KmsKey(DEFAULT_SECRET_KEY, 1); } diff --git a/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/SM4GCM96Algorithm.java b/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/SM4GCM96.java index e13cb40..f4ad0a2 100644 --- a/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/SM4GCM96Algorithm.java +++ b/groot-core/src/main/java/com/geedgenetworks/core/udf/encrypt/SM4GCM96.java @@ -8,7 +8,7 @@ import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.util.Base64; -public class SM4GCM96Algorithm implements EncryptionAlgorithm { +public class SM4GCM96 implements EncryptionAlgorithm { private static final String IDENTIFIER = "sm4-gcm96"; private static final String ALGORITHM = "SM4"; private static final String TRANSFORMATION = "SM4/GCM/NoPadding"; @@ -20,7 +20,7 @@ public class SM4GCM96Algorithm implements EncryptionAlgorithm { private final Cipher cipher; private KmsKey kmsKey; - public SM4GCM96Algorithm() throws Exception { + public SM4GCM96() throws Exception { this.cipher = Cipher.getInstance(TRANSFORMATION); this.kmsKey = new KmsKey(DEFAULT_SECRET_KEY, 1); } diff --git a/groot-core/src/main/java/com/geedgenetworks/core/utils/EncryptionAlgorithmUtils.java b/groot-core/src/main/java/com/geedgenetworks/core/utils/EncryptionAlgorithmUtils.java index 0a0fe33..0327e49 100644 --- a/groot-core/src/main/java/com/geedgenetworks/core/utils/EncryptionAlgorithmUtils.java +++ b/groot-core/src/main/java/com/geedgenetworks/core/utils/EncryptionAlgorithmUtils.java @@ -1,9 +1,9 @@ package com.geedgenetworks.core.utils; import com.geedgenetworks.core.udf.encrypt.EncryptionAlgorithm; -import com.geedgenetworks.core.udf.encrypt.AES128GCM96Algorithm; -import com.geedgenetworks.core.udf.encrypt.AES256GCM96Algorithm; -import com.geedgenetworks.core.udf.encrypt.SM4GCM96Algorithm; +import com.geedgenetworks.core.udf.encrypt.AES128GCM96; +import com.geedgenetworks.core.udf.encrypt.AES256GCM96; +import com.geedgenetworks.core.udf.encrypt.SM4GCM96; import lombok.extern.slf4j.Slf4j; /** @@ -18,11 +18,11 @@ public final class EncryptionAlgorithmUtils { public static EncryptionAlgorithm createEncryptionAlgorithm(String identifier) throws Exception { switch (identifier) { case ALGORITHM_AES_128_GCM96_NAME: - return new AES128GCM96Algorithm(); + return new AES128GCM96(); case ALGORITHM_AES_256_GCM96_NAME: - return new AES256GCM96Algorithm(); + return new AES256GCM96(); case ALGORITHM_SM4_GCM96_NAME: - return new SM4GCM96Algorithm(); + return new SM4GCM96(); default: return null; } diff --git a/groot-core/src/test/java/com/geedgenetworks/core/udf/test/simple/EncryptFunctionTest.java b/groot-core/src/test/java/com/geedgenetworks/core/udf/test/simple/EncryptFunctionTest.java index a83d853..d2091f7 100644 --- a/groot-core/src/test/java/com/geedgenetworks/core/udf/test/simple/EncryptFunctionTest.java +++ b/groot-core/src/test/java/com/geedgenetworks/core/udf/test/simple/EncryptFunctionTest.java @@ -237,7 +237,7 @@ public class EncryptFunctionTest { " ]\n" + "}"; HttpClientPoolUtil instance = Mockito.mock(HttpClientPoolUtil.class); - Mockito.when(instance.httpGet(ArgumentMatchers.any())).thenReturn(sensitiveFieldsStr); + Mockito.when(instance.httpGet(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(sensitiveFieldsStr); MockedStatic<HttpClientPoolUtil> httpClientPoolUtilMockedStatic = Mockito.mockStatic(HttpClientPoolUtil.class); Mockito.when(HttpClientPoolUtil.getInstance()).thenReturn(instance); return httpClientPoolUtilMockedStatic; |
