Skip to content

Commit 7d05257

Browse files
authored
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".
1 parent 566979c commit 7d05257

File tree

10 files changed

+39
-36
lines changed

10 files changed

+39
-36
lines changed

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ public class RealmConfig {
2020
final boolean enabled;
2121
final int order;
2222
private final Environment env;
23-
private final Settings globalSettings;
23+
private final Settings settings;
2424
private final ThreadContext threadContext;
2525

26-
public RealmConfig(RealmIdentifier identifier, Settings globalSettings, Environment env,
27-
ThreadContext threadContext) {
26+
public RealmConfig(RealmIdentifier identifier, Settings settings, Environment env, ThreadContext threadContext) {
2827
this.identifier = identifier;
29-
this.globalSettings = globalSettings;
28+
this.settings = settings;
3029
this.env = env;
31-
enabled = getSetting(RealmSettings.ENABLED_SETTING);
32-
order = getSetting(RealmSettings.ORDER_SETTING);
30+
this.enabled = getSetting(RealmSettings.ENABLED_SETTING);
31+
this.order = getSetting(RealmSettings.ORDER_SETTING);
3332
this.threadContext = threadContext;
3433
}
3534

@@ -53,8 +52,13 @@ public String type() {
5352
return identifier.type;
5453
}
5554

56-
public Settings globalSettings() {
57-
return globalSettings;
55+
/**
56+
* @return The settings for the current node.
57+
* This will include the settings for this realm (as well as other realms, and other non-security settings).
58+
* @see #getConcreteSetting(Setting.AffixSetting)
59+
*/
60+
public Settings settings() {
61+
return settings;
5862
}
5963

6064
public Environment env() {
@@ -95,16 +99,16 @@ public <T> Setting<T> getConcreteSetting(Function<String, Setting.AffixSetting<T
9599
}
96100

97101
/**
98-
* Obtain the value of the provided {@code setting} from the node's {@link #globalSettings global settings}.
102+
* Obtain the value of the provided {@code setting} from the node's {@link #settings global settings}.
99103
* The {@link Setting.AffixSetting} is made <em>concrete</em> through {@link #getConcreteSetting(Setting.AffixSetting)}, which is then
100104
* used to {@link Setting#get(Settings) retrieve} the setting value.
101105
*/
102106
public <T> T getSetting(Setting.AffixSetting<T> setting) {
103-
return getConcreteSetting(setting).get(globalSettings);
107+
return getConcreteSetting(setting).get(settings);
104108
}
105109

106110
/**
107-
* Obtain the value of the provided {@code setting} from the node's {@link #globalSettings global settings}.
111+
* Obtain the value of the provided {@code setting} from the node's {@link #settings global settings}.
108112
* {@link #getConcreteSetting(Function)} is used to obtain a <em>concrete setting</em> from the provided
109113
* {@link Function}/{@link Setting.AffixSetting}, and this <em>concrete setting</em> is then used to
110114
* {@link Setting#get(Settings) retrieve} the setting value.
@@ -114,7 +118,7 @@ public <T> T getSetting(Function<String, Setting.AffixSetting<T>> settingFactory
114118
}
115119

116120
/**
117-
* Obtain the value of the provided {@code setting} from the node's {@link #globalSettings global settings}.
121+
* Obtain the value of the provided {@code setting} from the node's {@link #settings global settings}.
118122
* {@link #getConcreteSetting(Function)} is used to obtain a <em>concrete setting</em> from the provided
119123
* {@link Function}/{@link Setting.AffixSetting}.
120124
* If this <em>concrete setting</em> {@link Setting#exists(Settings) exists} in the global settings, then its value is returned,
@@ -125,38 +129,38 @@ public <T> T getSetting(Function<String, Setting.AffixSetting<T>> settingFactory
125129
}
126130

127131
/**
128-
* Obtain the value of the provided {@code setting} from the node's {@link #globalSettings global settings}.
132+
* Obtain the value of the provided {@code setting} from the node's {@link #settings global settings}.
129133
* {@link #getConcreteSetting(Setting.AffixSetting)} is used to obtain a <em>concrete setting</em> from the provided
130134
* {@link Setting.AffixSetting}.
131135
* If this <em>concrete setting</em> {@link Setting#exists(Settings) exists} in the global settings, then its value is returned,
132136
* otherwise the {@code onElse} {@link Supplier} is executed and returned.
133137
*/
134138
public <T> T getSetting(Setting.AffixSetting<T> setting, Supplier<T> orElse) {
135139
final Setting<T> concrete = setting.getConcreteSettingForNamespace(name());
136-
if (concrete.exists(globalSettings)) {
137-
return concrete.get(globalSettings);
140+
if (concrete.exists(settings)) {
141+
return concrete.get(settings);
138142
} else {
139143
return orElse.get();
140144
}
141145
}
142146

143147
/**
144-
* Determines whether the provided {@code setting} has an explicit value in the node's {@link #globalSettings global settings}.
148+
* Determines whether the provided {@code setting} has an explicit value in the node's {@link #settings global settings}.
145149
* {@link #getConcreteSetting(Function)} is used to obtain a <em>concrete setting</em> from the provided
146150
* {@link Function}/{@link Setting.AffixSetting}, and this <em>concrete setting</em> is then used to
147151
* {@link Setting#exists(Settings) check} for a value.
148152
*/
149153
public <T> boolean hasSetting(Function<String, Setting.AffixSetting<T>> settingFactory) {
150-
return getConcreteSetting(settingFactory).exists(globalSettings);
154+
return getConcreteSetting(settingFactory).exists(settings);
151155
}
152156

153157
/**
154-
* Determines whether the provided {@code setting} has an explicit value in the node's {@link #globalSettings global settings}.
158+
* Determines whether the provided {@code setting} has an explicit value in the node's {@link #settings global settings}.
155159
* {@link #getConcreteSetting(Setting.AffixSetting)} is used to obtain a <em>concrete setting</em> from the provided
156160
* {@link Setting.AffixSetting}, and this <em>concrete setting</em> is then used to {@link Setting#exists(Settings) check} for a value.
157161
*/
158162
public <T> boolean hasSetting(Setting.AffixSetting<T> setting) {
159-
return getConcreteSetting(setting).exists(globalSettings);
163+
return getConcreteSetting(setting).exists(settings);
160164
}
161165

162166
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public ReservedRealm(Environment env, Settings settings, NativeUsersStore native
8787
protected void doAuthenticate(UsernamePasswordToken token, ActionListener<AuthenticationResult> listener) {
8888
if (realmEnabled == false) {
8989
listener.onResponse(AuthenticationResult.notHandled());
90-
} else if (ClientReservedRealm.isReserved(token.principal(), config.globalSettings()) == false) {
90+
} else if (ClientReservedRealm.isReserved(token.principal(), config.settings()) == false) {
9191
listener.onResponse(AuthenticationResult.notHandled());
9292
} else {
9393
getUserInfo(token.principal(), ActionListener.wrap((userInfo) -> {
@@ -120,13 +120,13 @@ protected void doAuthenticate(UsernamePasswordToken token, ActionListener<Authen
120120
@Override
121121
protected void doLookupUser(String username, ActionListener<User> listener) {
122122
if (realmEnabled == false) {
123-
if (anonymousEnabled && AnonymousUser.isAnonymousUsername(username, config.globalSettings())) {
123+
if (anonymousEnabled && AnonymousUser.isAnonymousUsername(username, config.settings())) {
124124
listener.onResponse(anonymousUser);
125125
}
126126
listener.onResponse(null);
127-
} else if (ClientReservedRealm.isReserved(username, config.globalSettings()) == false) {
127+
} else if (ClientReservedRealm.isReserved(username, config.settings()) == false) {
128128
listener.onResponse(null);
129-
} else if (AnonymousUser.isAnonymousUsername(username, config.globalSettings())) {
129+
} else if (AnonymousUser.isAnonymousUsername(username, config.settings())) {
130130
listener.onResponse(anonymousEnabled ? anonymousUser : null);
131131
} else {
132132
getUserInfo(username, ActionListener.wrap((userInfo) -> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public FileUserPasswdStore(RealmConfig config, ResourceWatcherService watcherSer
5656

5757
FileUserPasswdStore(RealmConfig config, ResourceWatcherService watcherService, Runnable listener) {
5858
file = resolveFile(config.env());
59-
settings = config.globalSettings();
59+
settings = config.settings();
6060
users = parseFileLenient(file, logger, settings);
6161
listeners = new CopyOnWriteArrayList<>(Collections.singletonList(listener));
6262
FileWatcher watcher = new FileWatcher(file.getParent());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private static X509TrustManager trustManagersFromTruststore(String truststorePat
249249
try (SecureString password = realmConfig.getSetting(PkiRealmSettings.TRUST_STORE_PASSWORD)) {
250250
String trustStoreAlgorithm = realmConfig.getSetting(PkiRealmSettings.TRUST_STORE_ALGORITHM);
251251
String trustStoreType = SSLConfigurationSettings.getKeyStoreType(
252-
realmConfig.getConcreteSetting(PkiRealmSettings.TRUST_STORE_TYPE), realmConfig.globalSettings(),
252+
realmConfig.getConcreteSetting(PkiRealmSettings.TRUST_STORE_TYPE), realmConfig.settings(),
253253
truststorePath);
254254
try {
255255
return CertParsingUtils.trustManager(truststorePath, trustStoreType, password.getChars(), trustStoreAlgorithm, realmConfig

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.logging.log4j.Level;
3333
import org.apache.logging.log4j.LogManager;
3434
import org.apache.logging.log4j.Logger;
35-
import org.apache.logging.log4j.LogManager;
3635
import org.elasticsearch.cli.EnvironmentAwareCommand;
3736
import org.elasticsearch.cli.ExitCodes;
3837
import org.elasticsearch.cli.SuppressForbidden;
@@ -158,7 +157,7 @@ EntityDescriptor buildEntityDescriptor(Terminal terminal, OptionSet options, Env
158157
final boolean batch = options.has(batchSpec);
159158

160159
final RealmConfig realm = findRealm(terminal, options, env);
161-
final Settings realmSettings = realm.globalSettings().getByPrefix(RealmSettings.realmSettingPrefix(realm.identifier()));
160+
final Settings realmSettings = realm.settings().getByPrefix(RealmSettings.realmSettingPrefix(realm.identifier()));
162161
terminal.println(Terminal.Verbosity.VERBOSE,
163162
"Using realm configuration\n=====\n" + realmSettings.toDelimitedString('\n') + "=====");
164163
final Locale locale = findLocale(options);
@@ -399,7 +398,7 @@ private Map<String, String> getAttributeNames(OptionSet options, RealmConfig rea
399398
attributes.put(a, null);
400399
}
401400
final String prefix = RealmSettings.realmSettingPrefix(realm.identifier()) + SamlRealmSettings.AttributeSetting.ATTRIBUTES_PREFIX;
402-
final Settings attributeSettings = realm.globalSettings().getByPrefix(prefix);
401+
final Settings attributeSettings = realm.settings().getByPrefix(prefix);
403402
for (String key : sorted(attributeSettings.keySet())) {
404403
final String attr = attributeSettings.get(key);
405404
attributes.put(attr, key);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public static SamlRealm create(RealmConfig config, SSLService sslService, Resour
179179
UserRoleMapper roleMapper) throws Exception {
180180
SamlUtils.initialize(logger);
181181

182-
if (TokenService.isTokenServiceEnabled(config.globalSettings()) == false) {
182+
if (TokenService.isTokenServiceEnabled(config.settings()) == false) {
183183
throw new IllegalStateException("SAML requires that the token service be enabled ("
184184
+ XPackSettings.TOKEN_SERVICE_ENABLED_SETTING.getKey() + ")");
185185
}
@@ -317,7 +317,7 @@ static SigningConfiguration buildSigningConfiguration(RealmConfig config) throws
317317
private static List<X509Credential> buildCredential(RealmConfig config, String prefix, Setting.AffixSetting<String> aliasSetting,
318318
boolean allowMultiple) {
319319
final X509KeyPairSettings keyPairSettings = X509KeyPairSettings.withPrefix(prefix, false);
320-
final X509KeyManager keyManager = CertParsingUtils.getKeyManager(keyPairSettings, config.globalSettings(), null, config.env());
320+
final X509KeyManager keyManager = CertParsingUtils.getKeyManager(keyPairSettings, config.settings(), null, config.env());
321321
if (keyManager == null) {
322322
return null;
323323
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class DelegatedAuthorizationSupport {
4646
* {@link #DelegatedAuthorizationSupport(Iterable, List, Settings, ThreadContext, XPackLicenseState)}
4747
*/
4848
public DelegatedAuthorizationSupport(Iterable<? extends Realm> allRealms, RealmConfig config, XPackLicenseState licenseState) {
49-
this(allRealms, config.getSetting(AUTHZ_REALMS), config.globalSettings(), config.threadContext(),
49+
this(allRealms, config.getSetting(AUTHZ_REALMS), config.settings(), config.threadContext(),
5050
licenseState);
5151
}
5252

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public void testLdapRealmSelectsLdapUserSearchSessionFactory() throws Exception
314314
.put(getFullSettingKey(identifier, SSLConfigurationSettings.VERIFICATION_MODE_SETTING_REALM), VerificationMode.CERTIFICATE)
315315
.build();
316316
final RealmConfig config = getRealmConfig(identifier, settings);
317-
SessionFactory sessionFactory = LdapRealm.sessionFactory(config, new SSLService(config.globalSettings(), config.env()), threadPool);
317+
SessionFactory sessionFactory = LdapRealm.sessionFactory(config, new SSLService(config.settings(), config.env()), threadPool);
318318
try {
319319
assertThat(sessionFactory, is(instanceOf(LdapUserSearchSessionFactory.class)));
320320
} finally {
@@ -435,7 +435,7 @@ public void testUsageStats() throws Exception {
435435

436436
RealmConfig config = getRealmConfig(identifier, settings.build());
437437

438-
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, new SSLService(config.globalSettings(), config.env()), threadPool);
438+
LdapSessionFactory ldapFactory = new LdapSessionFactory(config, new SSLService(config.settings(), config.env()), threadPool);
439439
LdapRealm realm = new LdapRealm(config, ldapFactory, new DnRoleMapper(config, resourceWatcherService), threadPool);
440440
realm.initialize(Collections.singleton(realm), licenseState);
441441

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private TestSessionFactory createSessionFactory(LdapLoadBalancing loadBalancing)
240240
Settings globalSettings = Settings.builder().put("path.home", createTempDir()).put(settings).build();
241241
RealmConfig config = new RealmConfig(REALM_IDENTIFIER, globalSettings,
242242
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
243-
return new TestSessionFactory(config, new SSLService(Settings.EMPTY, TestEnvironment.newEnvironment(config.globalSettings())),
243+
return new TestSessionFactory(config, new SSLService(Settings.EMPTY, TestEnvironment.newEnvironment(config.settings())),
244244
threadPool);
245245
}
246246

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void testReadIdpMetadataFromHttps() throws Exception {
140140
assertEquals(0, proxyServer.requests().size());
141141

142142
Tuple<RealmConfig, SSLService> config = buildConfig("https://localhost:" + proxyServer.getPort());
143-
logger.info("Settings\n{}", config.v1().globalSettings().toDelimitedString('\n'));
143+
logger.info("Settings\n{}", config.v1().settings().toDelimitedString('\n'));
144144
final ResourceWatcherService watcherService = mock(ResourceWatcherService.class);
145145
Tuple<AbstractReloadingMetadataResolver, Supplier<EntityDescriptor>> tuple
146146
= SamlRealm.initializeResolver(logger, config.v1(), config.v2(), watcherService);
@@ -284,7 +284,7 @@ public SamlRealm buildRealm(RealmConfig config, UserRoleMapper roleMapper, SamlA
284284
try {
285285
return new SamlRealm(config, roleMapper, authenticator, logoutHandler, () -> idp, sp);
286286
} catch (SettingsException e) {
287-
logger.info(new ParameterizedMessage("Settings are invalid:\n{}", config.globalSettings().toDelimitedString('\n')), e);
287+
logger.info(new ParameterizedMessage("Settings are invalid:\n{}", config.settings().toDelimitedString('\n')), e);
288288
throw e;
289289
}
290290
}

0 commit comments

Comments
 (0)