File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
main/java/com/ibm/watson/developer_cloud/service
test/java/com/ibm/watson/developer_cloud/service Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ public abstract class WatsonService {
7070 private static final String BASIC = "Basic " ;
7171 private static final String BEARER = "Bearer " ;
7272 private static final String APIKEY_AS_USERNAME = "apikey" ;
73+ private static final String ICP_PREFIX = "icp-" ;
7374 private static final Logger LOG = Logger .getLogger (WatsonService .class .getName ());
7475 private static final String AUTH_HEADER_DEPRECATION_MESSAGE = "Authenticating with the X-Watson-Authorization-Token"
7576 + "header is deprecated. The token continues to work with Cloud Foundry services, but is not supported for "
@@ -350,7 +351,8 @@ public void setEndPoint(final String endPoint) {
350351 * @param password the password
351352 */
352353 public void setUsernameAndPassword (final String username , final String password ) {
353- if (username .equals (APIKEY_AS_USERNAME )) {
354+ // we'll perform the token exchange for users UNLESS they're on ICP
355+ if (username .equals (APIKEY_AS_USERNAME ) && !password .startsWith (ICP_PREFIX )) {
354356 IamOptions iamOptions = new IamOptions .Builder ()
355357 .apiKey (password )
356358 .build ();
Original file line number Diff line number Diff line change 33import org .junit .Test ;
44
55import static org .junit .Assert .assertTrue ;
6+ import static org .junit .Assert .assertFalse ;
67
78public 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}
You can’t perform that action at this time.
0 commit comments