[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 <fwang12@ebay.com>
Signed-off-by: Fei Wang <fwang12@ebay.com>
This commit is contained in:
Fei Wang 2022-06-22 19:59:34 +08:00
parent f629992fb3
commit 37c0d4258c

View File

@ -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)))
}