Skip to content

Commit 00ad3ce

Browse files
committed
Merge remote-tracking branch 'origin/main' into esql_geogrid_types
2 parents 355c18d + c76bd8e commit 00ad3ce

File tree

3 files changed

+70
-43
lines changed

3 files changed

+70
-43
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySettingsSource.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,14 @@ public SecuritySettingsSource(boolean sslEnabled, Path parentFolder, Scope scope
136136
}
137137
}
138138

139-
Path homePath(final int nodeOrdinal) {
139+
protected Path homePath(final int nodeOrdinal) {
140140
return parentFolder.resolve(subfolderPrefix + "-" + nodeOrdinal);
141141
}
142142

143143
@Override
144144
public Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
145145
final Path home = homePath(nodeOrdinal);
146-
final Path xpackConf = home.resolve("config");
147-
try {
148-
Files.createDirectories(xpackConf);
149-
} catch (IOException e) {
150-
throw new UncheckedIOException(e);
151-
}
152-
writeFile(xpackConf, "roles.yml", configRoles());
153-
writeFile(xpackConf, "users", configUsers());
154-
writeFile(xpackConf, "users_roles", configUsersRoles());
155-
writeFile(xpackConf, "operator_users.yml", configOperatorUsers());
156-
writeFile(xpackConf, "service_tokens", configServiceTokens());
146+
writeConfigFiles(home);
157147

158148
Settings.Builder builder = Settings.builder()
159149
.put(Environment.PATH_HOME_SETTING.getKey(), home)
@@ -176,6 +166,20 @@ public Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
176166
return builder.build();
177167
}
178168

169+
protected void writeConfigFiles(Path home) {
170+
final Path xpackConf = home.resolve("config");
171+
try {
172+
Files.createDirectories(xpackConf);
173+
} catch (IOException e) {
174+
throw new UncheckedIOException(e);
175+
}
176+
writeFile(xpackConf, "roles.yml", configRoles());
177+
writeFile(xpackConf, "users", configUsers());
178+
writeFile(xpackConf, "users_roles", configUsersRoles());
179+
writeFile(xpackConf, "operator_users.yml", configOperatorUsers());
180+
writeFile(xpackConf, "service_tokens", configServiceTokens());
181+
}
182+
179183
@Override
180184
public Path nodeConfigPath(int nodeOrdinal) {
181185
return homePath(nodeOrdinal).resolve("config");
@@ -244,7 +248,7 @@ public static void addSSLSettingsForNodePEMFiles(Settings.Builder builder, Strin
244248
);
245249
}
246250

247-
private void addNodeSSLSettings(Settings.Builder builder) {
251+
protected void addNodeSSLSettings(Settings.Builder builder) {
248252
if (sslEnabled) {
249253
builder.put("xpack.security.transport.ssl.enabled", true);
250254
if (usePEM) {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.security;
9+
10+
import org.elasticsearch.common.settings.Settings;
11+
import org.elasticsearch.license.XPackLicenseState;
12+
import org.elasticsearch.plugins.ReloadablePlugin;
13+
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
14+
import org.elasticsearch.xpack.core.security.SecurityExtension;
15+
import org.elasticsearch.xpack.core.ssl.SSLService;
16+
17+
import java.nio.file.Path;
18+
import java.util.List;
19+
20+
public abstract class AbstractLocalStateSecurity extends LocalStateCompositeXPackPlugin implements ReloadablePlugin {
21+
@SuppressWarnings("this-escape")
22+
public AbstractLocalStateSecurity(Settings settings, Path configPath) {
23+
super(settings, configPath);
24+
25+
plugins.add(new Security(settings, AbstractLocalStateSecurity.this.securityExtensions()) {
26+
@Override
27+
protected SSLService getSslService() {
28+
return AbstractLocalStateSecurity.this.getSslService();
29+
}
30+
31+
@Override
32+
protected XPackLicenseState getLicenseState() {
33+
return AbstractLocalStateSecurity.this.getLicenseState();
34+
}
35+
});
36+
}
37+
38+
@Override
39+
public void reload(Settings settings) throws Exception {
40+
plugins.stream().filter(p -> p instanceof ReloadablePlugin).forEach(p -> {
41+
try {
42+
((ReloadablePlugin) p).reload(settings);
43+
} catch (Exception e) {
44+
throw new RuntimeException(e);
45+
}
46+
});
47+
}
48+
49+
protected List<SecurityExtension> securityExtensions() {
50+
return List.of();
51+
}
52+
}

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/LocalStateSecurity.java

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@
1616
import org.elasticsearch.license.LicenseService;
1717
import org.elasticsearch.license.XPackLicenseState;
1818
import org.elasticsearch.plugins.Plugin;
19-
import org.elasticsearch.plugins.ReloadablePlugin;
2019
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
2120
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
2221
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
2322
import org.elasticsearch.threadpool.ThreadPool;
2423
import org.elasticsearch.transport.TransportService;
25-
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
2624
import org.elasticsearch.xpack.core.action.TransportXPackInfoAction;
2725
import org.elasticsearch.xpack.core.action.TransportXPackUsageAction;
2826
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
2927
import org.elasticsearch.xpack.core.action.XPackInfoFeatureResponse;
3028
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
3129
import org.elasticsearch.xpack.core.action.XPackUsageFeatureResponse;
3230
import org.elasticsearch.xpack.core.action.XPackUsageResponse;
33-
import org.elasticsearch.xpack.core.security.SecurityExtension;
3431
import org.elasticsearch.xpack.core.ssl.SSLService;
3532
import org.elasticsearch.xpack.ilm.IndexLifecycle;
3633
import org.elasticsearch.xpack.monitoring.Monitoring;
@@ -39,7 +36,7 @@
3936
import java.util.Collections;
4037
import java.util.List;
4138

42-
public class LocalStateSecurity extends LocalStateCompositeXPackPlugin implements ReloadablePlugin {
39+
public class LocalStateSecurity extends AbstractLocalStateSecurity {
4340

4441
public static class SecurityTransportXPackUsageAction extends TransportXPackUsageAction {
4542
@Inject
@@ -102,21 +99,6 @@ protected XPackLicenseState getLicenseState() {
10299
return thisVar.getLicenseState();
103100
}
104101
});
105-
plugins.add(new Security(settings, thisVar.securityExtensions()) {
106-
@Override
107-
protected SSLService getSslService() {
108-
return thisVar.getSslService();
109-
}
110-
111-
@Override
112-
protected XPackLicenseState getLicenseState() {
113-
return thisVar.getLicenseState();
114-
}
115-
});
116-
}
117-
118-
protected List<SecurityExtension> securityExtensions() {
119-
return List.of();
120102
}
121103

122104
@Override
@@ -132,15 +114,4 @@ protected Class<? extends TransportAction<XPackInfoRequest, XPackInfoResponse>>
132114
public List<Plugin> plugins() {
133115
return plugins;
134116
}
135-
136-
@Override
137-
public void reload(Settings settings) throws Exception {
138-
plugins.stream().filter(p -> p instanceof ReloadablePlugin).forEach(p -> {
139-
try {
140-
((ReloadablePlugin) p).reload(settings);
141-
} catch (Exception e) {
142-
throw new RuntimeException(e);
143-
}
144-
});
145-
}
146117
}

0 commit comments

Comments
 (0)