Skip to content

Commit 59ff9bc

Browse files
make auth method values case-insensitive for config and resource providers (#248)
parse AUTHENTICATION/authenticationMethod values case-insensitively and add tests
1 parent dff8f98 commit 59ff9bc

File tree

5 files changed

+208
-5
lines changed

5 files changed

+208
-5
lines changed

ojdbc-provider-oci/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ share the same sets of parameters for authentication configuration.
231231

232232
The Centralized Config Providers in this module use the
233233
[OCI SDK Authentication Methods](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdk_authentication_methods.htm) to provide authorization and authentication to the Object Storage, Database Tools Connection and Vault services.
234-
The user can provide an optional parameter `AUTHENTICATION` (case-ignored) which is mapped with the following Credential Class.
234+
The user can provide an optional parameter `AUTHENTICATION` (case-ignored), and its values are also parsed case-insensitively. It is mapped with the following Credential Class.
235235

236236
<table>
237237
<thead><tr>
@@ -885,7 +885,7 @@ not supported.
885885
Providers in this module must authenticate with OCI. By default, a provider will
886886
automatically detect any available credentials. A specific credential
887887
may be configured using the "authenticationMethod" parameter. The parameter may
888-
be set to any of the following values:
888+
be set to any of the following values (case-insensitive):
889889
<dl>
890890
<dt>config-file</dt>
891891
<dd>

ojdbc-provider-oci/src/main/java/oracle/jdbc/provider/oci/configuration/OciConfigurationParameters.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import oracle.jdbc.provider.parameter.Parameter;
4545
import oracle.jdbc.provider.parameter.ParameterSetParser;
4646

47+
import java.util.Locale;
48+
4749
import static oracle.jdbc.provider.oci.authentication.AuthenticationDetailsFactory.*;
4850
import static oracle.jdbc.provider.oci.authentication.AuthenticationMethod.*;
4951
import static oracle.jdbc.provider.oci.objectstorage.ObjectFactory.OBJECT_URL;
@@ -136,7 +138,7 @@ private static int parsePositiveInt(String paramName, String s) {
136138
*/
137139
private static AuthenticationMethod parseAuthentication(
138140
String authentication) {
139-
switch (authentication) {
141+
switch (authentication.toUpperCase(Locale.ROOT)) {
140142
case "OCI_DEFAULT": return API_KEY;
141143
case "OCI_INSTANCE_PRINCIPAL": return INSTANCE_PRINCIPAL;
142144
case "OCI_RESOURCE_PRINCIPAL": return RESOURCE_PRINCIPAL;

ojdbc-provider-oci/src/main/java/oracle/jdbc/provider/oci/resource/OciResourceProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import oracle.jdbc.provider.resource.ResourceParameter;
4949
import oracle.jdbc.provider.util.Wallet;
5050

51+
import java.util.Locale;
5152
import java.util.Map;
5253
import java.util.stream.Stream;
5354

@@ -148,9 +149,9 @@ private static int parsePositiveInt(String paramName, String s) {
148149
* {@link AuthenticationMethod}
149150
* recognized by the {@link AuthenticationDetailsFactory}.
150151
*/
151-
private static AuthenticationMethod parseAuthenticationMethod(
152+
static AuthenticationMethod parseAuthenticationMethod(
152153
String authenticationMethod) {
153-
switch (authenticationMethod) {
154+
switch (authenticationMethod.toLowerCase(Locale.ROOT)) {
154155
case "config-file": return CONFIG_FILE;
155156
case "instance-principal": return INSTANCE_PRINCIPAL;
156157
case "resource-principal": return RESOURCE_PRINCIPAL;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
** Copyright (c) 2026 Oracle and/or its affiliates.
3+
**
4+
** The Universal Permissive License (UPL), Version 1.0
5+
**
6+
** Subject to the condition set forth below, permission is hereby granted to any
7+
** person obtaining a copy of this software, associated documentation and/or data
8+
** (collectively the "Software"), free of charge and under any and all copyright
9+
** rights in the Software, and any and all patent rights owned or freely
10+
** licensable by each licensor hereunder covering either (i) the unmodified
11+
** Software as contributed to or provided by such licensor, or (ii) the Larger
12+
** Works (as defined below), to deal in both
13+
**
14+
** (a) the Software, and
15+
** (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
** one is included with the Software (each a "Larger Work" to which the Software
17+
** is contributed by such licensors),
18+
**
19+
** without restriction, including without limitation the rights to copy, create
20+
** derivative works of, display, perform, and distribute the Software and make,
21+
** use, sell, offer for sale, import, export, have made, and have sold the
22+
** Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
** either these or other terms.
24+
**
25+
** This license is subject to the following condition:
26+
** The above copyright notice and either this complete permission notice or at
27+
** a minimum a reference to the UPL must be included in all copies or
28+
** substantial portions of the Software.
29+
**
30+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
** SOFTWARE.
37+
*/
38+
39+
package oracle.jdbc.provider.oci.configuration;
40+
41+
import oracle.jdbc.provider.parameter.ParameterSet;
42+
import org.junit.jupiter.api.Test;
43+
44+
import java.util.Collections;
45+
import java.util.HashMap;
46+
import java.util.Map;
47+
48+
import static oracle.jdbc.provider.oci.authentication.AuthenticationDetailsFactory.AUTHENTICATION_METHOD;
49+
import static oracle.jdbc.provider.oci.authentication.AuthenticationMethod.API_KEY;
50+
import static oracle.jdbc.provider.oci.authentication.AuthenticationMethod.INSTANCE_PRINCIPAL;
51+
import static org.junit.jupiter.api.Assertions.assertEquals;
52+
import static org.junit.jupiter.api.Assertions.assertThrows;
53+
54+
/**
55+
* Verifies parsing behavior of AUTHENTICATION values in
56+
* {@link OciConfigurationParameters}.
57+
*/
58+
public class OciConfigurationParametersTest {
59+
60+
/**
61+
* Verifies lowercase AUTHENTICATION values are parsed successfully.
62+
*/
63+
@Test
64+
public void testAuthenticationValueLowerCase() {
65+
ParameterSet parameterSet = OciConfigurationParameters.getParser()
66+
.parseNamedValues(mapOf("AUTHENTICATION", "oci_default"));
67+
68+
assertEquals(API_KEY, parameterSet.getOptional(AUTHENTICATION_METHOD));
69+
}
70+
71+
/**
72+
* Verifies uppercase AUTHENTICATION values are parsed successfully.
73+
*/
74+
@Test
75+
public void testAuthenticationValueUpperCase() {
76+
ParameterSet parameterSet = OciConfigurationParameters.getParser()
77+
.parseNamedValues(mapOf("AUTHENTICATION", "OCI_DEFAULT"));
78+
79+
assertEquals(API_KEY, parameterSet.getOptional(AUTHENTICATION_METHOD));
80+
}
81+
82+
/**
83+
* Verifies mixed-case AUTHENTICATION values are parsed successfully.
84+
*/
85+
@Test
86+
public void testAuthenticationValueMixedCase() {
87+
ParameterSet parameterSet = OciConfigurationParameters.getParser()
88+
.parseNamedValues(mapOf("AUTHENTICATION", "OCI_instance_principal"));
89+
90+
assertEquals(INSTANCE_PRINCIPAL, parameterSet.getOptional(AUTHENTICATION_METHOD));
91+
}
92+
93+
/**
94+
* Verifies unknown AUTHENTICATION values are rejected.
95+
*/
96+
@Test
97+
public void testAuthenticationValueUnknownRejected() {
98+
assertThrows(
99+
IllegalArgumentException.class,
100+
() -> OciConfigurationParameters.getParser()
101+
.parseNamedValues(mapOf("AUTHENTICATION", "oci_unknown")));
102+
}
103+
104+
private static Map<String, String> mapOf(String key, String value) {
105+
Map<String, String> map = new HashMap<>();
106+
map.put(key, value);
107+
return Collections.unmodifiableMap(map);
108+
}
109+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
** Copyright (c) 2026 Oracle and/or its affiliates.
3+
**
4+
** The Universal Permissive License (UPL), Version 1.0
5+
**
6+
** Subject to the condition set forth below, permission is hereby granted to any
7+
** person obtaining a copy of this software, associated documentation and/or data
8+
** (collectively the "Software"), free of charge and under any and all copyright
9+
** rights in the Software, and any and all patent rights owned or freely
10+
** licensable by each licensor hereunder covering either (i) the unmodified
11+
** Software as contributed to or provided by such licensor, or (ii) the Larger
12+
** Works (as defined below), to deal in both
13+
**
14+
** (a) the Software, and
15+
** (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
** one is included with the Software (each a "Larger Work" to which the Software
17+
** is contributed by such licensors),
18+
**
19+
** without restriction, including without limitation the rights to copy, create
20+
** derivative works of, display, perform, and distribute the Software and make,
21+
** use, sell, offer for sale, import, export, have made, and have sold the
22+
** Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
** either these or other terms.
24+
**
25+
** This license is subject to the following condition:
26+
** The above copyright notice and either this complete permission notice or at
27+
** a minimum a reference to the UPL must be included in all copies or
28+
** substantial portions of the Software.
29+
**
30+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
** SOFTWARE.
37+
*/
38+
39+
package oracle.jdbc.provider.oci.resource;
40+
41+
import oracle.jdbc.provider.oci.authentication.AuthenticationMethod;
42+
import org.junit.jupiter.api.Test;
43+
44+
import static org.junit.jupiter.api.Assertions.assertEquals;
45+
import static org.junit.jupiter.api.Assertions.assertThrows;
46+
47+
/**
48+
* Verifies shared authentication parsing behavior in {@link OciResourceProvider}.
49+
*/
50+
public class OciResourceProviderTest {
51+
52+
/**
53+
* Verifies lowercase resource authentication values are parsed.
54+
*/
55+
@Test
56+
public void testResourceAuthenticationValueLowerCase() {
57+
assertEquals(
58+
AuthenticationMethod.CONFIG_FILE,
59+
OciResourceProvider.parseAuthenticationMethod("config-file"));
60+
}
61+
62+
/**
63+
* Verifies uppercase resource authentication values are parsed.
64+
*/
65+
@Test
66+
public void testResourceAuthenticationValueUpperCase() {
67+
assertEquals(
68+
AuthenticationMethod.CONFIG_FILE,
69+
OciResourceProvider.parseAuthenticationMethod("CONFIG-FILE"));
70+
}
71+
72+
/**
73+
* Verifies mixed-case resource authentication values are parsed.
74+
*/
75+
@Test
76+
public void testResourceAuthenticationValueMixedCase() {
77+
assertEquals(
78+
AuthenticationMethod.INSTANCE_PRINCIPAL,
79+
OciResourceProvider.parseAuthenticationMethod("Instance-PRINCIPAL"));
80+
}
81+
82+
/**
83+
* Verifies unknown resource authentication values are rejected.
84+
*/
85+
@Test
86+
public void testResourceAuthenticationValueUnknownRejected() {
87+
assertThrows(
88+
IllegalArgumentException.class,
89+
() -> OciResourceProvider.parseAuthenticationMethod("not-a-method"));
90+
}
91+
}

0 commit comments

Comments
 (0)