From 37c0d4258c5c05cd31dcdaa4cd44fa0e97f607f8 Mon Sep 17 00:00:00 2001 From: Fei Wang Date: Wed, 22 Jun 2022 19:59:34 +0800 Subject: [PATCH] [KYUUBI #2894] Add synchronized for the ciphers of internal security accessor ### _Why are the changes needed?_ The cipher is not thread-safe. ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2933 from turboFei/cipher_not_thread_safe. Closes #2894 ea3f79c03 [Fei Wang] not thread safe Authored-by: Fei Wang Signed-off-by: Fei Wang --- .../service/authentication/InternalSecurityAccessor.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/InternalSecurityAccessor.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/InternalSecurityAccessor.scala index 3c77634ef..62680e6a6 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/InternalSecurityAccessor.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/InternalSecurityAccessor.scala @@ -66,11 +66,11 @@ class InternalSecurityAccessor(conf: KyuubiConf, val isServer: Boolean) { } } - private[authentication] def encrypt(value: String): String = { + private[authentication] def encrypt(value: String): String = synchronized { byteArrayToHexString(encryptor.doFinal(value.getBytes)) } - private[authentication] def decrypt(value: String): String = { + private[authentication] def decrypt(value: String): String = synchronized { new String(decryptor.doFinal(hexStringToByteArray(value))) }