modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java | 38 ++++++++++ modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java | 3 2 files changed, 41 insertions(+)
New commits: commit 80e9f520ab6dfa5fa42357aa7fa5dbfdeb98d631 Author: John Mazzitelli mazz@redhat.com Date: Thu May 9 21:50:21 2013 -0400
BZ 951382 - if keystore/truststore is left undefined in agent config, we'll explicitly set the pref for the user using the "conf/" location
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java index d959552..6e1a95a 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java @@ -2313,6 +2313,9 @@ public class AgentMain { * @throws Exception if any error causes the startup to fail */ private void startCommServices(BootstrapLatchCommandListener listener) throws Exception { + // BZ 951382 - if any locations for keystore/truststore are not configured, set our own defaults to the conf/ directory + assignDefaultLocationToKeystoreTruststoreFiles(); + // create our client sender so we can send commands to our server // do this before we create our auto-discovery listener and start the server-side services // since it will be needed by the listener very quickly if the server is already online @@ -2348,6 +2351,41 @@ public class AgentMain { return; }
+ private void assignDefaultLocationToKeystoreTruststoreFiles() { + File confDir = new File("conf"); + if (!confDir.exists()) { + return; // conf/ doesn't exist (perhaps we are running in a test?) - do nothing and just fallback to the standard defaults + } + + String prefNamesFileNames[][] = { + { ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_KEYSTORE_FILE, + ServiceContainerConfigurationConstants.DEFAULT_CONNECTOR_SECURITY_KEYSTORE_FILE_NAME }, + { ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_TRUSTSTORE_FILE, + ServiceContainerConfigurationConstants.DEFAULT_CONNECTOR_SECURITY_TRUSTSTORE_FILE_NAME }, + { AgentConfigurationConstants.CLIENT_SENDER_SECURITY_KEYSTORE_FILE, + AgentConfigurationConstants.DEFAULT_CLIENT_SENDER_SECURITY_KEYSTORE_FILE_NAME }, + { AgentConfigurationConstants.CLIENT_SENDER_SECURITY_TRUSTSTORE_FILE, + AgentConfigurationConstants.DEFAULT_CLIENT_SENDER_SECURITY_TRUSTSTORE_FILE_NAME } }; + + Preferences prefs = m_configuration.getPreferences(); + for (String[] prefNameFileName : prefNamesFileNames) { + String value = prefs.get(prefNameFileName[0], null); + if (value == null) { + value = new File(confDir, prefNameFileName[1]).getAbsolutePath(); + prefs.put(prefNameFileName[0], value); + LOG.debug(AgentI18NResourceKeys.CERT_FILE_LOCATION, prefNameFileName[0], value); + } + } + + try { + prefs.flush(); + } catch (Exception e) { + LOG.warn(AgentI18NResourceKeys.CANNOT_STORE_PREFERENCES, "keystore/truststore files", e); + } + + return; + } + private boolean isAutoDiscoveryEnabled() { return m_autoDiscoveryListener != null; } diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java index 10761ff..21a39a9 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java @@ -28,6 +28,9 @@ import mazz.i18n.annotation.I18NResourceBundle; */ @I18NResourceBundle(baseName = "agent-messages", defaultLocale = "en") public interface AgentI18NResourceKeys { + @I18NMessage("Explicitly setting file location [{0}] to [{1}]") + String CERT_FILE_LOCATION = "AgentConfiguration.cert-file-location"; + @I18NMessage("The configured server alias [{0}] cannot be resolved - will use localhost address. Cause: {1}") String SERVER_ALIAS_UNKNOWN = "AgentConfiguration.server-alias-unknown";
rhq-commits@lists.fedorahosted.org