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