gnodet-bot commented on code in PR #31279:
URL: https://github.com/apache/camel/pull/31279#discussion_r4770887224


##########
components/camel-cyberark-vault/src/main/java/org/apache/camel/component/cyberark/vault/CyberArkVaultPropertiesFunction.java:
##########
@@ -122,6 +122,18 @@ protected void doStart() throws Exception {
                 password = cyberArkVaultConfiguration.getPassword();
                 apiKey = cyberArkVaultConfiguration.getApiKey();
                 authToken = cyberArkVaultConfiguration.getAuthToken();
+                // Pre-populate the tracked secrets from configuration, so 
callers (such as a
+                // reload-trigger task) can inspect which secrets are in use 
before the first
+                // apply() call resolves them.
+                String configuredSecrets = 
cyberArkVaultConfiguration.getSecrets();
+                if (ObjectHelper.isNotEmpty(configuredSecrets)) {
+                    for (String s : configuredSecrets.split(",")) {
+                        String trimmed = s.trim();
+                        if (!trimmed.isEmpty()) {
+                            secrets.add(trimmed);
+                        }
+                    }
+                }
             }
         }
 

Review Comment:
   ⚠️ **Reachability gap**: this entire block — including the 
`configuredSecrets` pre-population added by this PR — is guarded by 
`ObjectHelper.isEmpty(url) && ObjectHelper.isEmpty(account)`. When users 
configure the Conjur URL/account via environment variables 
(`CAMEL_VAULT_CYBERARK_URL` / `CAMEL_VAULT_CYBERARK_ACCOUNT`), the outer guard 
short-circuits and `camel.vault.cyberark.secrets` is never consumed. Consider 
moving the secrets pre-population to a code path that also runs when env vars 
supply the connection settings.



##########
components/camel-cyberark-vault/src/main/java/org/apache/camel/component/cyberark/vault/client/impl/ConjurClientImpl.java:
##########
@@ -131,50 +131,75 @@ private String retrieveSecret(String secretId, String 
version, boolean retryOnUn
     @Override
     public String authenticate() {
         try {
-            String login;
-            String credential;
-
             if (apiKey != null) {
-                // Authenticate with API key
-                login = username;
-                credential = apiKey;
+                // Authenticate with API key: POST 
/authn/{account}/{login}/authenticate
+                // body = API key, returns a short-lived access token
+                return authenticateWithApiKey(username, apiKey);
             } else if (password != null) {
-                // Authenticate with password
-                login = username;
-                credential = password;
+                // Authenticate with password: two steps per the Conjur API.
+                // Step 1: GET /authn/{account}/login with HTTP Basic auth 
(username:password)
+                //         returns the API key of the user.
+                // Step 2: POST /authn/{account}/{login}/authenticate with 
that API key
+                //         returns a short-lived access token.
+                String resolvedApiKey = loginWithPassword(username, password);
+                return authenticateWithApiKey(username, resolvedApiKey);
             } else if (authToken != null) {
                 // Already have a token
                 return authToken;
             } else {
                 throw new IllegalStateException("No authentication credentials 
available");
             }
-
-            // URL encode the login
-            String encodedLogin = URLEncoder.encode(login, 
StandardCharsets.UTF_8);
-
-            String authUrl = String.format("%s/authn/%s/%s/authenticate",
-                    url, account, encodedLogin);
-
-            HttpRequest request = HttpRequest.newBuilder()
-                    .uri(URI.create(authUrl))
-                    .header("Content-Type", "text/plain")
-                    .POST(HttpRequest.BodyPublishers.ofString(credential))
-                    .build();
-
-            HttpResponse<String> response = httpClient.send(request, 
HttpResponse.BodyHandlers.ofString());
-
-            if (response.statusCode() == 200) {
-                String token = response.body();
-                LOG.debug("Successfully authenticated with Conjur");
-                return token;
-            } else {
-                throw new IOException("Authentication failed: HTTP " + 
response.statusCode() + " - " + response.body());
-            }
         } catch (IOException | InterruptedException e) {
             throw new RuntimeException("Error authenticating with Conjur", e);

Review Comment:
   ⚠️ **Interrupt status lost**: `InterruptedException` is absorbed without 
restoring the interrupt flag. This catch is pre-existing, but this PR widens 
its scope — `loginWithPassword()` and `authenticateWithApiKey()` both declare 
`throws InterruptedException`. Callers that rely on interrupt-based 
cancellation will silently lose the signal.
   
   ```suggestion
           } catch (InterruptedException e) {
               Thread.currentThread().interrupt();
               throw new RuntimeException("Error authenticating with Conjur", 
e);
           } catch (IOException e) {
               throw new RuntimeException("Error authenticating with Conjur", 
e);
           }
   ```



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