|
39 | 39 | import org.elasticsearch.search.internal.ContextIndexSearcher;
|
40 | 40 | import org.elasticsearch.test.AbstractBuilderTestCase;
|
41 | 41 | import org.elasticsearch.test.IndexSettingsModule;
|
| 42 | +import org.elasticsearch.xpack.core.security.SecurityContext; |
42 | 43 | import org.elasticsearch.xpack.core.security.authc.Authentication;
|
43 |
| -import org.elasticsearch.xpack.core.security.authc.AuthenticationField; |
| 44 | +import org.elasticsearch.xpack.core.security.authc.support.AuthenticationContextSerializer; |
44 | 45 | import org.elasticsearch.xpack.core.security.authz.permission.DocumentPermissions;
|
45 | 46 | import org.elasticsearch.xpack.core.security.authz.permission.FieldPermissions;
|
46 | 47 | import org.elasticsearch.xpack.core.security.user.User;
|
@@ -69,10 +70,14 @@ public void testDLS() throws Exception {
|
69 | 70 | when(mapperService.simpleMatchToFullName(anyString()))
|
70 | 71 | .then(invocationOnMock -> Collections.singletonList((String) invocationOnMock.getArguments()[0]));
|
71 | 72 |
|
72 |
| - ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 73 | + final ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 74 | + final SecurityContext securityContext = new SecurityContext(Settings.EMPTY, threadContext); |
| 75 | + |
73 | 76 | final Authentication authentication = mock(Authentication.class);
|
74 | 77 | when(authentication.getUser()).thenReturn(mock(User.class));
|
75 |
| - threadContext.putTransient(AuthenticationField.AUTHENTICATION_KEY, authentication); |
| 78 | + when(authentication.encode()).thenReturn(randomAlphaOfLength(24)); // don't care as long as it's not null |
| 79 | + new AuthenticationContextSerializer().writeToContext(authentication, threadContext); |
| 80 | + |
76 | 81 | IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(shardId.getIndex(), Settings.EMPTY);
|
77 | 82 | Client client = mock(Client.class);
|
78 | 83 | when(client.settings()).thenReturn(Settings.EMPTY);
|
@@ -135,7 +140,7 @@ null, null, mapperService, null, null, xContentRegistry(), writableRegistry(),
|
135 | 140 | FieldPermissions(),
|
136 | 141 | DocumentPermissions.filteredBy(singleton(new BytesArray(termQuery))));
|
137 | 142 | SecurityIndexReaderWrapper wrapper = new SecurityIndexReaderWrapper(s -> queryShardContext,
|
138 |
| - bitsetCache, threadContext, licenseState, scriptService) { |
| 143 | + bitsetCache, securityContext, licenseState, scriptService) { |
139 | 144 |
|
140 | 145 | @Override
|
141 | 146 | protected IndicesAccessControl getIndicesAccessControl() {
|
@@ -173,10 +178,13 @@ public void testDLSWithLimitedPermissions() throws Exception {
|
173 | 178 | when(mapperService.simpleMatchToFullName(anyString()))
|
174 | 179 | .then(invocationOnMock -> Collections.singletonList((String) invocationOnMock.getArguments()[0]));
|
175 | 180 |
|
176 |
| - ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 181 | + final ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 182 | + final SecurityContext securityContext = new SecurityContext(Settings.EMPTY, threadContext); |
177 | 183 | final Authentication authentication = mock(Authentication.class);
|
178 | 184 | when(authentication.getUser()).thenReturn(mock(User.class));
|
179 |
| - threadContext.putTransient(AuthenticationField.AUTHENTICATION_KEY, authentication); |
| 185 | + when(authentication.encode()).thenReturn(randomAlphaOfLength(24)); // don't care as long as it's not null |
| 186 | + new AuthenticationContextSerializer().writeToContext(authentication, threadContext); |
| 187 | + |
180 | 188 | final boolean noFilteredIndexPermissions = randomBoolean();
|
181 | 189 | boolean restrictiveLimitedIndexPermissions = false;
|
182 | 190 | if (noFilteredIndexPermissions == false) {
|
@@ -208,7 +216,7 @@ null, null, mapperService, null, null, xContentRegistry(), writableRegistry(),
|
208 | 216 | XPackLicenseState licenseState = mock(XPackLicenseState.class);
|
209 | 217 | when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(true);
|
210 | 218 | SecurityIndexReaderWrapper wrapper = new SecurityIndexReaderWrapper(s -> queryShardContext,
|
211 |
| - bitsetCache, threadContext, licenseState, scriptService) { |
| 219 | + bitsetCache, securityContext, licenseState, scriptService) { |
212 | 220 |
|
213 | 221 | @Override
|
214 | 222 | protected IndicesAccessControl getIndicesAccessControl() {
|
|
0 commit comments