tabish121 commented on code in PR #6258:
URL: https://github.com/apache/artemis/pull/6258#discussion_r2874584927


##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/security/impl/SecurityStoreImpl.java:
##########
@@ -569,9 +582,26 @@ private boolean checkAuthorizationCache(final SimpleString 
dest, final String us
    }
 
    private String createAuthenticationCacheKey(String username, String 
password, RemotingConnection connection) {
+      MessageDigest md = getDigest();
+      if (username != null) {
+         md.update(username.getBytes(StandardCharsets.UTF_8));
+      }
+      md.update(CACHE_KEY_SEPARATOR);
+      if (password != null) {
+         md.update(password.getBytes(StandardCharsets.UTF_8));
+      }
+      md.update(CACHE_KEY_SEPARATOR);
+      String certSubjectDN = CertificateUtil.getCertSubjectDN(connection);
+      if (!CERT_SUBJECT_DN_UNAVAILABLE.equals(certSubjectDN)) {
+         md.update(certSubjectDN.getBytes(StandardCharsets.UTF_8));
+      }
+      return ByteUtil.bytesToHex(md.digest());
+   }
+
+   private static MessageDigest getDigest() {
       try {
-         return 
ByteUtil.bytesToHex(MessageDigest.getInstance("SHA-256").digest((username + 
password + 
CertificateUtil.getCertSubjectDN(connection)).getBytes(StandardCharsets.UTF_8)));
-      } catch (NoSuchAlgorithmException e) {
+         return (MessageDigest) SHA256.clone();
+      } catch (CloneNotSupportedException e) {

Review Comment:
   Instead of throwing here would it not make sense to try and get an instance 
via something like `return MessageDigest.getInstance(digest.getAlgorithm());` 
and only throw if that fails?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to