1
1
# Authentication
2
2
The java-sdk-core project supports the following types of authentication:
3
3
- Basic Authentication
4
- - Bearer Token
5
- - Identity and Access Management (IAM)
6
- - Cloud Pak for Data
4
+ - Bearer Token Authentication
5
+ - Identity and Access Management (IAM) Authentication
6
+ - Container Authentication
7
+ - Cloud Pak for Data Authentication
7
8
- No Authentication
8
9
9
10
The SDK user configures the appropriate type of authentication for use with service instances.
@@ -23,15 +24,20 @@ configuration information. The configuration examples below will use
23
24
environment variables, although the same properties could be specified in a
24
25
credentials file instead.
25
26
27
+
26
28
## Basic Authentication
27
29
The ` BasicAuthenticator ` is used to add Basic Authentication information to
28
30
each outbound request in the ` Authorization ` header in the form:
29
31
```
30
32
Authorization: Basic <encoded username and password>
31
33
```
34
+
32
35
### Properties
36
+
33
37
- username: (required) the basic auth username
38
+
34
39
- password: (required) the basic auth password
40
+
35
41
### Programming example
36
42
``` java
37
43
import com.ibm.cloud.sdk.core.security.BasicAuthenticator ;
@@ -48,6 +54,7 @@ ExampleService service = new ExampleService(authenticator);
48
54
49
55
// 'service' can now be used to invoke operations.
50
56
```
57
+
51
58
### Configuration example
52
59
External configuration:
53
60
```
@@ -69,14 +76,18 @@ ExampleService service = new ExampleService(authenticator);
69
76
// 'service' can now be used to invoke operations.
70
77
```
71
78
79
+
72
80
## Bearer Token Authentication
73
81
The ` BearerTokenAuthenticator ` will add a user-supplied bearer token to
74
82
each outbound request in the ` Authorization ` header in the form:
75
83
```
76
84
Authorization: Bearer <bearer-token>
77
85
```
86
+
78
87
### Properties
88
+
79
89
- bearerToken: (required) the bearer token value
90
+
80
91
### Programming example
81
92
``` java
82
93
import com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator ;
@@ -96,6 +107,7 @@ ExampleService service = new ExampleService(authenticator);
96
107
newToken = // ... obtain new bearer token value
97
108
authenticator. setBearerToken(newToken);
98
109
```
110
+
99
111
### Configuration example
100
112
External configuration:
101
113
```
@@ -120,13 +132,15 @@ ExampleService service = new ExampleService(authenticator);
120
132
newToken = // ... obtain new bearer token value
121
133
((BearerTokenAuthenticator ) authenticator). setBearerToken(newToken);
122
134
```
135
+
123
136
Note that the use of external configuration is not as useful with the ` BearerTokenAuthenticator ` as it
124
137
is for other authenticator types because bearer tokens typically need to be obtained and refreshed
125
138
programmatically since they normally have a relatively short lifespan before they expire. This
126
139
authenticator type is intended for situations in which the application will be managing the bearer
127
140
token itself in terms of initial acquisition and refreshing as needed.
128
141
129
- ## Identity and Access Management Authentication (IAM)
142
+
143
+ ## Identity and Access Management (IAM) Authentication
130
144
The ` IamAuthenticator ` will accept a user-supplied api key and will perform
131
145
the necessary interactions with the IAM token service to obtain a suitable
132
146
bearer token for the specified api key. The authenticator will also obtain
@@ -136,18 +150,25 @@ form:
136
150
```
137
151
Authorization: Bearer <bearer-token>
138
152
```
153
+
139
154
### Properties
155
+
140
156
- apikey: (required) the IAM api key
157
+
141
158
- url: (optional) The URL representing the IAM token service endpoint. If not specified, a suitable
142
159
default value is used.
160
+
143
161
- clientId/clientSecret: (optional) The ` clientId ` and ` clientSecret ` fields are used to form a
144
162
"basic auth" Authorization header for interactions with the IAM token server. If neither field
145
163
is specified, then no Authorization header will be sent with token server requests. These fields
146
164
are optional, but must be specified together.
165
+
147
166
- disableSSLVerification: (optional) A flag that indicates whether verificaton of the server's SSL
148
167
certificate should be disabled or not. The default value is ` false ` .
168
+
149
169
- headers: (optional) A set of key/value pairs that will be sent as HTTP headers in requests
150
170
made to the IAM token service.
171
+
151
172
### Programming example
152
173
``` java
153
174
import com.ibm.cloud.sdk.core.security.IamAuthenticator ;
@@ -163,6 +184,7 @@ ExampleService service = new ExampleService(authenticator);
163
184
164
185
// 'service' can now be used to invoke operations.
165
186
```
187
+
166
188
### Configuration example
167
189
External configuration:
168
190
```
@@ -183,7 +205,99 @@ ExampleService service = new ExampleService(authenticator);
183
205
// 'service' can now be used to invoke operations.
184
206
```
185
207
186
- ## Cloud Pak for Data
208
+
209
+ ## Container Authentication
210
+ The ` ContainerAuthenticator ` is intended to be used by application code
211
+ running inside a compute resource managed by the IBM Kubernetes Service (IKS)
212
+ in which a secure compute resource token (CR token) has been stored in a file
213
+ within the compute resource's local file system.
214
+ The CR token is similar to an IAM apikey except that it is managed automatically by
215
+ the compute resource provider (IKS).
216
+ This allows the application developer to:
217
+ - avoid storing credentials in application code, configuraton files or a password vault
218
+ - avoid managing or rotating credentials
219
+
220
+ The ` ContainerAuthenticator ` will retrieve the CR token from
221
+ the compute resource in which the application is running, and will then perform
222
+ the necessary interactions with the IAM token service to obtain an IAM access token
223
+ using the IAM "get token" operation with grant-type ` cr-token ` .
224
+ The authenticator will repeat these steps to obtain a new IAM access token when the
225
+ current access token expires.
226
+ The IAM access token is added to each outbound request in the ` Authorization ` header in the form:
227
+ ```
228
+ Authorization: Bearer <IAM-access-token>
229
+ ```
230
+
231
+ ### Properties
232
+
233
+ - crTokenFilename: (optional) the name of the file containing the injected CR token value.
234
+ If not specified, then ` /var/run/secrets/tokens/vault-token ` is used as the default value.
235
+ The application must have ` read ` permissions on the file containing the CR token value.
236
+
237
+ - iamProfileName: (optional) the name of the linked trusted IAM profile to be used when obtaining the
238
+ IAM access token (a CR token might map to multiple IAM profiles).
239
+ One of ` iamProfileName ` or ` iamProfileID ` must be specified.
240
+
241
+ - iamProfileID: (optional) the id of the linked trusted IAM profile to be used when obtaining the
242
+ IAM access token (a CR token might map to multiple IAM profiles).
243
+ One of ` iamProfileName ` or ` iamProfileID ` must be specified.
244
+
245
+ - url: (optional) The base endpoint URL of the IAM token service.
246
+ The default value of this property is the "prod" IAM token service endpoint
247
+ (` https://iam.cloud.ibm.com ` ).
248
+
249
+ - clientId/clientSecret: (optional) The ` clientId ` and ` clientSecret ` fields are used to form a
250
+ "basic auth" Authorization header for interactions with the IAM token service. If neither field
251
+ is specified, then no Authorization header will be sent with token server requests. These fields
252
+ are optional, but must be specified together.
253
+
254
+ - scope: (optional) the scope to be associated with the IAM access token.
255
+ If not specified, then no scope will be associated with the access token.
256
+
257
+ - disableSSLVerification: (optional) A flag that indicates whether verificaton of the server's SSL
258
+ certificate should be disabled or not. The default value is ` false ` .
259
+
260
+ - headers: (optional) A set of key/value pairs that will be sent as HTTP headers in requests
261
+ made to the IAM token service.
262
+
263
+ ### Programming example
264
+ ``` java
265
+ import com.ibm.cloud.sdk.core.security.ContainerAuthenticator ;
266
+ import <sdk_base_package>.ExampleService.v1.ExampleService ;
267
+ ...
268
+ // Create the authenticator.
269
+ ContainerAuthenticator authenticator = new ContainerAuthenticator .Builder ()
270
+ .iamProfileName(" iam-user123" )
271
+ .build();
272
+
273
+ // Create the service instance.
274
+ ExampleService service = new ExampleService (authenticator);
275
+
276
+ // 'service' can now be used to invoke operations.
277
+ ```
278
+
279
+ ### Configuration example
280
+ External configuration:
281
+ ```
282
+ export EXAMPLE_SERVICE_AUTH_TYPE=container
283
+ export EXAMPLE_SERVICE_IAM_PROFILE_NAME=iam-user123
284
+ ```
285
+ Application code:
286
+ ``` java
287
+ import com.ibm.cloud.sdk.core.security.ConfigBaseAuthenticatorFactory ;
288
+ import <sdk_base_package>.ExampleService.v1.ExampleService ;
289
+ ...
290
+ // Create the authenticator.
291
+ Authenticator authenticator = ConfigBasedAuthenticatorFactory . getAuthenticator(" example_service" );
292
+
293
+ // Create the service instance.
294
+ ExampleService service = new ExampleService (authenticator);
295
+
296
+ // 'service' can now be used to invoke operations.
297
+ ```
298
+
299
+
300
+ ## Cloud Pak for Data Authentication
187
301
The ` CloudPakForDataAuthenticator ` will accept user-supplied values for the username and either a password or apikey, and will
188
302
perform the necessary interactions with the Cloud Pak for Data token service to obtain a suitable
189
303
bearer token. The authenticator will also obtain a new bearer token when the current token expires.
@@ -192,15 +306,23 @@ form:
192
306
```
193
307
Authorization: Bearer <bearer-token>
194
308
```
309
+
195
310
### Properties
311
+
196
312
- username: (required) the username used to obtain a bearer token.
313
+
197
314
- password: (required if apikey is not specified) the password used to obtain a bearer token.
315
+
198
316
- apikey: (required if password is not specified) the apikey used to obtain a bearer token.
317
+
199
318
- url: (required) The base URL associated with the Cloud Pak for Data token service.
319
+
200
320
- disableSSLVerification: (optional) A flag that indicates whether verificaton of the server's SSL
201
321
certificate should be disabled or not. The default value is ` false ` .
322
+
202
323
- headers: (optional) A set of key/value pairs that will be sent as HTTP headers in requests
203
324
made to the IAM token service.
325
+
204
326
### Programming example
205
327
``` java
206
328
import com.ibm.cloud.sdk.core.security.CloudPakForDataAuthenticator ;
0 commit comments