diff --git a/linkis-commons/linkis-common/src/main/java/org/apache/linkis/common/utils/TicketCipher.java b/linkis-commons/linkis-common/src/main/java/org/apache/linkis/common/utils/TicketCipher.java index 7e704b00959..cd85aa6bdee 100644 --- a/linkis-commons/linkis-common/src/main/java/org/apache/linkis/common/utils/TicketCipher.java +++ b/linkis-commons/linkis-common/src/main/java/org/apache/linkis/common/utils/TicketCipher.java @@ -58,6 +58,7 @@ public class TicketCipher { "linkis-ticket-v2".getBytes(StandardCharsets.UTF_8); private static final byte VERSION_V2 = 0x02; + private final boolean useV2; private final SecretKey encKey; private final String cryptKeyRaw; private final SecureRandom rng = new SecureRandom(); @@ -68,14 +69,11 @@ public class TicketCipher { */ public TicketCipher(String cryptKeyRaw, boolean useV2) { this.cryptKeyRaw = cryptKeyRaw; - if (useV2) { - try { - this.encKey = deriveKey(cryptKeyRaw); - } catch (Exception e) { - throw new RuntimeException("Failed to derive ticket encryption key", e); - } - } else { - this.encKey = null; // unused in V1 mode + this.useV2 = useV2; + try { + this.encKey = deriveKey(cryptKeyRaw); + } catch (Exception e) { + throw new RuntimeException("Failed to derive ticket encryption key", e); } } @@ -86,7 +84,7 @@ public TicketCipher(String cryptKeyRaw, boolean useV2) { * When V2 is disabled: legacy DES (via DESUtil.encrypt). */ public String encrypt(String plaintext) throws Exception { - if (encKey != null) { + if (useV2) { return encryptV2(plaintext); } return DESUtil.encrypt(plaintext, cryptKeyRaw); diff --git a/linkis-commons/linkis-module/src/test/resources/linkis.properties b/linkis-commons/linkis-module/src/test/resources/linkis.properties index 1c575edc5b8..dd4ce5e4eaf 100644 --- a/linkis-commons/linkis-module/src/test/resources/linkis.properties +++ b/linkis-commons/linkis-module/src/test/resources/linkis.properties @@ -18,4 +18,5 @@ wds.linkis.server.version=v1 #test wds.linkis.test.mode=true -wds.linkis.test.user=hadoop \ No newline at end of file +wds.linkis.test.user=hadoop +wds.linkis.crypt.key=linkis-unit-test-crypt-key-not-for-deployment