Skip to content

Commit b4173c8

Browse files
authored
Remove deprecated RealmConfig constructor (#35327)
This removes an obsolete constructor that was still being called from some tests. Relates: #30241
1 parent 2395e16 commit b4173c8

File tree

11 files changed

+49
-68
lines changed

11 files changed

+49
-68
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ public class RealmConfig {
2323
private final Settings globalSettings;
2424
private final ThreadContext threadContext;
2525

26-
@Deprecated
27-
public RealmConfig(RealmIdentifier identifier, Settings settings, Settings globalSettings, Environment env,
28-
ThreadContext threadContext) {
29-
this(identifier, globalSettings, env, threadContext);
30-
}
31-
3226
public RealmConfig(RealmIdentifier identifier, Settings globalSettings, Environment env,
3327
ThreadContext threadContext) {
3428
this.identifier = identifier;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.common.settings.Settings;
99
import org.elasticsearch.common.util.concurrent.ThreadContext;
10+
import org.elasticsearch.env.Environment;
1011
import org.elasticsearch.env.TestEnvironment;
1112
import org.elasticsearch.test.ESTestCase;
1213
import org.elasticsearch.threadpool.ThreadPool;
@@ -46,12 +47,13 @@ public void testNativeRealmRegistersIndexHealthChangeListener() throws Exception
4647
verifyZeroInteractions(securityIndex);
4748

4849
Settings settings = Settings.builder().put("path.home", createTempDir()).build();
49-
factories.get(NativeRealmSettings.TYPE).create(new RealmConfig(new RealmConfig.RealmIdentifier(NativeRealmSettings.TYPE, "test"),
50-
Settings.EMPTY, settings, TestEnvironment.newEnvironment(settings), new ThreadContext(settings)));
50+
final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier(NativeRealmSettings.TYPE, "test");
51+
final Environment env = TestEnvironment.newEnvironment(settings);
52+
final ThreadContext threadContext = new ThreadContext(settings);
53+
factories.get(NativeRealmSettings.TYPE).create(new RealmConfig(realmId, settings, env, threadContext));
5154
verify(securityIndex).addIndexStateListener(isA(BiConsumer.class));
5255

53-
factories.get(NativeRealmSettings.TYPE).create(new RealmConfig(new RealmConfig.RealmIdentifier(NativeRealmSettings.TYPE, "test"),
54-
Settings.EMPTY, settings, TestEnvironment.newEnvironment(settings), new ThreadContext(settings)));
56+
factories.get(NativeRealmSettings.TYPE).create(new RealmConfig(realmId, settings, env, threadContext));
5557
verify(securityIndex, times(2)).addIndexStateListener(isA(BiConsumer.class));
5658
}
5759

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/esnative/NativeRealmTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void testCacheClearOnIndexHealthChange() {
3232
final AtomicInteger numInvalidation = new AtomicInteger(0);
3333
int expectedInvalidation = 0;
3434
Settings settings = Settings.builder().put("path.home", createTempDir()).build();
35-
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("native", "native"), Settings.EMPTY,
36-
settings, TestEnvironment.newEnvironment(settings), new ThreadContext(settings));
35+
RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("native", "native");
36+
RealmConfig config = new RealmConfig(realmId, settings, TestEnvironment.newEnvironment(settings), new ThreadContext(settings));
3737
final NativeRealm nativeRealm = new NativeRealm(config, mock(NativeUsersStore.class), threadPool) {
3838
@Override
3939
void clearCache() {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/file/FileUserPasswdStoreTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void testStore_AutoReload() throws Exception {
122122

123123
private RealmConfig getRealmConfig(Settings fileSettings) {
124124
final RealmConfig.RealmIdentifier identifier = new RealmConfig.RealmIdentifier("file", "file-test");
125-
return new RealmConfig(identifier, fileSettings, settings, env, threadPool.getThreadContext());
125+
return new RealmConfig(identifier, settings, env, threadPool.getThreadContext());
126126
}
127127

128128
public void testStore_AutoReload_WithParseFailures() throws Exception {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/file/FileUserRolesStoreTests.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,8 @@ public void testStore_ConfiguredWithUnreadableFile() throws Exception {
7474
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8
7575
Files.write(file, lines, StandardCharsets.UTF_16);
7676

77-
Settings fileSettings = randomBoolean() ? Settings.EMPTY : Settings.builder()
78-
.put("files.users_roles", file.toAbsolutePath())
79-
.build();
80-
81-
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("file", "file-test"), fileSettings, settings, env,
82-
new ThreadContext(Settings.EMPTY));
77+
RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("file", "file-test");
78+
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY));
8379
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
8480
FileUserRolesStore store = new FileUserRolesStore(config, watcherService);
8581
assertThat(store.entriesCount(), is(0));
@@ -90,12 +86,9 @@ public void testStoreAutoReload() throws Exception {
9086
Path tmp = getUsersRolesPath();
9187
Files.copy(users, tmp, StandardCopyOption.REPLACE_EXISTING);
9288

93-
Settings fileSettings = randomBoolean() ? Settings.EMPTY : Settings.builder()
94-
.put("files.users_roles", tmp.toAbsolutePath())
95-
.build();
9689

97-
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("file", "file-test"), fileSettings, settings, env,
98-
new ThreadContext(Settings.EMPTY));
90+
final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("file", "file-test");
91+
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY));
9992
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
10093
final CountDownLatch latch = new CountDownLatch(1);
10194

@@ -129,12 +122,8 @@ public void testStoreAutoReloadWithParseFailure() throws Exception {
129122
Path tmp = getUsersRolesPath();
130123
Files.copy(users, tmp, StandardCopyOption.REPLACE_EXISTING);
131124

132-
Settings fileSettings = randomBoolean() ? Settings.EMPTY : Settings.builder()
133-
.put("files.users_roles", tmp.toAbsolutePath())
134-
.build();
135-
136-
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("file", "file-test"), fileSettings, settings, env,
137-
new ThreadContext(Settings.EMPTY));
125+
final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("file", "file-test");
126+
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY));
138127
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
139128
final CountDownLatch latch = new CountDownLatch(1);
140129

