|
8 | 8 | package org.elasticsearch.xpack.core.security.authc;
|
9 | 9 |
|
10 | 10 | import org.elasticsearch.TransportVersion;
|
11 |
| -import org.elasticsearch.TransportVersions; |
12 | 11 | import org.elasticsearch.common.Strings;
|
13 | 12 | import org.elasticsearch.common.bytes.BytesArray;
|
14 | 13 | import org.elasticsearch.common.bytes.BytesReference;
|
15 | 14 | import org.elasticsearch.common.settings.Settings;
|
16 | 15 | import org.elasticsearch.common.util.ArrayUtils;
|
17 | 16 | import org.elasticsearch.test.ESTestCase;
|
18 |
| -import org.elasticsearch.test.TransportVersionUtils; |
19 | 17 | import org.elasticsearch.xpack.core.security.action.apikey.ApiKey;
|
20 | 18 | import org.elasticsearch.xpack.core.security.authc.service.ServiceAccountSettings;
|
21 | 19 | import org.elasticsearch.xpack.core.security.authz.RoleDescriptorsIntersection;
|
22 | 20 | import org.elasticsearch.xpack.core.security.authz.store.RoleKey;
|
23 | 21 | import org.elasticsearch.xpack.core.security.authz.store.RoleReference;
|
24 | 22 | import org.elasticsearch.xpack.core.security.authz.store.RoleReference.ApiKeyRoleReference;
|
25 |
| -import org.elasticsearch.xpack.core.security.authz.store.RoleReference.BwcApiKeyRoleReference; |
26 | 23 | import org.elasticsearch.xpack.core.security.authz.store.RoleReference.FixedRoleReference;
|
27 | 24 | import org.elasticsearch.xpack.core.security.authz.store.RoleReference.NamedRoleReference;
|
28 | 25 | import org.elasticsearch.xpack.core.security.authz.store.RoleReference.ServiceAccountRoleReference;
|
|
32 | 29 | import org.elasticsearch.xpack.core.security.user.User;
|
33 | 30 |
|
34 | 31 | import java.util.Arrays;
|
35 |
| -import java.util.Collections; |
36 | 32 | import java.util.HashMap;
|
37 | 33 | import java.util.List;
|
38 | 34 | import java.util.Map;
|
@@ -287,50 +283,6 @@ private static void expectFixedReferenceAtIndex(int index, List<RoleReference> r
|
287 | 283 | assertThat(fixedRoleReference.id(), equalTo(expectedKey));
|
288 | 284 | }
|
289 | 285 |
|
290 |
| - public void testGetRoleReferencesForApiKeyBwc() { |
291 |
| - Map<String, Object> authMetadata = new HashMap<>(); |
292 |
| - final String apiKeyId = randomAlphaOfLength(12); |
293 |
| - authMetadata.put(AuthenticationField.API_KEY_ID_KEY, apiKeyId); |
294 |
| - authMetadata.put(AuthenticationField.API_KEY_NAME_KEY, randomBoolean() ? null : randomAlphaOfLength(12)); |
295 |
| - boolean emptyApiKeyRoleDescriptor = randomBoolean(); |
296 |
| - Map<String, Object> roleARDMap = Map.of("cluster", List.of("monitor")); |
297 |
| - authMetadata.put( |
298 |
| - API_KEY_ROLE_DESCRIPTORS_KEY, |
299 |
| - (emptyApiKeyRoleDescriptor) |
300 |
| - ? randomFrom(Arrays.asList(null, Collections.emptyMap())) |
301 |
| - : Collections.singletonMap("a role", roleARDMap) |
302 |
| - ); |
303 |
| - |
304 |
| - Map<String, Object> limitedRdMap = Map.of("cluster", List.of("all")); |
305 |
| - authMetadata.put(API_KEY_LIMITED_ROLE_DESCRIPTORS_KEY, Collections.singletonMap("limited role", limitedRdMap)); |
306 |
| - |
307 |
| - final Subject subject = new Subject( |
308 |
| - new User("joe"), |
309 |
| - new Authentication.RealmRef(API_KEY_REALM_NAME, API_KEY_REALM_TYPE, "node"), |
310 |
| - TransportVersionUtils.randomVersionBetween(random(), TransportVersions.V_7_0_0, TransportVersions.V_7_8_1), |
311 |
| - authMetadata |
312 |
| - ); |
313 |
| - |
314 |
| - final RoleReferenceIntersection roleReferenceIntersection = subject.getRoleReferenceIntersection(getAnonymousUser()); |
315 |
| - final List<RoleReference> roleReferences = roleReferenceIntersection.getRoleReferences(); |
316 |
| - |
317 |
| - if (emptyApiKeyRoleDescriptor) { |
318 |
| - assertThat(roleReferences, contains(isA(BwcApiKeyRoleReference.class))); |
319 |
| - final BwcApiKeyRoleReference limitedByRoleReference = (BwcApiKeyRoleReference) roleReferences.get(0); |
320 |
| - assertThat(limitedByRoleReference.getApiKeyId(), equalTo(apiKeyId)); |
321 |
| - assertThat(limitedByRoleReference.getRoleDescriptorsMap(), equalTo(authMetadata.get(API_KEY_LIMITED_ROLE_DESCRIPTORS_KEY))); |
322 |
| - } else { |
323 |
| - assertThat(roleReferences, contains(isA(BwcApiKeyRoleReference.class), isA(BwcApiKeyRoleReference.class))); |
324 |
| - final BwcApiKeyRoleReference roleReference = (BwcApiKeyRoleReference) roleReferences.get(0); |
325 |
| - assertThat(roleReference.getApiKeyId(), equalTo(apiKeyId)); |
326 |
| - assertThat(roleReference.getRoleDescriptorsMap(), equalTo(authMetadata.get(API_KEY_ROLE_DESCRIPTORS_KEY))); |
327 |
| - |
328 |
| - final BwcApiKeyRoleReference limitedByRoleReference = (BwcApiKeyRoleReference) roleReferences.get(1); |
329 |
| - assertThat(limitedByRoleReference.getApiKeyId(), equalTo(apiKeyId)); |
330 |
| - assertThat(limitedByRoleReference.getRoleDescriptorsMap(), equalTo(authMetadata.get(API_KEY_LIMITED_ROLE_DESCRIPTORS_KEY))); |
331 |
| - } |
332 |
| - } |
333 |
| - |
334 | 286 | public void testGetFleetApiKeyRoleReferenceBwcBugFix() {
|
335 | 287 | final BytesReference roleBytes = new BytesArray("{\"a role\": {\"cluster\": [\"all\"]}}");
|
336 | 288 | final BytesReference limitedByRoleBytes = new BytesArray("{}");
|
|
0 commit comments