43
43
*/
44
44
45
45
import com .oracle .bmc .auth .AuthenticationDetailsProvider ;
46
+ import com .oracle .bmc .auth .AbstractAuthenticationDetailsProvider ;
47
+ import com .oracle .bmc .auth .InstancePrincipalsAuthenticationDetailsProvider ;
48
+ import com .oracle .bmc .auth .ResourcePrincipalAuthenticationDetailsProvider ;
46
49
import com .oracle .bmc .auth .ConfigFileAuthenticationDetailsProvider ;
47
50
import com .oracle .bmc .identitydataplane .DataplaneClient ;
48
51
import com .oracle .bmc .identitydataplane .model .GenerateScopedAccessTokenDetails ;
@@ -157,11 +160,18 @@ private static AccessToken createAccessToken() {
157
160
* @return Base 64 encoding of a JWT access token
158
161
*/
159
162
private static String requestToken (PublicKey publicKey ) {
160
-
161
- // Read the configuration identified by the OCI_PROFILE
162
- final AuthenticationDetailsProvider authentication ;
163
+
164
+ final AbstractAuthenticationDetailsProvider authentication ;
165
+
166
+ // Instance principal and resource principal authentication are also supported, and
167
+ // can be used as shown below.
168
+ // authentication = InstancePrincipalsAuthenticationDetailsProvider.builder().build();
169
+ // authentication = ResourcePrincipalAuthenticationDetailsProvider.builder().build();
170
+
163
171
try {
164
- authentication = new ConfigFileAuthenticationDetailsProvider (OCI_PROFILE );
172
+ // In this code sample, authentication is shown using a config file.
173
+ // Read the configuration identified by the OCI_PROFILE
174
+ authentication = new ConfigFileAuthenticationDetailsProvider (OCI_PROFILE );
165
175
}
166
176
catch (IOException ioException ) {
167
177
// Not recovering if the profile can not be read
@@ -175,9 +185,18 @@ private static String requestToken(PublicKey publicKey) {
175
185
176
186
// This scope uses the * character to identify all databases in the cloud
177
187
// tenancy of the authenticated user. The * could be replaced with the OCID
178
- // of a compartment, or of a particular database within a compartment
188
+ // of a compartment, or of a particular database within a compartment.
189
+ // Refer to the examples below.
179
190
String scope = "urn:oracle:db::id::*" ;
180
191
192
+ // A scope that authorizes access to all databases within a compartment has
193
+ // the form: urn:oracle:db::id::<compartment-ocid>
194
+ // String scope = "urn:oracle:db::id::ocid1.compartment.oc1..xxxxxxxx"
195
+
196
+ // A scope that authorizes access to a single database within a compartment
197
+ // has the form: urn:oracle:db::id::<compartment-ocid>::<database-ocid>
198
+ // String scope = "urn:oracle:db::id::ocid1.compartment.oc1..xxxxxx::ocid1.autonomousdatabase.oc1.phx.xxxxxx"
199
+
181
200
// Create a GenerateScopedAccessTokenDetails object with the public key
182
201
// and the scope
183
202
GenerateScopedAccessTokenDetails tokenDetails =
@@ -187,7 +206,7 @@ private static String requestToken(PublicKey publicKey) {
187
206
.build ();
188
207
189
208
// Request an access token using a DataplaneClient
190
- try (DataplaneClient client = new DataplaneClient (authentication )) {
209
+ try (DataplaneClient client = DataplaneClient . builder (). build (authentication )) {
191
210
return client .generateScopedAccessToken (
192
211
GenerateScopedAccessTokenRequest .builder ()
193
212
.generateScopedAccessTokenDetails (tokenDetails )
0 commit comments