urunni88 commented on code in PR #30151:
URL: https://github.com/apache/camel/pull/30151#discussion_r4585057896


##########
components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationConfigurer.java:
##########
@@ -112,6 +136,57 @@ public <T extends AuthenticationProvider> 
AuthenticationHandler createAuthentica
         authenticationConfig.setEnabled(true);
     }
 
+    /**
+     * Vert.x only uses the keys whose alias is the name of a JWT algorithm, 
such as RS256. A keystore without such an
+     * alias loads fine, but then every signed token fails, so warn at startup.
+     */
+    private static void warnIfNoJwtAlias(String type, String path, String 
password, String configPrefix) {
+        if (path == null) {
+            return;
+        }
+        try (InputStream is = openKeystore(path)) {
+            if (is == null) {
+                // Vert.x reports a keystore it cannot read
+                return;
+            }
+            KeyStore keyStore = KeyStore.getInstance(type);
+            keyStore.load(is, password != null ? password.toCharArray() : 
null);
+            String warning = checkJwtKeystoreAliases(keyStore, configPrefix, 
path);
+            if (warning != null) {
+                LOG.warn(warning);
+            }
+        } catch (Exception e) {
+            LOG.debug("Cannot read the JWT keystore {} to check its aliases", 
path, e);
+        }
+    }
+
+    /**
+     * Returns the warning for a keystore that has no key under an alias 
Vert.x uses, or null when it has one.
+     */
+    static String checkJwtKeystoreAliases(KeyStore keyStore, String 
configPrefix, String path)
+            throws KeyStoreException {
+        List<String> aliases = Collections.list(keyStore.aliases());
+        for (String alias : aliases) {
+            // the aliases of a PKCS12 or JKS keystore are not case-sensitive
+            if 
(JWT_KEYSTORE_ALIASES.stream().anyMatch(alias::equalsIgnoreCase)) {
+                return null;

Review Comment:
   Done in 9a776e4: the check now calls `getEntry()` with the keystore password 
for each algorithm, as Vert.x does, so a key with another password fails too. 
The `equalsIgnoreCase` loop is gone.



-- 
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]

Reply via email to