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 @@ -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 ();
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