Skip to content

Commit 57d5532

Browse files
authored
Merge branch 'master' into pa/core-updates
2 parents 319edc2 + 07d95aa commit 57d5532

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

core/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public abstract class WatsonService {
7171
private static final String BASIC = "Basic ";
7272
private static final String BEARER = "Bearer ";
7373
private static final String APIKEY_AS_USERNAME = "apikey";
74+
private static final String ICP_PREFIX = "icp-";
7475
private static final Logger LOG = Logger.getLogger(WatsonService.class.getName());
7576
private static final String AUTH_HEADER_DEPRECATION_MESSAGE = "Authenticating with the X-Watson-Authorization-Token"
7677
+ "header is deprecated. The token continues to work with Cloud Foundry services, but is not supported for "
@@ -378,7 +379,8 @@ public void setEndPoint(final String endPoint) {
378379
* @param password the password
379380
*/
380381
public void setUsernameAndPassword(final String username, final String password) {
381-
if (username.equals(APIKEY_AS_USERNAME)) {
382+
// we'll perform the token exchange for users UNLESS they're on ICP
383+
if (username.equals(APIKEY_AS_USERNAME) && !password.startsWith(ICP_PREFIX)) {
382384
IamOptions iamOptions = new IamOptions.Builder()
383385
.apiKey(password)
384386
.build();

core/src/test/java/com/ibm/watson/developer_cloud/service/AuthenticationTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import org.junit.Test;
44

55
import static org.junit.Assert.assertTrue;
6+
import static org.junit.Assert.assertFalse;
67

78
public class AuthenticationTest {
9+
private static final String APIKEY_USERNAME = "apikey";
810
private static final String APIKEY = "12345";
11+
private static final String ICP_APIKEY = "icp-12345";
912

1013
public class TestService extends WatsonService {
1114
private static final String SERVICE_NAME = "test";
@@ -18,7 +21,14 @@ public TestService() {
1821
@Test
1922
public void authenticateWithApiKeyAsUsername() {
2023
TestService service = new TestService();
21-
service.setUsernameAndPassword("apikey", APIKEY);
24+
service.setUsernameAndPassword(APIKEY_USERNAME, APIKEY);
2225
assertTrue(service.isTokenManagerSet());
2326
}
27+
28+
@Test
29+
public void authenticateWithIcp() {
30+
TestService service = new TestService();
31+
service.setUsernameAndPassword(APIKEY_USERNAME, ICP_APIKEY);
32+
assertFalse(service.isTokenManagerSet());
33+
}
2434
}

0 commit comments

Comments
 (0)