@@ -222,13 +211,9 @@ public void testParseFileEmptyRolesDoesNotCauseNPE() throws Exception {
222211
.put("path.home", createTempDir())
223212
.build();
224213

225-
Settings fileSettings = randomBoolean() ? Settings.EMPTY : Settings.builder()
226-
.put("files.users_roles", usersRoles.toAbsolutePath())
227-
.build();
228-
229214
Environment env = TestEnvironment.newEnvironment(settings);
230-
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("file", "file-test"), fileSettings, settings, env,
231-
new ThreadContext(Settings.EMPTY));
215+
final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("file", "file-test");
216+
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY));
232217
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
233218
FileUserRolesStore store = new FileUserRolesStore(config, watcherService);
234219
assertThat(store.roles("user"), equalTo(Strings.EMPTY_ARRAY));

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/kerberos/KerberosRealmAuthenticateFailedTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void testAuthenticateDifferentFailureScenarios() throws LoginException, G
122122
public void testDelegatedAuthorizationFailedToResolve() throws Exception {
123123
final String username = randomPrincipalName();
124124
final MockLookupRealm otherRealm = new MockLookupRealm(new RealmConfig(new RealmConfig.RealmIdentifier("mock", "other_realm"),
125-
Settings.EMPTY, globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings)));
125+
globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings)));
126126
final User lookupUser = new User(randomAlphaOfLength(5));
127127
otherRealm.registerUser(lookupUser);
128128

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,27 +324,27 @@ private void sleepUntil(long until) throws InterruptedException {
324324
}
325325

326326
public void testAuthenticateContract() throws Exception {
327-
Realm realm = new FailingAuthenticationRealm(Settings.EMPTY, globalSettings, threadPool);
327+
Realm realm = new FailingAuthenticationRealm(globalSettings, threadPool);
328328
PlainActionFuture<AuthenticationResult> future = new PlainActionFuture<>();
329329
realm.authenticate(new UsernamePasswordToken("user", new SecureString("pass")), future);
330330
User user = future.actionGet().getUser();
331331
assertThat(user, nullValue());
332332

333-
realm = new ThrowingAuthenticationRealm(Settings.EMPTY, globalSettings, threadPool);
333+
realm = new ThrowingAuthenticationRealm(globalSettings, threadPool);
334334
future = new PlainActionFuture<>();
335335
realm.authenticate(new UsernamePasswordToken("user", new SecureString("pass")), future);
336336
RuntimeException e = expectThrows(RuntimeException.class, future::actionGet);
337337
assertThat(e.getMessage(), containsString("whatever exception"));
338338
}
339339

