@@ -223,7 +223,45 @@ public Iterator<Setting<?>> settings() {
223223 */
224224 public static final Setting .AffixSetting <String > AUTH_PASSWORD_SETTING =
225225 Setting .affixKeySetting ("xpack.monitoring.exporters." ,"auth.password" ,
226- (key ) -> Setting .simpleString (key , Property .Dynamic , Property .NodeScope , Property .Filtered ));
226+ (key ) -> Setting .simpleString (key ,
227+ new Setting .Validator <String >() {
228+ @ Override
229+ public void validate (String password ) {
230+ // no password validation that is independent of other settings
231+ }
232+
233+ @ Override
234+ public void validate (String password , Map <Setting <?>, Object > settings ) {
235+ final String namespace =
236+ HttpExporter .AUTH_PASSWORD_SETTING .getNamespace (
237+ HttpExporter .AUTH_PASSWORD_SETTING .getConcreteSetting (key ));
238+ final String username =
239+ (String ) settings .get (AUTH_USERNAME_SETTING .getConcreteSettingForNamespace (namespace ));
240+
241+ // username is required for any auth
242+ if (Strings .isNullOrEmpty (username )) {
243+ if (Strings .isNullOrEmpty (password ) == false ) {
244+ throw new IllegalArgumentException (
245+ "[" + AUTH_PASSWORD_SETTING .getConcreteSettingForNamespace (namespace ).getKey () + "] without [" +
246+ AUTH_USERNAME_SETTING .getConcreteSettingForNamespace (namespace ).getKey () + "]" );
247+ }
248+ }
249+ }
250+
251+ @ Override
252+ public Iterator <Setting <?>> settings () {
253+ final String namespace =
254+ HttpExporter .AUTH_PASSWORD_SETTING .getNamespace (
255+ HttpExporter .AUTH_PASSWORD_SETTING .getConcreteSetting (key ));
256+ final List <Setting <?>> settings = List .of (
257+ HttpExporter .AUTH_USERNAME_SETTING .getConcreteSettingForNamespace (namespace ));
258+ return settings .iterator ();
259+ }
260+
261+ },
262+ Property .Dynamic ,
263+ Property .NodeScope ,
264+ Property .Filtered ));
227265 /**
228266 * The SSL settings.
229267 *
@@ -634,17 +672,6 @@ private static CredentialsProvider createCredentialsProvider(final Config config
634672 final String username = AUTH_USERNAME_SETTING .getConcreteSettingForNamespace (config .name ()).get (config .settings ());
635673 final String password = AUTH_PASSWORD_SETTING .getConcreteSettingForNamespace (config .name ()).get (config .settings ());
636674
637- // username is required for any auth
638- if (Strings .isNullOrEmpty (username )) {
639- if (Strings .isNullOrEmpty (password ) == false ) {
640- throw new SettingsException (
641- "[" + AUTH_PASSWORD_SETTING .getConcreteSettingForNamespace (config .name ()).getKey () + "] without [" +
642- AUTH_USERNAME_SETTING .getConcreteSettingForNamespace (config .name ()).getKey () + "]" );
643- }
644- // nothing to configure; default situation for most users
645- return null ;
646- }
647-
648675 final CredentialsProvider credentialsProvider = new BasicCredentialsProvider ();
649676 credentialsProvider .setCredentials (AuthScope .ANY , new UsernamePasswordCredentials (username , password ));
650677
0 commit comments