@@ -121,6 +121,11 @@ public WatsonService(final String name) {
121121 client = configureHttpClient ();
122122 }
123123
124+ /**
125+ * Calls appropriate methods to set credential values based on parsed ServiceCredentials object.
126+ *
127+ * @param serviceCredentials object containing parsed credential values
128+ */
124129 private void setCredentialFields (CredentialUtils .ServiceCredentials serviceCredentials ) {
125130 setEndPoint (serviceCredentials .getUrl ());
126131
@@ -341,6 +346,11 @@ public String getName() {
341346 * @param apiKey the new API key
342347 */
343348 public void setApiKey (String apiKey ) {
349+ if (CredentialUtils .hasBadStartOrEndChar (apiKey )) {
350+ throw new IllegalArgumentException ("The API key shouldn't start or end with curly brackets or quotes. Please "
351+ + "remove any surrounding {, }, or \" characters." );
352+ }
353+
344354 if (this .endPoint .equals (this .defaultEndPoint )) {
345355 this .endPoint = "https://gateway-a.watsonplatform.net/visual-recognition/api" ;
346356 }
@@ -376,6 +386,11 @@ protected void setAuthentication(final Builder builder) {
376386 * @param endPoint the new end point. Will be ignored if empty or null
377387 */
378388 public void setEndPoint (final String endPoint ) {
389+ if (CredentialUtils .hasBadStartOrEndChar (endPoint )) {
390+ throw new IllegalArgumentException ("The URL shouldn't start or end with curly brackets or quotes. Please "
391+ + "remove any surrounding {, }, or \" characters." );
392+ }
393+
379394 if ((endPoint != null ) && !endPoint .isEmpty ()) {
380395 String newEndPoint = endPoint .endsWith ("/" ) ? endPoint .substring (0 , endPoint .length () - 1 ) : endPoint ;
381396 if (this .endPoint == null ) {
@@ -392,6 +407,11 @@ public void setEndPoint(final String endPoint) {
392407 * @param password the password
393408 */
394409 public void setUsernameAndPassword (final String username , final String password ) {
410+ if (CredentialUtils .hasBadStartOrEndChar (username ) || CredentialUtils .hasBadStartOrEndChar (password )) {
411+ throw new IllegalArgumentException ("The username and password shouldn't start or end with curly brackets or "
412+ + "quotes. Please remove any surrounding {, }, or \" characters." );
413+ }
414+
395415 // we'll perform the token exchange for users UNLESS they're on ICP
396416 if (username .equals (APIKEY_AS_USERNAME ) && !password .startsWith (ICP_PREFIX )) {
397417 IamOptions iamOptions = new IamOptions .Builder ()
0 commit comments