Learned that issue was regarding the spring security, generation of nonce and needs to be encoded as Base64
Note that the String, "nonceStr" is not encoded as Base64. But when you put it into the ByteBuffer, "buf", you have decode it as Base64. This will intermittently cause issue depending on whether if the UUID generated is Base64 compliant.
String nonceStr = UUID.create();
System.out.println("nonceStr: "+nonceStr);
byte[] a = Base64.decodeBase64(nonceStr.getBytes());
System.out.println("nonceStr: "+Base64.encodeBase64String(a));
String base64NonceStr = new String(Base64.encodeBase64(nonceStr.getBytes()));
System.out.println("base64NonceStr: "+base64NonceStr);
byte[] b = Base64.decodeBase64(base64NonceStr.getBytes());
System.out.println("base64NonceStr: "+Base64.encodeBase64String(b));
nonceStr: ac1c6f1cc80f4cbde9f753bfd5f0fa
nonceStr: ac1c6f1cc80f4cbde9f753bfd5f0fQ==
base64NonceStr: YWMxYzZmMWNjODBmNGNiZGU5Zjc1M2JmZDVmMGZh
base64NonceStr: YWMxYzZmMWNjODBmNGNiZGU5Zjc1M2JmZDVmMGZh
nonceStr: ac1c6f1c2da679b7dea1384b81fb2431
nonceStr: ac1c6f1c2da679b7dea1384b81fb2431
base64NonceStr: YWMxYzZmMWMyZGE2NzliN2RlYTEzODRiODFmYjI0MzE=
base64NonceStr: YWMxYzZmMWMyZGE2NzliN2RlYTEzODRiODFmYjI0MzE=
nonceStr: ac1c6f1cc80f4cbdea17677b796ad8
nonceStr: ac1c6f1cc80f4cbdea17677b796adw==
base64NonceStr: YWMxYzZmMWNjODBmNGNiZGVhMTc2NzdiNzk2YWQ4
base64NonceStr: YWMxYzZmMWNjODBmNGNiZGVhMTc2NzdiNzk2YWQ4
2 out of 3 runs generated nonceStr with issue based on your current code. The simplest change to fix is to simply Base64 encode your generated nonceStr, instead of
String nonceStr = UUID.create();
change it to
String nonceStr = new String(Base64.encodeBase64(UUID.create().getBytes()));