340340
public void testLookupContract() throws Exception {
341-
Realm realm = new FailingAuthenticationRealm(Settings.EMPTY, globalSettings, threadPool);
341+
Realm realm = new FailingAuthenticationRealm(globalSettings, threadPool);
342342
PlainActionFuture<User> future = new PlainActionFuture<>();
343343
realm.lookupUser("user", future);
344344
User user = future.actionGet();
345345
assertThat(user, nullValue());
346346

347-
realm = new ThrowingAuthenticationRealm(Settings.EMPTY, globalSettings, threadPool);
347+
realm = new ThrowingAuthenticationRealm(globalSettings, threadPool);
348348
future = new PlainActionFuture<>();
349349
realm.lookupUser("user", future);
350350
RuntimeException e = expectThrows(RuntimeException.class, future::actionGet);
@@ -384,7 +384,7 @@ public void testSingleAuthPerUserLimit() throws Exception {
384384
final AtomicInteger authCounter = new AtomicInteger(0);
385385
final Hasher pwdHasher = Hasher.resolve(randomFrom("pbkdf2", "pbkdf2_1000", "bcrypt", "bcrypt9"));
386386
final String passwordHash = new String(pwdHasher.hash(password));
387-
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("caching", "test_realm"), Settings.EMPTY, globalSettings,
387+
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("caching", "test_realm"), globalSettings,
388388
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
389389
final CachingUsernamePasswordRealm realm = new CachingUsernamePasswordRealm(config, threadPool) {
390390
@Override
@@ -450,7 +450,7 @@ public void testCacheConcurrency() throws Exception {
450450
final SecureString randomPassword = new SecureString(randomAlphaOfLength(password.length()).toCharArray());
451451
final Hasher localHasher = Hasher.resolve(randomFrom("pbkdf2", "pbkdf2_1000", "bcrypt", "bcrypt9"));
452452
final String passwordHash = new String(localHasher.hash(password));
453-
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("caching", "test_realm"), Settings.EMPTY, globalSettings,
453+
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("caching", "test_realm"), globalSettings,
454454
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
455455
final CachingUsernamePasswordRealm realm = new CachingUsernamePasswordRealm(config, threadPool) {
456456
@Override
@@ -518,7 +518,7 @@ public void testUserLookupConcurrency() throws Exception {
518518
final String username = "username";
519519
final AtomicInteger lookupCounter = new AtomicInteger(0);
520520

521-
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("caching", "test_realm"), Settings.EMPTY, globalSettings,
521+
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("caching", "test_realm"), globalSettings,
522522
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(Settings.EMPTY));
523523
final CachingUsernamePasswordRealm realm = new CachingUsernamePasswordRealm(config, threadPool) {
524524
@Override
@@ -605,8 +605,8 @@ public void testAuthenticateDisabled() throws Exception {
605605

606606
static class FailingAuthenticationRealm extends CachingUsernamePasswordRealm {
607607

608-
FailingAuthenticationRealm(Settings settings, Settings global, ThreadPool threadPool) {
609-
super(new RealmConfig(new RealmConfig.RealmIdentifier("caching", "failing-test"), settings, global,
608+
FailingAuthenticationRealm(Settings global, ThreadPool threadPool) {
609+
super(new RealmConfig(new RealmConfig.RealmIdentifier("caching", "failing-test"), global,
610610
TestEnvironment.newEnvironment(global),
611611
threadPool.getThreadContext()), threadPool);
612612
}
@@ -624,8 +624,8 @@ protected void doLookupUser(String username, ActionListener<User> listener) {
624624

625625
static class ThrowingAuthenticationRealm extends CachingUsernamePasswordRealm {
626626

627-
ThrowingAuthenticationRealm(Settings settings, Settings globalSettings, ThreadPool threadPool) {
628-
super(new RealmConfig(new RealmConfig.RealmIdentifier("caching", "throwing-test"), settings, globalSettings,
627+
ThrowingAuthenticationRealm(Settings globalSettings, ThreadPool threadPool) {
628+
super(new RealmConfig(new RealmConfig.RealmIdentifier("caching", "throwing-test"), globalSettings,
629629
TestEnvironment.newEnvironment(globalSettings),
630630
threadPool.getThreadContext()), threadPool);
631631
}
@@ -649,7 +649,7 @@ static class AlwaysAuthenticateCachingRealm extends CachingUsernamePasswordRealm
649649
private boolean usersEnabled = true;
650650

651651
AlwaysAuthenticateCachingRealm(Settings globalSettings, ThreadPool threadPool) {
652-
this(new RealmConfig(new RealmConfig.RealmIdentifier("caching", "always-test"), Settings.EMPTY, globalSettings,
652+
this(new RealmConfig(new RealmConfig.RealmIdentifier("caching", "always-test"), globalSettings,
653653
TestEnvironment.newEnvironment(globalSettings),
654654
threadPool.getThreadContext()), threadPool);
655655
}
@@ -682,7 +682,7 @@ static class LookupNotSupportedRealm extends CachingUsernamePasswordRealm {
682682
public final AtomicInteger lookupInvocationCounter = new AtomicInteger(0);
683683

684684
LookupNotSupportedRealm(Settings globalSettings, ThreadPool threadPool) {
685-
super(new RealmConfig(new RealmConfig.RealmIdentifier("caching", "lookup-notsupported-test"), Settings.EMPTY, globalSettings,
685+
super(new RealmConfig(new RealmConfig.RealmIdentifier("caching", "lookup-notsupported-test"), globalSettings,
686686
TestEnvironment.newEnvironment(globalSettings), threadPool.getThreadContext()), threadPool);
687687
}
688688

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/ExpressionRoleMappingTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ExpressionRoleMappingTests extends ESTestCase {
3939
@Before
4040
public void setupMapping() throws Exception {
4141
realm = new RealmConfig(new RealmConfig.RealmIdentifier("ldap", "ldap1"),
42-
Settings.EMPTY, Settings.EMPTY, Mockito.mock(Environment.class), new ThreadContext(Settings.EMPTY));
42+
Settings.EMPTY, Mockito.mock(Environment.class), new ThreadContext(Settings.EMPTY));
4343
}
4444

4545
public void testParseValidJson() throws Exception {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/NativeRoleMappingStoreTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected void loadMappings(ActionListener<List<ExpressionRoleMapping>> listener
8484
}
8585
};
8686

87-
final RealmConfig realm = new RealmConfig(new RealmConfig.RealmIdentifier("ldap", "ldap1"), Settings.EMPTY, Settings.EMPTY,
87+
final RealmConfig realm = new RealmConfig(new RealmConfig.RealmIdentifier("ldap", "ldap1"), Settings.EMPTY,
8888
mock(Environment.class), new ThreadContext(Settings.EMPTY));
8989

9090
final PlainActionFuture<Set<String>> future = new PlainActionFuture<>();
@@ -197,7 +197,7 @@ private NativeRoleMappingStore buildRoleMappingStoreForInvalidationTesting(Atomi
197197
}).when(client).execute(eq(ClearRealmCacheAction.INSTANCE), any(ClearRealmCacheRequest.class), any(ActionListener.class));
198198

199199
final Environment env = TestEnvironment.newEnvironment(settings);
200-
final RealmConfig realmConfig = new RealmConfig(new RealmConfig.RealmIdentifier("ldap", getTestName()), Settings.EMPTY,
200+
final RealmConfig realmConfig = new RealmConfig(new RealmConfig.RealmIdentifier("ldap", getTestName()),
201201
settings, env, threadContext);
202202
final CachingUsernamePasswordRealm mockRealm = new CachingUsernamePasswordRealm(realmConfig, threadPool) {
203203
@Override

x-pack/qa/third-party/active-directory/src/test/java/org/elasticsearch/xpack/security/authc/ldap/ADLdapUserSearchSessionFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void testUserSearchWithActiveDirectory() throws Exception {
9090
});
9191
Settings fullSettings = builder.build();
9292
sslService = new SSLService(fullSettings, TestEnvironment.newEnvironment(fullSettings));
93-
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("ad", "ad-as-ldap-test"), settings, globalSettings,
93+
RealmConfig config = new RealmConfig(new RealmConfig.RealmIdentifier("ad", "ad-as-ldap-test"), globalSettings,
9494
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
9595
LdapUserSearchSessionFactory sessionFactory = getLdapUserSearchSessionFactory(config, sslService, threadPool);
9696

0 commit comments

Comments
 (0)