|
7 | 7 | package org.elasticsearch.xpack.ccr;
|
8 | 8 |
|
9 | 9 | import org.elasticsearch.ElasticsearchStatusException;
|
10 |
| -import org.elasticsearch.action.ActionType; |
11 | 10 | import org.elasticsearch.action.ActionListener;
|
12 | 11 | import org.elasticsearch.action.ActionRequest;
|
13 | 12 | import org.elasticsearch.action.ActionResponse;
|
| 13 | +import org.elasticsearch.action.ActionType; |
14 | 14 | import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
15 | 15 | import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
16 | 16 | import org.elasticsearch.action.admin.indices.stats.IndexShardStats;
|
|
45 | 45 | import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
|
46 | 46 | import org.elasticsearch.xpack.core.security.authz.permission.ResourcePrivileges;
|
47 | 47 | import org.elasticsearch.xpack.core.security.support.Exceptions;
|
| 48 | +import org.elasticsearch.xpack.core.security.user.User; |
48 | 49 |
|
49 | 50 | import java.util.Arrays;
|
50 | 51 | import java.util.Collections;
|
|
61 | 62 | /**
|
62 | 63 | * Encapsulates licensing checking for CCR.
|
63 | 64 | */
|
64 |
| -public final class CcrLicenseChecker { |
| 65 | +public class CcrLicenseChecker { |
65 | 66 |
|
66 | 67 | private final BooleanSupplier isCcrAllowed;
|
67 | 68 | private final BooleanSupplier isAuthAllowed;
|
@@ -307,9 +308,12 @@ public void hasPrivilegesToFollowIndices(final Client remoteClient, final String
|
307 | 308 | return;
|
308 | 309 | }
|
309 | 310 |
|
310 |
| - ThreadContext threadContext = remoteClient.threadPool().getThreadContext(); |
311 |
| - SecurityContext securityContext = new SecurityContext(Settings.EMPTY, threadContext); |
312 |
| - String username = securityContext.getUser().principal(); |
| 311 | + final User user = getUser(remoteClient); |
| 312 | + if (user == null) { |
| 313 | + handler.accept(new IllegalStateException("missing or unable to read authentication info on request")); |
| 314 | + return; |
| 315 | + } |
| 316 | + String username = user.principal(); |
313 | 317 |
|
314 | 318 | RoleDescriptor.IndicesPrivileges privileges = RoleDescriptor.IndicesPrivileges.builder()
|
315 | 319 | .indices(indices)
|
@@ -344,6 +348,12 @@ public void hasPrivilegesToFollowIndices(final Client remoteClient, final String
|
344 | 348 | remoteClient.execute(HasPrivilegesAction.INSTANCE, request, ActionListener.wrap(responseHandler, handler));
|
345 | 349 | }
|
346 | 350 |
|
| 351 | + User getUser(final Client remoteClient) { |
| 352 | + final ThreadContext threadContext = remoteClient.threadPool().getThreadContext(); |
| 353 | + final SecurityContext securityContext = new SecurityContext(Settings.EMPTY, threadContext); |
| 354 | + return securityContext.getUser(); |
| 355 | + } |
| 356 | + |
347 | 357 | public static Client wrapClient(Client client, Map<String, String> headers) {
|
348 | 358 | if (headers.isEmpty()) {
|
349 | 359 | return client;
|
|
0 commit comments