Skip to content

Commit 7c76828

Browse files
Fix fallback to config file when partial OCI API Key credentials are provided (Fixes #159) (#187)
Handle partial API Key credentials fallback to config file
1 parent 7560094 commit 7c76828

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

ojdbc-provider-oci/src/main/java/oracle/jdbc/provider/oci/authentication/AuthenticationDetailsFactory.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,23 +239,24 @@ private static AbstractAuthenticationDetailsProvider getAuthenticationDetails(
239239
* Returns authentication details using the following API key-based
240240
* methods:
241241
* <ol>
242-
* <li>Simple authentication: if any of the credentials, including tenant ID
243-
* , user ID, fingerprint, private key, or passphrase, are provided in
244-
* the given {@code parameters}</li>
242+
* <li>Simple authentication: if all required credentials (tenant ID,
243+
* user ID, fingerprint, and private key are provided in the given
244+
* {@code parameters}</li>
245245
* <li>Config File (API key) authentication: otherwise</li>
246246
* </ol>
247247
* @return API key-based authentication details
248248
*/
249249
private static AuthenticationDetailsProvider
250250
apiKeyBasedAuthentication(ParameterSet parameters) {
251-
if (parameters.contains(TENANT_ID)
252-
|| parameters.contains(USER_ID)
253-
|| parameters.contains(FINGERPRINT)
254-
|| parameters.contains(PRIVATE_KEY)
255-
|| parameters.contains(PASS_PHRASE)
256-
|| parameters.contains(REGION)) {
251+
boolean hasAllRequiredKeys =
252+
parameters.contains(TENANT_ID)
253+
&& parameters.contains(USER_ID)
254+
&& parameters.contains(FINGERPRINT)
255+
&& parameters.contains(PRIVATE_KEY);
256+
257+
if(hasAllRequiredKeys)
257258
return simpleAuthentication(parameters);
258-
}
259+
259260
return configFileAuthentication(parameters);
260261
}
261262

ojdbc-provider-oci/src/test/java/oracle/jdbc/provider/oci/AuthenticationDetailsFactoryTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public void testConfigFile() {
7272
.build());
7373
}
7474

75+
/**
76+
* Verifies partial API_KEY credentials fallback to config file.
77+
*/
78+
@Test
79+
public void testApiKeyPartialCredentials() {
80+
verifyAuthenticationDetails(
81+
buildParameterSet(AuthenticationMethod.API_KEY)
82+
.add("Test OCI_USER", AuthenticationDetailsFactory.USER_ID, "dummy-user-id")
83+
.build());
84+
}
85+
7586
/**
7687
* Verifies {@link AuthenticationMethod#CLOUD_SHELL}
7788
*/

0 commit comments

Comments
 (0)