gnodet-bot commented on code in PR #30151:
URL: https://github.com/apache/camel/pull/30151#discussion_r4583959533
##########
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);
Review Comment:
⚠️ **`KeyStore.getInstance(null)` throws `NullPointerException`** — when
`jwtKeystoreType` is not set, `type` is `null` here, and
`KeyStore.getInstance(null)` throws NPE. The broad `catch (Exception e)` on
line 159 silently swallows it and logs at DEBUG, so users who omit the type
config receive no alias warning at all. Use `KeyStore.getDefaultType()` as the
fallback, as Vert.x does:
```suggestion
KeyStore keyStore = KeyStore.getInstance(type != null ? type :
KeyStore.getDefaultType());
```
##########
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:
💡 **Alias-name check is weaker than Vert.x's actual loading**: Vert.x calls
`keyStore.getEntry(algName, new KeyStore.PasswordProtection(password))` for
each algorithm name and skips entries it cannot read. This check only verifies
the alias name exists — it passes for a `TrustedCertificateEntry` named `RS256`
(no signing key) and for a valid key alias protected by a different password.
Both cases pass the alias check but cause a silent 401 at runtime.
Switching to `getEntry()` as davsclaus suggested would mirror Vert.x exactly
and make this `equalsIgnoreCase` loop unnecessary.
--
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]