|
47 | 47 | import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
|
48 | 48 | import org.elasticsearch.xpack.core.security.authz.permission.ResourcePrivileges;
|
49 | 49 | import org.elasticsearch.xpack.core.security.support.Exceptions;
|
| 50 | +import org.elasticsearch.xpack.core.security.user.User; |
50 | 51 |
|
51 | 52 | import java.util.Arrays;
|
52 | 53 | import java.util.Collections;
|
|
63 | 64 | /**
|
64 | 65 | * Encapsulates licensing checking for CCR.
|
65 | 66 | */
|
66 |
| -public final class CcrLicenseChecker { |
| 67 | +public class CcrLicenseChecker { |
67 | 68 |
|
68 | 69 | private final BooleanSupplier isCcrAllowed;
|
69 | 70 | private final BooleanSupplier isAuthAllowed;
|
@@ -313,9 +314,12 @@ public void hasPrivilegesToFollowIndices(final Client remoteClient, final String
|
313 | 314 | return;
|
314 | 315 | }
|
315 | 316 |
|
316 |
| - ThreadContext threadContext = remoteClient.threadPool().getThreadContext(); |
317 |
| - SecurityContext securityContext = new SecurityContext(Settings.EMPTY, threadContext); |
318 |
| - String username = securityContext.getUser().principal(); |
| 317 | + final User user = getUser(remoteClient); |
| 318 | + if (user == null) { |
| 319 | + handler.accept(new IllegalStateException("missing or unable to read authentication info on request")); |
| 320 | + return; |
| 321 | + } |
| 322 | + String username = user.principal(); |
319 | 323 |
|
320 | 324 | RoleDescriptor.IndicesPrivileges privileges = RoleDescriptor.IndicesPrivileges.builder()
|
321 | 325 | .indices(indices)
|
@@ -350,6 +354,12 @@ public void hasPrivilegesToFollowIndices(final Client remoteClient, final String
|
350 | 354 | remoteClient.execute(HasPrivilegesAction.INSTANCE, request, ActionListener.wrap(responseHandler, handler));
|
351 | 355 | }
|
352 | 356 |
|
| 357 | + User getUser(final Client remoteClient) { |
| 358 | + final ThreadContext threadContext = remoteClient.threadPool().getThreadContext(); |
| 359 | + final SecurityContext securityContext = new SecurityContext(Settings.EMPTY, threadContext); |
| 360 | + return securityContext.getUser(); |
| 361 | + } |
| 362 | + |
353 | 363 | public static Client wrapClient(Client client, Map<String, String> headers) {
|
354 | 364 | if (headers.isEmpty()) {
|
355 | 365 | return client;
|
|
0 commit comments