浏览代码

Rename RealmConfig.globalSettings() to settings() (#35330)

There is no longer a concept of non-global "realm settings". All realm
settings should be loaded from the node's settings using standard
Setting classes.

This change renames the "globalSettings" field and method to simply be
"settings".
Tim Vernum 7 年之前
父节点
当前提交
7d05257896

+ 23 - 19
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/RealmConfig.java

@@ -20,16 +20,15 @@ public class RealmConfig {
     final boolean enabled;
     final boolean enabled;
     final int order;
     final int order;
     private final Environment env;
     private final Environment env;
-    private final Settings globalSettings;
+    private final Settings settings;
     private final ThreadContext threadContext;
     private final ThreadContext threadContext;
 
 
-    public RealmConfig(RealmIdentifier identifier, Settings globalSettings, Environment env,
-                       ThreadContext threadContext) {
+    public RealmConfig(RealmIdentifier identifier, Settings settings, Environment env, ThreadContext threadContext) {
         this.identifier = identifier;
         this.identifier = identifier;
-        this.globalSettings = globalSettings;
+        this.settings = settings;
         this.env = env;
         this.env = env;
-        enabled = getSetting(RealmSettings.ENABLED_SETTING);
-        order = getSetting(RealmSettings.ORDER_SETTING);
+        this.enabled = getSetting(RealmSettings.ENABLED_SETTING);
+        this.order = getSetting(RealmSettings.ORDER_SETTING);
         this.threadContext = threadContext;
         this.threadContext = threadContext;
     }
     }
 
 
@@ -53,8 +52,13 @@ public class RealmConfig {
         return identifier.type;
         return identifier.type;
     }
     }
 
 
-    public Settings globalSettings() {
-        return globalSettings;
+    /**
+     * @return The settings for the current node.
+     * This will include the settings for this realm (as well as other realms, and other non-security settings).
+     * @see #getConcreteSetting(Setting.AffixSetting)
+     */
+    public Settings settings() {
+        return settings;
     }
     }
 
 
     public Environment env() {
     public Environment env() {
@@ -95,16 +99,16 @@ public class RealmConfig {
     }
     }
 
 
     /**
     /**
-     * Obtain the value of the provided {@code setting} from the node's {@link #globalSettings global settings}.
+     * Obtain the value of the provided {@code setting} from the node's {@link #settings global settings}.
      * The {@link Setting.AffixSetting} is made <em>concrete</em> through {@link #getConcreteSetting(Setting.AffixSetting)}, which is then
      * The {@link Setting.AffixSetting} is made <em>concrete</em> through {@link #getConcreteSetting(Setting.AffixSetting)}, which is then
      * used to {@link Setting#get(Settings) retrieve} the setting value.
      * used to {@link Setting#get(Settings) retrieve} the setting value.
      */
      */
     public <T> T getSetting(Setting.AffixSetting<T> setting) {
     public <T> T getSetting(Setting.AffixSetting<T> setting) {
-        return getConcreteSetting(setting).get(globalSettings);
+        return getConcreteSetting(setting).get(settings);
     }
     }
 
 
     /**
     /**
-     * Obtain the value of the provided {@code setting} from the node's {@link #globalSettings global settings}.
+     * Obtain the value of the provided {@code setting} from the node's {@link #settings global settings}.
      * {@link #getConcreteSetting(Function)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link #getConcreteSetting(Function)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link Function}/{@link Setting.AffixSetting}, and this <em>concrete setting</em> is then used to
      * {@link Function}/{@link Setting.AffixSetting}, and this <em>concrete setting</em> is then used to
      * {@link Setting#get(Settings) retrieve} the setting value.
      * {@link Setting#get(Settings) retrieve} the setting value.
@@ -114,7 +118,7 @@ public class RealmConfig {
     }
     }
 
 
     /**
     /**
-     * Obtain the value of the provided {@code setting} from the node's {@link #globalSettings global settings}.
+     * Obtain the value of the provided {@code setting} from the node's {@link #settings global settings}.
      * {@link #getConcreteSetting(Function)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link #getConcreteSetting(Function)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link Function}/{@link Setting.AffixSetting}.
      * {@link Function}/{@link Setting.AffixSetting}.
      * If this <em>concrete setting</em> {@link Setting#exists(Settings) exists} in the global settings, then its value is returned,
      * If this <em>concrete setting</em> {@link Setting#exists(Settings) exists} in the global settings, then its value is returned,
@@ -125,7 +129,7 @@ public class RealmConfig {
     }
     }
 
 
     /**
     /**
-     * Obtain the value of the provided {@code setting} from the node's {@link #globalSettings global settings}.
+     * Obtain the value of the provided {@code setting} from the node's {@link #settings global settings}.
      * {@link #getConcreteSetting(Setting.AffixSetting)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link #getConcreteSetting(Setting.AffixSetting)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link Setting.AffixSetting}.
      * {@link Setting.AffixSetting}.
      * If this <em>concrete setting</em> {@link Setting#exists(Settings) exists} in the global settings, then its value is returned,
      * If this <em>concrete setting</em> {@link Setting#exists(Settings) exists} in the global settings, then its value is returned,
@@ -133,30 +137,30 @@ public class RealmConfig {
      */
      */
     public <T> T getSetting(Setting.AffixSetting<T> setting, Supplier<T> orElse) {
     public <T> T getSetting(Setting.AffixSetting<T> setting, Supplier<T> orElse) {
         final Setting<T> concrete = setting.getConcreteSettingForNamespace(name());
         final Setting<T> concrete = setting.getConcreteSettingForNamespace(name());
-        if (concrete.exists(globalSettings)) {
-            return concrete.get(globalSettings);
+        if (concrete.exists(settings)) {
+            return concrete.get(settings);
         } else {
         } else {
             return orElse.get();
             return orElse.get();
         }
         }
     }
     }
 
 
     /**
     /**
-     * Determines whether the provided {@code setting} has an explicit value in the node's {@link #globalSettings global settings}.
+     * Determines whether the provided {@code setting} has an explicit value in the node's {@link #settings global settings}.
      * {@link #getConcreteSetting(Function)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link #getConcreteSetting(Function)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link Function}/{@link Setting.AffixSetting}, and this <em>concrete setting</em> is then used to
      * {@link Function}/{@link Setting.AffixSetting}, and this <em>concrete setting</em> is then used to
      * {@link Setting#exists(Settings) check} for a value.
      * {@link Setting#exists(Settings) check} for a value.
      */
      */
     public <T> boolean hasSetting(Function<String, Setting.AffixSetting<T>> settingFactory) {
     public <T> boolean hasSetting(Function<String, Setting.AffixSetting<T>> settingFactory) {
-        return getConcreteSetting(settingFactory).exists(globalSettings);
+        return getConcreteSetting(settingFactory).exists(settings);
     }
     }
 
 
     /**
     /**
-     * Determines whether the provided {@code setting} has an explicit value in the node's {@link #globalSettings global settings}.
+     * Determines whether the provided {@code setting} has an explicit value in the node's {@link #settings global settings}.
      * {@link #getConcreteSetting(Setting.AffixSetting)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link #getConcreteSetting(Setting.AffixSetting)} is used to obtain a <em>concrete setting</em> from the provided
      * {@link Setting.AffixSetting}, and this <em>concrete setting</em> is then used to {@link Setting#exists(Settings) check} for a value.
      * {@link Setting.AffixSetting}, and this <em>concrete setting</em> is then used to {@link Setting#exists(Settings) check} for a value.
      */
      */
     public <T> boolean hasSetting(Setting.AffixSetting<T> setting) {
     public <T> boolean hasSetting(Setting.AffixSetting<T> setting) {
-        return getConcreteSetting(setting).exists(globalSettings);
+        return getConcreteSetting(setting).exists(settings);
     }
     }
 
 
     /**
     /**

+ 4 - 4
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/ReservedRealm.java

@@ -87,7 +87,7 @@ public class ReservedRealm extends CachingUsernamePasswordRealm {
     protected void doAuthenticate(UsernamePasswordToken token, ActionListener<AuthenticationResult> listener) {
     protected void doAuthenticate(UsernamePasswordToken token, ActionListener<AuthenticationResult> listener) {
         if (realmEnabled == false) {
         if (realmEnabled == false) {
             listener.onResponse(AuthenticationResult.notHandled());
             listener.onResponse(AuthenticationResult.notHandled());
-        } else if (ClientReservedRealm.isReserved(token.principal(), config.globalSettings()) == false) {
+        } else if (ClientReservedRealm.isReserved(token.principal(), config.settings()) == false) {
             listener.onResponse(AuthenticationResult.notHandled());
             listener.onResponse(AuthenticationResult.notHandled());
         } else {
         } else {
             getUserInfo(token.principal(), ActionListener.wrap((userInfo) -> {
             getUserInfo(token.principal(), ActionListener.wrap((userInfo) -> {
@@ -120,13 +120,13 @@ public class ReservedRealm extends CachingUsernamePasswordRealm {
     @Override
     @Override
     protected void doLookupUser(String username, ActionListener<User> listener) {
     protected void doLookupUser(String username, ActionListener<User> listener) {
         if (realmEnabled == false) {
         if (realmEnabled == false) {
-            if (anonymousEnabled && AnonymousUser.isAnonymousUsername(username, config.globalSettings())) {
+            if (anonymousEnabled && AnonymousUser.isAnonymousUsername(username, config.settings())) {
                 listener.onResponse(anonymousUser);
                 listener.onResponse(anonymousUser);
             }
             }
             listener.onResponse(null);
             listener.onResponse(null);
-        } else if (ClientReservedRealm.isReserved(username, config.globalSettings()) == false) {
+        } else if (ClientReservedRealm.isReserved(username, config.settings()) == false) {
             listener.onResponse(null);
             listener.onResponse(null);
-        } else if (AnonymousUser.isAnonymousUsername(username, config.globalSettings())) {
+        } else if (AnonymousUser.isAnonymousUsername(username, config.settings())) {
             listener.onResponse(anonymousEnabled ? anonymousUser : null);
             listener.onResponse(anonymousEnabled ? anonymousUser : null);
         } else {
         } else {
             getUserInfo(username, ActionListener.wrap((userInfo) -> {
             getUserInfo(username, ActionListener.wrap((userInfo) -> {

+ 1 - 1
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/file/FileUserPasswdStore.java

@@ -56,7 +56,7 @@ public class FileUserPasswdStore {
 
 
     FileUserPasswdStore(RealmConfig config, ResourceWatcherService watcherService, Runnable listener) {
     FileUserPasswdStore(RealmConfig config, ResourceWatcherService watcherService, Runnable listener) {
         file = resolveFile(config.env());
         file = resolveFile(config.env());
-        settings = config.globalSettings();
+        settings = config.settings();
         users = parseFileLenient(file, logger, settings);
         users = parseFileLenient(file, logger, settings);
         listeners = new CopyOnWriteArrayList<>(Collections.singletonList(listener));
         listeners = new CopyOnWriteArrayList<>(Collections.singletonList(listener));
         FileWatcher watcher = new FileWatcher(file.getParent());
         FileWatcher watcher = new FileWatcher(file.getParent());

+ 1 - 1
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/pki/PkiRealm.java

@@ -249,7 +249,7 @@ public class PkiRealm extends Realm implements CachingRealm {
         try (SecureString password = realmConfig.getSetting(PkiRealmSettings.TRUST_STORE_PASSWORD)) {
         try (SecureString password = realmConfig.getSetting(PkiRealmSettings.TRUST_STORE_PASSWORD)) {
             String trustStoreAlgorithm = realmConfig.getSetting(PkiRealmSettings.TRUST_STORE_ALGORITHM);
             String trustStoreAlgorithm = realmConfig.getSetting(PkiRealmSettings.TRUST_STORE_ALGORITHM);
             String trustStoreType = SSLConfigurationSettings.getKeyStoreType(
             String trustStoreType = SSLConfigurationSettings.getKeyStoreType(
-                    realmConfig.getConcreteSetting(PkiRealmSettings.TRUST_STORE_TYPE), realmConfig.globalSettings(),
+                    realmConfig.getConcreteSetting(PkiRealmSettings.TRUST_STORE_TYPE), realmConfig.settings(),
                     truststorePath);
                     truststorePath);
             try {
             try {
                 return CertParsingUtils.trustManager(truststorePath, trustStoreType, password.getChars(), trustStoreAlgorithm, realmConfig
                 return CertParsingUtils.trustManager(truststorePath, trustStoreType, password.getChars(), trustStoreAlgorithm, realmConfig

+ 2 - 3
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlMetadataCommand.java

@@ -32,7 +32,6 @@ import joptsimple.OptionSpec;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.LogManager;
 import org.elasticsearch.cli.EnvironmentAwareCommand;
 import org.elasticsearch.cli.EnvironmentAwareCommand;
 import org.elasticsearch.cli.ExitCodes;
 import org.elasticsearch.cli.ExitCodes;
 import org.elasticsearch.cli.SuppressForbidden;
 import org.elasticsearch.cli.SuppressForbidden;
@@ -158,7 +157,7 @@ public class SamlMetadataCommand extends EnvironmentAwareCommand {
         final boolean batch = options.has(batchSpec);
         final boolean batch = options.has(batchSpec);
 
 
         final RealmConfig realm = findRealm(terminal, options, env);
         final RealmConfig realm = findRealm(terminal, options, env);
-        final Settings realmSettings = realm.globalSettings().getByPrefix(RealmSettings.realmSettingPrefix(realm.identifier()));
+        final Settings realmSettings = realm.settings().getByPrefix(RealmSettings.realmSettingPrefix(realm.identifier()));
         terminal.println(Terminal.Verbosity.VERBOSE,
         terminal.println(Terminal.Verbosity.VERBOSE,
                 "Using realm configuration\n=====\n" + realmSettings.toDelimitedString('\n') + "=====");
                 "Using realm configuration\n=====\n" + realmSettings.toDelimitedString('\n') + "=====");
         final Locale locale = findLocale(options);
         final Locale locale = findLocale(options);
@@ -399,7 +398,7 @@ public class SamlMetadataCommand extends EnvironmentAwareCommand {
             attributes.put(a, null);
             attributes.put(a, null);
         }
         }
         final String prefix = RealmSettings.realmSettingPrefix(realm.identifier()) + SamlRealmSettings.AttributeSetting.ATTRIBUTES_PREFIX;
         final String prefix = RealmSettings.realmSettingPrefix(realm.identifier()) + SamlRealmSettings.AttributeSetting.ATTRIBUTES_PREFIX;
-        final Settings attributeSettings = realm.globalSettings().getByPrefix(prefix);
+        final Settings attributeSettings = realm.settings().getByPrefix(prefix);
         for (String key : sorted(attributeSettings.keySet())) {
         for (String key : sorted(attributeSettings.keySet())) {
             final String attr = attributeSettings.get(key);
             final String attr = attributeSettings.get(key);
             attributes.put(attr, key);
             attributes.put(attr, key);

+ 2 - 2
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlRealm.java

@@ -179,7 +179,7 @@ public final class SamlRealm extends Realm implements Releasable {
                                    UserRoleMapper roleMapper) throws Exception {
                                    UserRoleMapper roleMapper) throws Exception {
         SamlUtils.initialize(logger);
         SamlUtils.initialize(logger);
 
 
-        if (TokenService.isTokenServiceEnabled(config.globalSettings()) == false) {
+        if (TokenService.isTokenServiceEnabled(config.settings()) == false) {
             throw new IllegalStateException("SAML requires that the token service be enabled ("
             throw new IllegalStateException("SAML requires that the token service be enabled ("
                     + XPackSettings.TOKEN_SERVICE_ENABLED_SETTING.getKey() + ")");
                     + XPackSettings.TOKEN_SERVICE_ENABLED_SETTING.getKey() + ")");
         }
         }
@@ -317,7 +317,7 @@ public final class SamlRealm extends Realm implements Releasable {
     private static List<X509Credential> buildCredential(RealmConfig config, String prefix, Setting.AffixSetting<String> aliasSetting,
     private static List<X509Credential> buildCredential(RealmConfig config, String prefix, Setting.AffixSetting<String> aliasSetting,
                                                         boolean allowMultiple) {
                                                         boolean allowMultiple) {
         final X509KeyPairSettings keyPairSettings = X509KeyPairSettings.withPrefix(prefix, false);
         final X509KeyPairSettings keyPairSettings = X509KeyPairSettings.withPrefix(prefix, false);
-        final X509KeyManager keyManager = CertParsingUtils.getKeyManager(keyPairSettings, config.globalSettings(), null, config.env());
+        final X509KeyManager keyManager = CertParsingUtils.getKeyManager(keyPairSettings, config.settings(), null, config.env());
         if (keyManager == null) {
         if (keyManager == null) {
             return null;
             return null;
         }
         }

+ 1 - 1
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/DelegatedAuthorizationSupport.java

@@ -46,7 +46,7 @@ public class DelegatedAuthorizationSupport {
      * {@link #DelegatedAuthorizationSupport(Iterable, List, Settings, ThreadContext, XPackLicenseState)}
      * {@link #DelegatedAuthorizationSupport(Iterable, List, Settings, ThreadContext, XPackLicenseState)}
      */
      */
     public DelegatedAuthorizationSupport(Iterable<? extends Realm> allRealms, RealmConfig config, XPackLicenseState licenseState) {
     public DelegatedAuthorizationSupport(Iterable<? extends Realm> allRealms, RealmConfig config, XPackLicenseState licenseState) {
-        this(allRealms, config.getSetting(AUTHZ_REALMS), config.globalSettings(), config.threadContext(),
+        this(allRealms, config.getSetting(AUTHZ_REALMS), config.settings(), config.threadContext(),
             licenseState);
             licenseState);
     }
     }
 
 

+ 2 - 2
x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapRealmTests.java

@@ -314,7 +314,7 @@ public class LdapRealmTests extends LdapTestCase {
                 .put(getFullSettingKey(identifier, SSLConfigurationSettings.VERIFICATION_MODE_SETTING_REALM), VerificationMode.CERTIFICATE)
                 .put(getFullSettingKey(identifier, SSLConfigurationSettings.VERIFICATION_MODE_SETTING_REALM), VerificationMode.CERTIFICATE)
                 .build();
                 .build();
         final RealmConfig config = getRealmConfig(identifier, settings);
         final RealmConfig config = getRealmConfig(identifier, settings);
-        SessionFactory sessionFactory = LdapRealm.sessionFactory(config, new SSLService(config.globalSettings(), config.env()), threadPool);
+        SessionFactory sessionFactory = LdapRealm.sessionFactory(config, new SSLService(config.settings(), config.env()), threadPool);
         try {
         try {
             assertThat(sessionFactory, is(instanceOf(LdapUserSearchSessionFactory.class)));
             assertThat(sessionFactory, is(instanceOf(LdapUserSearchSessionFactory.class)));
         } finally {
         } finally {
@@ -435,7 +435,7 @@ public class LdapRealmTests extends LdapTestCase {
 
 
         RealmConfig config = getRealmConfig(identifier, settings.build());
         RealmConfig config = getRealmConfig(identifier, settings.build());
 
 
-        LdapSessionFactory ldapFactory = new LdapSessionFactory(config, new SSLService(config.globalSettings(), config.env()), threadPool);
+        LdapSessionFactory ldapFactory = new LdapSessionFactory(config, new SSLService(config.settings(), config.env()), threadPool);
         LdapRealm realm = new LdapRealm(config, ldapFactory, new DnRoleMapper(config, resourceWatcherService), threadPool);
         LdapRealm realm = new LdapRealm(config, ldapFactory, new DnRoleMapper(config, resourceWatcherService), threadPool);
         realm.initialize(Collections.singleton(realm), licenseState);
         realm.initialize(Collections.singleton(realm), licenseState);
 
 

+ 1 - 1
x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/support/SessionFactoryLoadBalancingTests.java

@@ -240,7 +240,7 @@ public class SessionFactoryLoadBalancingTests extends LdapTestCase {
         Settings globalSettings = Settings.builder().put("path.home", createTempDir()).put(settings).build();
         Settings globalSettings = Settings.builder().put("path.home", createTempDir()).put(settings).build();
         RealmConfig config = new RealmConfig(REALM_IDENTIFIER, globalSettings,
         RealmConfig config = new RealmConfig(REALM_IDENTIFIER, globalSettings,
                 TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
                 TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
-        return new TestSessionFactory(config, new SSLService(Settings.EMPTY, TestEnvironment.newEnvironment(config.globalSettings())),
+        return new TestSessionFactory(config, new SSLService(Settings.EMPTY, TestEnvironment.newEnvironment(config.settings())),
                 threadPool);
                 threadPool);
     }
     }
 
 

+ 2 - 2
x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlRealmTests.java

@@ -140,7 +140,7 @@ public class SamlRealmTests extends SamlTestCase {
             assertEquals(0, proxyServer.requests().size());
             assertEquals(0, proxyServer.requests().size());
 
 
             Tuple<RealmConfig, SSLService> config = buildConfig("https://localhost:" + proxyServer.getPort());
             Tuple<RealmConfig, SSLService> config = buildConfig("https://localhost:" + proxyServer.getPort());
-            logger.info("Settings\n{}", config.v1().globalSettings().toDelimitedString('\n'));
+            logger.info("Settings\n{}", config.v1().settings().toDelimitedString('\n'));
             final ResourceWatcherService watcherService = mock(ResourceWatcherService.class);
             final ResourceWatcherService watcherService = mock(ResourceWatcherService.class);
             Tuple<AbstractReloadingMetadataResolver, Supplier<EntityDescriptor>> tuple
             Tuple<AbstractReloadingMetadataResolver, Supplier<EntityDescriptor>> tuple
                     = SamlRealm.initializeResolver(logger, config.v1(), config.v2(), watcherService);
                     = SamlRealm.initializeResolver(logger, config.v1(), config.v2(), watcherService);
@@ -284,7 +284,7 @@ public class SamlRealmTests extends SamlTestCase {
         try {
         try {
             return new SamlRealm(config, roleMapper, authenticator, logoutHandler, () -> idp, sp);
             return new SamlRealm(config, roleMapper, authenticator, logoutHandler, () -> idp, sp);
         } catch (SettingsException e) {
         } catch (SettingsException e) {
-            logger.info(new ParameterizedMessage("Settings are invalid:\n{}", config.globalSettings().toDelimitedString('\n')), e);
+            logger.info(new ParameterizedMessage("Settings are invalid:\n{}", config.settings().toDelimitedString('\n')), e);
             throw e;
             throw e;
         }
         }
     }
     }