From 7f88d9f95c8da1675dd5314bb41f7fe2516e2003 Mon Sep 17 00:00:00 2001 From: ashitsalesforce Date: Mon, 14 Oct 2024 00:30:30 -0700 Subject: [PATCH] register all properties in a registry register all properties in a registry --- .../dataloader/config/AppConfig.java | 41 ++++++++++++++++--- .../config/ConfigPropertyMetadata.java | 28 ++++++++++++- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/salesforce/dataloader/config/AppConfig.java b/src/main/java/com/salesforce/dataloader/config/AppConfig.java index 0ff70c78..5bdeda8e 100644 --- a/src/main/java/com/salesforce/dataloader/config/AppConfig.java +++ b/src/main/java/com/salesforce/dataloader/config/AppConfig.java @@ -281,6 +281,18 @@ public class AppConfig { public static final String PROP_OAUTH_CLIENTID = OAUTH_PREFIX + OAUTH_PARTIAL_CLIENTID; public static final String PROP_OAUTH_REDIRECTURI = OAUTH_PREFIX + OAUTH_PARTIAL_REDIRECTURI; public static final String PROP_OAUTH_LOGIN_FROM_BROWSER = OAUTH_PREFIX + "loginfrombrowser"; + public static final String PROP_OAUTH_CLIENTID_PROD_PARTNER = OAUTH_PREFIX + + PROD_ENVIRONMENT_VAL + + "." + OAUTH_PARTIAL_PARTNER_CLIENTID; + public static final String PROP_OAUTH_CLIENTID_PROD_BULK = OAUTH_PREFIX + + PROD_ENVIRONMENT_VAL + + "." + OAUTH_PARTIAL_BULK_CLIENTID; + public static final String PROP_OAUTH_CLIENTID_SANDBOX_PARTNER = OAUTH_PREFIX + + SB_ENVIRONMENT_VAL + + "." + OAUTH_PARTIAL_PARTNER_CLIENTID; + public static final String PROP_OAUTH_CLIENTID_SANDBOX_BULK = OAUTH_PREFIX + + SB_ENVIRONMENT_VAL + + "." + OAUTH_PARTIAL_BULK_CLIENTID; public static final String OAUTH_REDIRECT_URI_SUFFIX = "services/oauth2/success"; public static final String PROP_REUSE_CLIENT_CONNECTION = "sfdc.reuseClientConnection"; public static final String PROP_RICH_TEXT_FIELD_REGEX = "sfdx.richtext.regex"; @@ -453,7 +465,7 @@ public class AppConfig { // Following properties are read-only, i.e. they are not overridden during save() to config.properties // - These properties are not set in Advanced Settings dialog. // - Make sure to list all sensitive properties such as password because these properties are not saved. - static final String[] READ_ONLY_PROPERTY_NAMES = { + private static final String[] READ_ONLY_PROPERTY_NAMES = { PROP_PASSWORD, PROP_IDLOOKUP_FIELD, PROP_MAPPING_FILE, @@ -497,7 +509,13 @@ public class AppConfig { PROP_USE_SYSTEM_PROPS_FOR_HTTP_CLIENT, }; - static final String[] ENCRYPTED_PROPERTY_NAMES = { + // internal properties are derived in code. + // They are neither read from, nor written to config.properties file. + private static final String[] INTERNAL_PROPERTY_NAMES = { + PROP_OAUTH_CLIENTID, + }; + + private static final String[] ENCRYPTED_PROPERTY_NAMES = { PROP_PASSWORD, PROP_PROXY_PASSWORD, PROP_OAUTH_ACCESSTOKEN, @@ -634,11 +652,11 @@ private void setDefaults(Map cliOptionsMap) { setDefaultValue(PROP_AUTH_ENVIRONMENTS, PROD_ENVIRONMENT_VAL + AppUtil.COMMA + SB_ENVIRONMENT_VAL); /* sfdc.oauth...clientid = DataLoaderBulkUI | DataLoaderPartnerUI */ - setDefaultValue(OAUTH_PREFIX + PROD_ENVIRONMENT_VAL + "." + OAUTH_PARTIAL_BULK_CLIENTID, OAUTH_BULK_CLIENTID_VAL); - setDefaultValue(OAUTH_PREFIX + PROD_ENVIRONMENT_VAL + "." + OAUTH_PARTIAL_PARTNER_CLIENTID, OAUTH_PARTNER_CLIENTID_VAL); + setDefaultValue(PROP_OAUTH_CLIENTID_PROD_BULK, OAUTH_BULK_CLIENTID_VAL); + setDefaultValue(PROP_OAUTH_CLIENTID_PROD_PARTNER, OAUTH_PARTNER_CLIENTID_VAL); - setDefaultValue(OAUTH_PREFIX + SB_ENVIRONMENT_VAL + "." + OAUTH_PARTIAL_BULK_CLIENTID, OAUTH_BULK_CLIENTID_VAL); - setDefaultValue(OAUTH_PREFIX + SB_ENVIRONMENT_VAL + "." + OAUTH_PARTIAL_PARTNER_CLIENTID, OAUTH_PARTNER_CLIENTID_VAL); + setDefaultValue(PROP_OAUTH_CLIENTID_SANDBOX_BULK, OAUTH_BULK_CLIENTID_VAL); + setDefaultValue(PROP_OAUTH_CLIENTID_SANDBOX_PARTNER, OAUTH_PARTNER_CLIENTID_VAL); setDefaultValue(PROP_OPERATION, "insert"); setDefaultValue(PROP_REUSE_CLIENT_CONNECTION, true); @@ -1021,6 +1039,17 @@ public static boolean isReadOnlyProperty(String propertyName) { return false; } + public static boolean isInternalProperty(String propertyName) { + if (propertyName == null) { + return false; + } + for (String roProp : AppConfig.INTERNAL_PROPERTY_NAMES) { + if (roProp.equals(propertyName)) { + return true; + } + } + return false; + } public static boolean isEncryptedProperty(String propertyName) { if (propertyName == null) { return false; diff --git a/src/main/java/com/salesforce/dataloader/config/ConfigPropertyMetadata.java b/src/main/java/com/salesforce/dataloader/config/ConfigPropertyMetadata.java index e6a5f464..a18aafa0 100644 --- a/src/main/java/com/salesforce/dataloader/config/ConfigPropertyMetadata.java +++ b/src/main/java/com/salesforce/dataloader/config/ConfigPropertyMetadata.java @@ -29,6 +29,7 @@ import java.util.HashMap; import com.salesforce.dataloader.ui.Labels; +import com.salesforce.dataloader.util.AppUtil; /* * Data class capturing information about configuration property (aka Setting). @@ -40,6 +41,7 @@ public class ConfigPropertyMetadata { private String defaultValue = ""; private boolean readOnly = false; private boolean encrypted = false; + private boolean internal = false; private boolean commandLineOption = false; private final String uiLabelTemplate; private final String uiTooltipTemplate; @@ -47,7 +49,8 @@ public class ConfigPropertyMetadata { static { Field[] appConfigFields = AppConfig.class.getDeclaredFields(); for (Field configField : appConfigFields) { - if (configField.getName().startsWith("PROP_")) { + if (configField.getName().startsWith("PROP_") + || configField.getName().startsWith("CLI_OPTION_")) { String propName; try { propName = configField.get(null).toString(); @@ -57,6 +60,21 @@ public class ConfigPropertyMetadata { ConfigPropertyMetadata configProp = new ConfigPropertyMetadata(configField.getName()); configProp.setEncrypted(AppConfig.isEncryptedProperty(propName)); configProp.setReadOnly(AppConfig.isReadOnlyProperty(propName)); + configProp.setInternal(AppConfig.isInternalProperty(propName)); + propertiesMap.put(propName, configProp); + } + } + Field[] appUtilFields = AppUtil.class.getDeclaredFields(); + for (Field configField : appUtilFields) { + if (configField.getName().startsWith("CLI_OPTION_")) { + String propName; + try { + propName = configField.get(null).toString(); + } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { + continue; + } + ConfigPropertyMetadata configProp = new ConfigPropertyMetadata(configField.getName()); + configProp.setReadOnly(true); propertiesMap.put(propName, configProp); } } @@ -124,4 +142,12 @@ public String getUiLabelTemplate() { public String getUiTooltip() { return uiTooltipTemplate; } + + public boolean isInternal() { + return internal; + } + + public void setInternal(boolean internal) { + this.internal = internal; + } } \ No newline at end of file