Skip to content

Commit 3eb7f12

Browse files
authored
Drop cluster scope method from RoleMappingMetadata (#124174)
This removes `getFromClusterState` from `RoleMappingMetadata` and replaces its use in the 2 test classes that were still using it
1 parent 2d1ab2e commit 3eb7f12

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/RoleMappingMetadata.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ public final class RoleMappingMetadata extends AbstractNamedDiffable<Metadata.Pr
6060

6161
private static final RoleMappingMetadata EMPTY = new RoleMappingMetadata(Set.of());
6262

63-
public static RoleMappingMetadata getFromClusterState(ClusterState clusterState) {
64-
final ProjectMetadata project = clusterState.metadata().getProject();
65-
return getFromProject(project);
66-
}
67-
6863
public static RoleMappingMetadata getFromProject(ProjectMetadata project) {
6964
return project.custom(RoleMappingMetadata.TYPE, RoleMappingMetadata.EMPTY);
7065
}

x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/FileSettingsRoleMappingsRestartIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.apache.lucene.tests.util.LuceneTestCase;
1111
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
1212
import org.elasticsearch.cluster.ClusterState;
13+
import org.elasticsearch.cluster.metadata.ProjectId;
1314
import org.elasticsearch.core.Tuple;
1415
import org.elasticsearch.integration.RoleMappingFileSettingsIT;
1516
import org.elasticsearch.reservedstate.service.FileSettingsService;
@@ -272,9 +273,10 @@ private void assertRoleMappingsInClusterStateWithAwait(
272273
}
273274

274275
private void assertRoleMappingsInClusterState(ClusterState clusterState, ExpressionRoleMapping... expectedRoleMappings) {
276+
final var project = clusterState.metadata().getProject(ProjectId.DEFAULT);
275277
String[] expectedRoleMappingNames = Arrays.stream(expectedRoleMappings).map(ExpressionRoleMapping::getName).toArray(String[]::new);
276278
assertRoleMappingReservedMetadata(clusterState, expectedRoleMappingNames);
277-
var actualRoleMappings = new ArrayList<>(RoleMappingMetadata.getFromClusterState(clusterState).getRoleMappings());
279+
var actualRoleMappings = new ArrayList<>(RoleMappingMetadata.getFromProject(project).getRoleMappings());
278280
assertThat(actualRoleMappings, containsInAnyOrder(expectedRoleMappings));
279281
}
280282

x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/authc/jwt/JwtRoleMappingsIntegTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.cluster.ClusterState;
1616
import org.elasticsearch.cluster.ClusterStateListener;
1717
import org.elasticsearch.cluster.ClusterStateUpdateTask;
18+
import org.elasticsearch.cluster.metadata.ProjectId;
1819
import org.elasticsearch.cluster.service.ClusterService;
1920
import org.elasticsearch.common.bytes.BytesArray;
2021
import org.elasticsearch.common.settings.Settings;
@@ -444,6 +445,7 @@ private SignedJWT getSignedJWT(JWTClaimsSet claimsSet) throws Exception {
444445
}
445446

446447
private void publishRoleMappings(Set<ExpressionRoleMapping> roleMappings) throws InterruptedException {
448+
final ProjectId projectId = ProjectId.DEFAULT;
447449
RoleMappingMetadata roleMappingMetadata = new RoleMappingMetadata(roleMappings);
448450
List<ClusterService> clusterServices = new ArrayList<>();
449451
internalCluster().getInstances(ClusterService.class).forEach(clusterServices::add);
@@ -452,7 +454,8 @@ private void publishRoleMappings(Set<ExpressionRoleMapping> roleMappings) throws
452454
clusterService.addListener(new ClusterStateListener() {
453455
@Override
454456
public void clusterChanged(ClusterChangedEvent event) {
455-
RoleMappingMetadata publishedRoleMappingMetadata = RoleMappingMetadata.getFromClusterState(event.state());
457+
final var project = event.state().metadata().getProject(projectId);
458+
RoleMappingMetadata publishedRoleMappingMetadata = RoleMappingMetadata.getFromProject(project);
456459
if (roleMappingMetadata.equals(publishedRoleMappingMetadata)) {
457460
clusterService.removeListener(this);
458461
publishedClusterState.countDown();
@@ -464,7 +467,9 @@ public void clusterChanged(ClusterChangedEvent event) {
464467
masterClusterService.submitUnbatchedStateUpdateTask("test-add-role-mapping", new ClusterStateUpdateTask() {
465468
@Override
466469
public ClusterState execute(ClusterState currentState) {
467-
return roleMappingMetadata.updateClusterState(currentState);
470+
return ClusterState.builder(currentState)
471+
.putProjectMetadata(roleMappingMetadata.updateProject(currentState.getMetadata().getProject(projectId)))
472+
.build();
468473
}
469474

470475
@Override

0 commit comments

Comments
 (0)