22The java-sdk-core project supports the following types of authentication:
33- Basic Authentication
44- Bearer Token Authentication
5- - Identity and Access Management (IAM) Authentication
5+ - Identity and Access Management (IAM) Authentication (grant type: apikey)
6+ - Identity and Access Management (IAM) Authentication (grant type: assume)
67- Container Authentication
78- VPC Instance Authentication
89- Cloud Pak for Data Authentication
@@ -12,11 +13,11 @@ The java-sdk-core project supports the following types of authentication:
1213The SDK user configures the appropriate type of authentication for use with service instances.
1314The authentication types that are appropriate for a particular service may vary from service to service,
1415so it is important for the SDK user to consult with the appropriate service documentation to understand
15- which authenticators are supported for that service.
16+ which authentication types are supported for that service.
1617
1718The java-sdk-core allows an authenticator to be specified in one of two ways:
18191 . programmatically - the SDK user constructs an instance of the desired authenticator using the appropriate Builder class or constructor,
19- and then passes the authenticator instance when constructing an instance of the service.
20+ and then passes the authenticator instance when constructing an instance of the service client .
20212 . configuration - the SDK user provides external configuration information (in the form of environment variables
2122or a credentials file) to indicate the type of authenticator, along with the configuration of the necessary properties
2223for that authenticator.
@@ -138,10 +139,10 @@ authenticator type is intended for situations in which the application will be m
138139token itself in terms of initial acquisition and refreshing as needed.
139140
140141
141- ## Identity and Access Management (IAM) Authentication
142- The ` IamAuthenticator ` will accept a user-supplied api key and will perform
142+ ## Identity and Access Management (IAM) Authentication (grant type: apikey)
143+ The ` IamAuthenticator ` will accept a user-supplied apikey and will perform
143144the necessary interactions with the IAM token service to obtain a suitable
144- bearer token for the specified api key . The authenticator will also obtain
145+ bearer token for the specified apikey . The authenticator will also obtain
145146a new bearer token when the current token expires. The bearer token is
146147then added to each outbound request in the ` Authorization ` header in the
147148form:
@@ -151,7 +152,7 @@ form:
151152
152153### Properties
153154
154- - apikey: (required) the IAM api key
155+ - apikey: (required) the IAM apikey to be used to obtain an IAM access token.
155156
156157- url: (optional) The base endpoint URL of the IAM token service.
157158The default value of this property is the "prod" IAM token service endpoint
@@ -214,6 +215,124 @@ ExampleService service = ExampleService.newInstance("example_service");
214215```
215216
216217
218+ ## Identity and Access Management (IAM) Authentication (grant type: assume)
219+ The ` IamAssumeAuthenticator ` performs a two-step token fetch sequence to obtain
220+ a bearer token that allows the application to assume the identity of a trusted profile:
221+ 1 . First, the authenticator obtains an initial bearer token using grant type
222+ ` urn:ibm:params:oauth:grant-type:apikey ` .
223+ This initial token will reflect the identity associated with the input apikey.
224+ 2 . Second, the authenticator uses the grant type ` urn:ibm:params:oauth:grant-type:assume ` to obtain a bearer token
225+ that reflects the identity of the trusted profile, passing in the initial bearer token
226+ from the first step, along with the trusted profile-related inputs.
227+
228+ The authenticator will also obtain a new bearer token when the current token expires.
229+ The bearer token is then added to each outbound request in the ` Authorization ` header in the
230+ form:
231+ ```
232+ Authorization: Bearer <bearer-token>
233+ ```
234+
235+ ### Properties
236+
237+ - apikey: (required) the IAM apikey to be used to obtain the initial IAM access token.
238+
239+ - iamProfileCrn: (optional) the Cloud Resource Name (CRN) associated with the trusted profile
240+ for which an access token should be fetched.
241+ Exactly one of iamProfileCrn, iamProfileId or iamProfileName must be specified.
242+
243+ - iamProfileId: (optional) the ID associated with the trusted profile
244+ for which an access token should be fetched.
245+ Exactly one of iamProfileCrn, iamProfileId or iamProfileName must be specified.
246+
247+ - iamProfileName: (optional) the name associated with the trusted profile
248+ for which an access token should be fetched. When specifying this property, you must also
249+ specify the iamAccountId property as well.
250+ Exactly one of iamProfileCrn, iamProfileId or iamProfileName must be specified.
251+
252+ - iamAccountId: (optional) the ID associated with the IAM account that contains the trusted profile
253+ referenced by the iamProfileName property. The imaAccountId property must be specified if and only if
254+ the iamProfileName property is specified.
255+
256+ - url: (optional) The base endpoint URL of the IAM token service.
257+ The default value of this property is the "prod" IAM token service endpoint
258+ (` https://iam.cloud.ibm.com ` ).
259+ Make sure that you use an IAM token service endpoint that is appropriate for the
260+ location of the service being used by your application.
261+ For example, if you are using an instance of a service in the "production" environment
262+ (e.g. ` https://resource-controller.cloud.ibm.com ` ),
263+ then the default "prod" IAM token service endpoint should suffice.
264+ However, if your application is using an instance of a service in the "staging" environment
265+ (e.g. ` https://resource-controller.test.cloud.ibm.com ` ),
266+ then you would also need to configure the authenticator to use the IAM token service "staging"
267+ endpoint as well (` https://iam.test.cloud.ibm.com ` ).
268+
269+ - clientId/clientSecret: (optional) The ` clientId ` and ` clientSecret ` fields are used to form a
270+ "basic auth" Authorization header for interactions with the IAM token server when fetching the
271+ initial IAM access token. These fields are optional, but must be specified together.
272+
273+ - scope: (optional) the scope to be used when obtaining the initial IAM access token.
274+ If not specified, then no scope will be associated with the access token.
275+
276+ - disableSSLVerification: (optional) A flag that indicates whether verification of the server's SSL
277+ certificate should be disabled or not. The default value is ` false ` .
278+
279+ - headers: (optional) A set of key/value pairs that will be sent as HTTP headers in requests
280+ made to the IAM token service.
281+
282+ ### Usage Notes
283+ - The IamAssumeAuthenticator is used to obtain an access token (a bearer token) from the IAM token service
284+ that allows an application to "assume" the identity of a trusted profile.
285+
286+ - The authenticator first uses the apikey, url, clientId/clientSecret, scope, disableSSLVerification, and headers
287+ properties to obtain an initial access token by invoking the IAM ` getToken `
288+ (grant_type=` urn:ibm:params:oauth:grant-type:apikey ` ) operation.
289+
290+ - The authenticator then uses the initial access token along with the url, iamProfileCrn, iamProfileId,
291+ iamProfileName, iamAccountId, disableSSLVerification, and headers properties to obtain an access token by invoking
292+ the IAM ` getToken ` (grant_type=` urn:ibm:params:oauth:grant-type:assume ` ) operation.
293+ The access token resulting from this second step will reflect the identity of the specified trusted profile.
294+
295+ - When providing the trusted profile information, you must specify exactly one of: iamProfileCrn, iamProfileId
296+ or iamProfileName. If you specify iamProfileCrn or iamProfileId, then the trusted profile must exist in the same account that is
297+ associated with the input apikey. If you specify iamProfileName, then you must also specify the iamAccountId property
298+ to indicate the IAM account in which the named trusted profile can be found.
299+
300+ ### Programming example
301+ ``` java
302+ import com.ibm.cloud.sdk.core.security.IamAssumeAuthenticator ;
303+ import <sdk_base_package>.ExampleService.v1.ExampleService ;
304+ ...
305+ // Create the authenticator.
306+ IamAssumeAuthenticator authenticator = new IamAssumeAuthenticator .Builder ()
307+ .iamProfileId(" myprofile-1" )
308+ .apikey(" myapikey" )
309+ .build();
310+
311+ // Create the service instance.
312+ ExampleService service = new ExampleService (ExampleService . DEFAULT_SERVICE_NAME , authenticator);
313+
314+ // 'service' can now be used to invoke operations.
315+ ```
316+
317+ ### Configuration example
318+ External configuration:
319+ ```
320+ export EXAMPLE_SERVICE_AUTH_TYPE=iamAssume
321+ export EXAMPLE_SERVICE_APIKEY=myapikey
322+ export EXAMPLE_SERVICE_IAM_PROFILE_ID=myprofile-1
323+ ```
324+ Application code:
325+ ``` java
326+ import <sdk_base_package>.ExampleService.v1.ExampleService ;
327+ ...
328+
329+ // Create the service instance.
330+ ExampleService service = ExampleService . newInstance(" example_service" );
331+
332+ // 'service' can now be used to invoke operations.
333+ ```
334+
335+
217336## Container Authentication
218337The ` ContainerAuthenticator ` is intended to be used by application code
219338running inside a compute resource managed by the IBM Kubernetes Service (IKS)
0 commit comments