From 0fef61a8f3a75ba2b6bcf7e9cef14a4a302e8b41 Mon Sep 17 00:00:00 2001 From: Domenico Francesco Bruscino Date: Mon, 20 Sep 2021 13:00:19 +0200 Subject: [PATCH] fix(hawtio-system): fix support for ActiveMQ Artemis client certificate login #2699 --- .../java/io/hawt/system/Authenticator.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/hawtio-system/src/main/java/io/hawt/system/Authenticator.java b/hawtio-system/src/main/java/io/hawt/system/Authenticator.java index f992cc6d98..630066b237 100644 --- a/hawtio-system/src/main/java/io/hawt/system/Authenticator.java +++ b/hawtio-system/src/main/java/io/hawt/system/Authenticator.java @@ -475,11 +475,19 @@ public void handle(Callback[] callbacks) { private void setCertificates(Callback callback) { try { - // Artemis still uses deprecated javax.security.cert.X509Certificate class - Method method = callback.getClass().getDeclaredMethod(ARTEMIS_CALLBACK_METHOD, javax.security.cert.X509Certificate[].class); - method.invoke(callback, new Object[] { toJavax(certificates) }); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | CertificateEncodingException | CertificateException e) { - LOG.error("Setting certificates to callback failed", e); + // Artemis uses java.security.cert.X509Certificate class since the 2.18.0 version. + Method method = callback.getClass().getDeclaredMethod(ARTEMIS_CALLBACK_METHOD, java.security.cert.X509Certificate[].class); + method.invoke(callback, new Object[] { certificates }); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + LOG.warn("Setting certificates to new callback failed", e); + + try { + // Artemis used deprecated javax.security.cert.X509Certificate class up to the 2.17.0 version. + Method method = callback.getClass().getDeclaredMethod(ARTEMIS_CALLBACK_METHOD, javax.security.cert.X509Certificate[].class); + method.invoke(callback, new Object[] { toJavax(certificates) }); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | CertificateEncodingException | CertificateException ex) { + LOG.error("Setting certificates to callback failed", ex); + } } }