From e9516055b34f3dd45f2ff6fbdd7479871e30de99 Mon Sep 17 00:00:00 2001 From: nsingh Date: Tue, 17 Jan 2017 11:28:21 -0800 Subject: [PATCH] Fixed bug when checking if refresh token is set in CLI config.json --- .../client/cftarget/CfCliParamsProvider.java | 28 +++++++++++-------- .../client/cftarget/ClientParamsProvider.java | 3 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/CfCliParamsProvider.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/CfCliParamsProvider.java index 7e2c79e91..b7a1f39dc 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/CfCliParamsProvider.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/CfCliParamsProvider.java @@ -50,18 +50,17 @@ public class CfCliParamsProvider implements ClientParamsProvider { if (userData != null) { String refreshToken = (String) userData.get(REFRESH_TOKEN); // Only support connecting to CF via refresh token for now - if (refreshToken == null) { - return null; - } - CFCredentials credentials = CFCredentials.fromRefreshToken(refreshToken); - boolean sslDisabled = (Boolean) userData.get(SSL_DISABLED); - String target = (String) userData.get(TARGET); - Map orgFields = (Map) userData.get(ORGANIZATION_FIELDS); - Map spaceFields = (Map) userData.get(SPACE_FIELDS); - if (target != null && orgFields != null && spaceFields != null) { - String orgName = (String) orgFields.get(NAME); - String spaceName = (String) spaceFields.get(NAME); - params.add(new CFClientParams(target, null, credentials, orgName, spaceName, sslDisabled)); + if (isRefreshTokenSet(refreshToken)) { + CFCredentials credentials = CFCredentials.fromRefreshToken(refreshToken); + boolean sslDisabled = (Boolean) userData.get(SSL_DISABLED); + String target = (String) userData.get(TARGET); + Map orgFields = (Map) userData.get(ORGANIZATION_FIELDS); + Map spaceFields = (Map) userData.get(SPACE_FIELDS); + if (target != null && orgFields != null && spaceFields != null) { + String orgName = (String) orgFields.get(NAME); + String spaceName = (String) spaceFields.get(NAME); + params.add(new CFClientParams(target, null, credentials, orgName, spaceName, sslDisabled)); + } } } } @@ -73,6 +72,10 @@ public class CfCliParamsProvider implements ClientParamsProvider { return params; } } + + private boolean isRefreshTokenSet(String token) { + return token != null && token.trim().length() > 0; + } private File getConfigJsonFile() throws IOException, InterruptedException { // Support Unix systems for now @@ -95,4 +98,5 @@ public class CfCliParamsProvider implements ClientParamsProvider { private String getUnixHomeDir() throws IOException, InterruptedException { return System.getProperty("user.home"); } + } diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/ClientParamsProvider.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/ClientParamsProvider.java index f8c4d9f6f..39e94a961 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/ClientParamsProvider.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/ClientParamsProvider.java @@ -16,9 +16,10 @@ public interface ClientParamsProvider { /** * - * @return non-null list of params to connect to Cloud Foundry + * @return non-null list of VALID params to connect to Cloud Foundry * @throws Exception if failure to resolve any params for Cloud Foundry */ List getParams() throws Exception; + } \ No newline at end of file