Cleanup: Split service transport service for client & server
In order to be more flexible this clean up commit splits the TransportService into a client and server one. As part of this we can safely remove the slightly misused TransportFilters class. Renamed shield.type from server to node, so we can differentiate between node2node and node2client communication. Original commit: elastic/x-pack-elasticsearch@a3a2f9bf38
This commit is contained in:
parent
060e17bc91
commit
431f30893f
1
pom.xml
1
pom.xml
|
@ -20,7 +20,6 @@
|
|||
<version>7</version>
|
||||
</parent>
|
||||
|
||||
<!-- needed for some test features for now, remove with 1.3 release -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>es-releases</id>
|
||||
|
|
|
@ -11,7 +11,10 @@ import org.elasticsearch.shield.authc.AuthenticationService;
|
|||
import org.elasticsearch.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* This interface allows clients, that connect to an elasticsearch cluster, to execute
|
||||
* additional logic before an operation is sent.
|
||||
*
|
||||
* This interface only applies to outgoing messages
|
||||
*/
|
||||
public interface ClientTransportFilter {
|
||||
|
||||
|
@ -25,7 +28,7 @@ public interface ClientTransportFilter {
|
|||
/**
|
||||
* The client transport filter that should be used in transport clients
|
||||
*/
|
||||
public static class Client implements ClientTransportFilter {
|
||||
public static class TransportClient implements ClientTransportFilter {
|
||||
|
||||
@Override
|
||||
public void outbound(String action, TransportRequest request) {
|
||||
|
@ -54,4 +57,4 @@ public interface ClientTransportFilter {
|
|||
authcService.attachUserHeaderIfMissing(request, User.SYSTEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.shield.transport;
|
||||
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.*;
|
||||
|
||||
public class SecuredClientTransportService extends TransportService {
|
||||
|
||||
private final ClientTransportFilter clientFilter;
|
||||
|
||||
@Inject
|
||||
public SecuredClientTransportService(Settings settings, Transport transport, ThreadPool threadPool, ClientTransportFilter clientFilter) {
|
||||
super(settings, transport, threadPool);
|
||||
this.clientFilter = clientFilter;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T extends TransportResponse> void sendRequest(DiscoveryNode node, String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler) {
|
||||
try {
|
||||
clientFilter.outbound(action, request);
|
||||
super.sendRequest(node, action, request, options, handler);
|
||||
} catch (Throwable t) {
|
||||
handler.handleException(new TransportException("failed sending request", t));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.shield.transport;
|
||||
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.collect.Maps;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.shield.transport.netty.NettySecuredTransport;
|
||||
|
@ -13,30 +14,30 @@ import org.elasticsearch.shield.transport.netty.SecuredMessageChannelHandler;
|
|||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SecuredTransportService extends TransportService {
|
||||
public class SecuredServerTransportService extends TransportService {
|
||||
|
||||
public static final String SETTING_NAME = "shield.type";
|
||||
|
||||
private final ServerTransportFilter clientProfileFilter;
|
||||
private final ServerTransportFilter nodeProfileFilter;
|
||||
private final ClientTransportFilter clientFilter;
|
||||
private final ServerTransportFilters serverTransportFilters;
|
||||
private final Map<String, ServerTransportFilter> profileFilters;
|
||||
|
||||
@Inject
|
||||
public SecuredTransportService(Settings settings, Transport transport, ThreadPool threadPool, ClientTransportFilter clientFilter, ServerTransportFilters serverTransportFilters) {
|
||||
public SecuredServerTransportService(Settings settings, Transport transport, ThreadPool threadPool,
|
||||
ServerTransportFilter.ClientProfile clientProfileFilter,
|
||||
ServerTransportFilter.NodeProfile nodeProfileFilter,
|
||||
ClientTransportFilter clientTransportFilter) {
|
||||
super(settings, transport, threadPool);
|
||||
this.clientFilter = clientFilter;
|
||||
this.serverTransportFilters = serverTransportFilters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHandler(String action, TransportRequestHandler handler) {
|
||||
// Only try to access the profile, if we use netty and SSL
|
||||
// otherwise use the regular secured request handler (this still allows for LocalTransport)
|
||||
if (transport instanceof NettySecuredTransport) {
|
||||
super.registerHandler(action, new ProfileSecuredRequestHandler(action, handler, serverTransportFilters));
|
||||
} else {
|
||||
super.registerHandler(action, new SecuredRequestHandler(action, handler, serverTransportFilters));
|
||||
}
|
||||
this.clientProfileFilter = clientProfileFilter;
|
||||
this.nodeProfileFilter = nodeProfileFilter;
|
||||
this.clientFilter = clientTransportFilter;
|
||||
this.profileFilters = initializeProfileFilters();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,6 +50,43 @@ public class SecuredTransportService extends TransportService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHandler(String action, TransportRequestHandler handler) {
|
||||
// Only try to access the profile, if we use netty and SSL
|
||||
// otherwise use the regular secured request handler (this still allows for LocalTransport)
|
||||
if (profileFilters != null) {
|
||||
super.registerHandler(action, new ProfileSecuredRequestHandler(action, handler, profileFilters));
|
||||
} else {
|
||||
super.registerHandler(action, new SecuredRequestHandler(action, handler, nodeProfileFilter));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, ServerTransportFilter> initializeProfileFilters() {
|
||||
if (!(transport instanceof NettySecuredTransport)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, Settings> profileSettings = settings.getGroups("transport.profiles.", true);
|
||||
Map<String, ServerTransportFilter> profileFilters = Maps.newHashMapWithExpectedSize(profileSettings.size());
|
||||
|
||||
for (Map.Entry<String, Settings> entry : profileSettings.entrySet()) {
|
||||
String type = entry.getValue().get(SETTING_NAME, "node");
|
||||
switch (type) {
|
||||
case "client":
|
||||
profileFilters.put(entry.getKey(), clientProfileFilter);
|
||||
break;
|
||||
default:
|
||||
profileFilters.put(entry.getKey(), nodeProfileFilter);
|
||||
}
|
||||
}
|
||||
|
||||
if (!profileFilters.containsKey("default")) {
|
||||
profileFilters.put("default", nodeProfileFilter);
|
||||
}
|
||||
|
||||
return profileFilters;
|
||||
}
|
||||
|
||||
static abstract class AbstractSecuredRequestHandler implements TransportRequestHandler {
|
||||
|
||||
protected TransportRequestHandler handler;
|
||||
|
@ -78,13 +116,14 @@ public class SecuredTransportService extends TransportService {
|
|||
protected final String action;
|
||||
protected final ServerTransportFilter transportFilter;
|
||||
|
||||
SecuredRequestHandler(String action, TransportRequestHandler handler, ServerTransportFilters serverTransportFilters) {
|
||||
SecuredRequestHandler(String action, TransportRequestHandler handler, ServerTransportFilter serverTransportFilter) {
|
||||
super(handler);
|
||||
this.action = action;
|
||||
this.transportFilter = serverTransportFilters.getTransportFilterForProfile("default");
|
||||
this.transportFilter = serverTransportFilter;
|
||||
}
|
||||
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void messageReceived(TransportRequest request, TransportChannel channel) throws Exception {
|
||||
try {
|
||||
transportFilter.inbound(action, request);
|
||||
|
@ -99,20 +138,24 @@ public class SecuredTransportService extends TransportService {
|
|||
static class ProfileSecuredRequestHandler extends AbstractSecuredRequestHandler {
|
||||
|
||||
protected final String action;
|
||||
protected final ServerTransportFilters serverTransportFilters;
|
||||
private final Map<String, ServerTransportFilter> profileFilters;
|
||||
|
||||
ProfileSecuredRequestHandler(String action, TransportRequestHandler handler, ServerTransportFilters serverTransportFilters) {
|
||||
public ProfileSecuredRequestHandler(String action, TransportRequestHandler handler, Map<String, ServerTransportFilter> profileFilters) {
|
||||
super(handler);
|
||||
this.action = action;
|
||||
this.serverTransportFilters = serverTransportFilters;
|
||||
this.profileFilters = profileFilters;
|
||||
}
|
||||
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void messageReceived(TransportRequest request, TransportChannel channel) throws Exception {
|
||||
try {
|
||||
SecuredMessageChannelHandler.VisibleNettyTransportChannel nettyTransportChannel = (SecuredMessageChannelHandler.VisibleNettyTransportChannel) channel;
|
||||
String profile = nettyTransportChannel.getProfile();
|
||||
ServerTransportFilter filter = serverTransportFilters.getTransportFilterForProfile(profile);
|
||||
ServerTransportFilter filter = profileFilters.get(profile);
|
||||
if (filter == null) {
|
||||
filter = profileFilters.get("default");
|
||||
}
|
||||
filter.inbound(action, request);
|
||||
} catch (Throwable t) {
|
||||
channel.sendResponse(t);
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.shield.transport;
|
|||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.PreProcessModule;
|
||||
import org.elasticsearch.common.inject.multibindings.MapBinder;
|
||||
import org.elasticsearch.common.inject.util.Providers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.shield.ShieldPlugin;
|
||||
|
@ -42,30 +41,27 @@ public class SecuredTransportModule extends AbstractShieldModule.Spawn implement
|
|||
@Override
|
||||
public void processModule(Module module) {
|
||||
if (module instanceof TransportModule) {
|
||||
((TransportModule) module).setTransportService(SecuredTransportService.class, ShieldPlugin.NAME);
|
||||
if (clientMode) {
|
||||
((TransportModule) module).setTransportService(SecuredClientTransportService.class, ShieldPlugin.NAME);
|
||||
} else {
|
||||
((TransportModule) module).setTransportService(SecuredServerTransportService.class, ShieldPlugin.NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(boolean clientMode) {
|
||||
MapBinder<String, ServerTransportFilter> mapBinder = MapBinder.newMapBinder(binder(), String.class, ServerTransportFilter.class);
|
||||
mapBinder.addBinding(ServerTransportFilters.SERVER_TRANSPORT_FILTER_TRANSPORT_CLIENT).to(ServerTransportFilter.TransportClient.class);
|
||||
|
||||
if (clientMode) {
|
||||
// no ip filtering on the client
|
||||
bind(IPFilter.class).toProvider(Providers.<IPFilter>of(null));
|
||||
bind(ClientTransportFilter.class).to(ClientTransportFilter.Client.class).asEagerSingleton();
|
||||
bind(ClientTransportFilter.class).to(ClientTransportFilter.TransportClient.class).asEagerSingleton();
|
||||
} else {
|
||||
mapBinder.addBinding(ServerTransportFilters.SERVER_TRANSPORT_FILTER_AUTHENTICATE_REJECT_INTERNAL_ACTIONS).to(ServerTransportFilter.RejectInternalActionsFilter.class);
|
||||
mapBinder.addBinding(ServerTransportFilters.SERVER_TRANSPORT_FILTER_AUTHENTICATE_ONLY).to(ServerTransportFilter.Node.class);
|
||||
|
||||
bind(ClientTransportFilter.class).to(ClientTransportFilter.Node.class).asEagerSingleton();
|
||||
|
||||
bind(ServerTransportFilter.ClientProfile.class).asEagerSingleton();
|
||||
bind(ServerTransportFilter.NodeProfile.class).asEagerSingleton();
|
||||
if (settings.getAsBoolean("shield.transport.filter.enabled", true)) {
|
||||
bind(IPFilter.class).asEagerSingleton();
|
||||
}
|
||||
}
|
||||
|
||||
bind(ServerTransportFilters.class).asEagerSingleton();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,12 @@ import org.elasticsearch.shield.authc.AuthenticationService;
|
|||
import org.elasticsearch.shield.authz.AuthorizationService;
|
||||
import org.elasticsearch.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* This interface allows to intercept messages as they come in and execute logic
|
||||
* This is used in SHIELD to execute the authentication/authorization on incoming
|
||||
* messages.
|
||||
* Note that this filter only applies for nodes, but not for clients.
|
||||
*/
|
||||
public interface ServerTransportFilter {
|
||||
|
||||
/**
|
||||
|
@ -22,25 +28,16 @@ public interface ServerTransportFilter {
|
|||
void inbound(String action, TransportRequest request);
|
||||
|
||||
/**
|
||||
* The server trasnport filter that should be used in transport clients
|
||||
* The server trasnport filter that should be used in nodes as it ensures that an incoming
|
||||
* request is properly authenticated and authorized
|
||||
*/
|
||||
public static class TransportClient implements ServerTransportFilter {
|
||||
|
||||
@Override
|
||||
public void inbound(String action, TransportRequest request) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The server trasnport filter that should be used in nodes
|
||||
*/
|
||||
public static class Node implements ServerTransportFilter {
|
||||
public static class NodeProfile implements ServerTransportFilter {
|
||||
|
||||
private final AuthenticationService authcService;
|
||||
private final AuthorizationService authzService;
|
||||
|
||||
@Inject
|
||||
public Node(AuthenticationService authcService, AuthorizationService authzService) {
|
||||
public NodeProfile(AuthenticationService authcService, AuthorizationService authzService) {
|
||||
this.authcService = authcService;
|
||||
this.authzService = authzService;
|
||||
}
|
||||
|
@ -62,12 +59,14 @@ public interface ServerTransportFilter {
|
|||
|
||||
/**
|
||||
* A server transport filter rejects internal calls, which should be used on connections
|
||||
* where only clients connect to
|
||||
* where only clients connect to. This ensures that no client can send any internal actions
|
||||
* or shard level actions. As it extends the NodeProfile the authentication/authorization is
|
||||
* done as well
|
||||
*/
|
||||
public static class RejectInternalActionsFilter extends ServerTransportFilter.Node {
|
||||
public static class ClientProfile extends NodeProfile {
|
||||
|
||||
@Inject
|
||||
public RejectInternalActionsFilter(AuthenticationService authcService, AuthorizationService authzService) {
|
||||
public ClientProfile(AuthenticationService authcService, AuthorizationService authzService) {
|
||||
super(authcService, authzService);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.shield.transport;
|
||||
|
||||
import org.elasticsearch.common.collect.Maps;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ServerTransportFilters extends AbstractComponent {
|
||||
|
||||
public static final String SETTING_NAME = "shield.type";
|
||||
|
||||
public static final String SERVER_TRANSPORT_FILTER_TRANSPORT_CLIENT = "transportclient";
|
||||
public static final String SERVER_TRANSPORT_FILTER_AUTHENTICATE_REJECT_INTERNAL_ACTIONS = "client";
|
||||
public static final String SERVER_TRANSPORT_FILTER_AUTHENTICATE_ONLY = "server";
|
||||
|
||||
|
||||
private final Map<String, ServerTransportFilter> transportFilters;
|
||||
private final boolean isTransportClient;
|
||||
private final ServerTransportFilter clientServerTransportFilter;
|
||||
|
||||
@Inject
|
||||
public ServerTransportFilters(Settings settings, Map<String, ServerTransportFilter> configuredTransportFilter) {
|
||||
super(settings);
|
||||
this.isTransportClient = "transport".equals(settings.get("client.type"));
|
||||
this.clientServerTransportFilter = configuredTransportFilter.get(SERVER_TRANSPORT_FILTER_TRANSPORT_CLIENT);
|
||||
|
||||
Map<String, Settings> profileSettings = settings.getGroups("transport.profiles.", true);
|
||||
this.transportFilters = Maps.newHashMapWithExpectedSize(profileSettings.size());
|
||||
|
||||
for (Map.Entry<String, Settings> entry : profileSettings.entrySet()) {
|
||||
String type = entry.getValue().get(SETTING_NAME, SERVER_TRANSPORT_FILTER_AUTHENTICATE_ONLY);
|
||||
transportFilters.put(entry.getKey(), configuredTransportFilter.get(type));
|
||||
}
|
||||
|
||||
if (!transportFilters.containsKey("default")) {
|
||||
transportFilters.put("default", configuredTransportFilter.get(SERVER_TRANSPORT_FILTER_AUTHENTICATE_ONLY));
|
||||
}
|
||||
|
||||
logger.trace("Added shield transport filters: {}", transportFilters.keySet());
|
||||
}
|
||||
|
||||
public ServerTransportFilter getTransportFilterForProfile(String profile) {
|
||||
if (isTransportClient) {
|
||||
return clientServerTransportFilter;
|
||||
}
|
||||
|
||||
if (!transportFilters.containsKey(profile)) {
|
||||
return transportFilters.get("default");
|
||||
}
|
||||
|
||||
return transportFilters.get(profile);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ import org.elasticsearch.node.internal.InternalNode;
|
|||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.shield.authc.support.SecuredString;
|
||||
import org.elasticsearch.shield.authc.support.UsernamePasswordToken;
|
||||
import org.elasticsearch.shield.transport.SecuredTransportService;
|
||||
import org.elasticsearch.shield.transport.SecuredServerTransportService;
|
||||
import org.elasticsearch.shield.transport.netty.NettySecuredTransport;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
||||
import org.elasticsearch.test.ShieldIntegrationTest;
|
||||
|
@ -80,7 +80,7 @@ public class ShieldPluginEnabledDisabledTests extends ShieldIntegrationTest {
|
|||
@Test
|
||||
public void testTransportEnabledDisabled() throws Exception {
|
||||
for (TransportService service : internalCluster().getInstances(TransportService.class)) {
|
||||
Matcher<TransportService> matcher = instanceOf(SecuredTransportService.class);
|
||||
Matcher<TransportService> matcher = instanceOf(SecuredServerTransportService.class);
|
||||
if (!enabled) {
|
||||
matcher = not(matcher);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class ServerTransportFilterIntegrationTest extends ShieldIntegrationTest
|
|||
|
||||
return settingsBuilder
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put("transport.profiles.default.shield.type", "server")
|
||||
.put("transport.profiles.default.shield.type", "node")
|
||||
.put("transport.profiles.client.shield.type", "client")
|
||||
.put("transport.profiles.client.port", randomClientPortRange)
|
||||
.put("transport.profiles.client.bind_host", "localhost") // make sure this is "localhost", no matter if ipv4 or ipv6, but be consistent
|
||||
|
|
|
@ -31,7 +31,7 @@ public class ServerTransportFilterTests extends ElasticsearchTestCase {
|
|||
public void init() throws Exception {
|
||||
authcService = mock(AuthenticationService.class);
|
||||
authzService = mock(AuthorizationService.class);
|
||||
filter = new ServerTransportFilter.Node(authcService, authzService);
|
||||
filter = new ServerTransportFilter.NodeProfile(authcService, authzService);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.shield.transport;
|
||||
|
||||
import org.elasticsearch.common.collect.Maps;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
public class ServerTransportFiltersTest extends ElasticsearchTestCase {
|
||||
|
||||
private Map<String, ServerTransportFilter> filters = Maps.newHashMap();
|
||||
|
||||
public class TestAuthenticateTransportFilter extends ServerTransportFilter.TransportClient {}
|
||||
public class TestRejectInternalActionsTransportFilter extends ServerTransportFilter.TransportClient {}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
filters.put(ServerTransportFilters.SERVER_TRANSPORT_FILTER_TRANSPORT_CLIENT, new ServerTransportFilter.TransportClient());
|
||||
filters.put(ServerTransportFilters.SERVER_TRANSPORT_FILTER_AUTHENTICATE_REJECT_INTERNAL_ACTIONS, new TestRejectInternalActionsTransportFilter());
|
||||
filters.put(ServerTransportFilters.SERVER_TRANSPORT_FILTER_AUTHENTICATE_ONLY, new TestAuthenticateTransportFilter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Settings settings = settingsBuilder()
|
||||
.put("transport.profiles.default.shield.type", "client")
|
||||
.put("transport.profiles.alternative.shield.type", "server")
|
||||
.build();
|
||||
|
||||
ServerTransportFilters serverTransportFilters = new ServerTransportFilters(settings, filters);
|
||||
|
||||
// default filter is returned by default
|
||||
ServerTransportFilter expectedClientFilter = serverTransportFilters.getTransportFilterForProfile("default");
|
||||
assertThat(expectedClientFilter, instanceOf(TestRejectInternalActionsTransportFilter.class));
|
||||
|
||||
ServerTransportFilter expectedDummyFilter = serverTransportFilters.getTransportFilterForProfile("alternative");
|
||||
assertThat(expectedDummyFilter, instanceOf(TestAuthenticateTransportFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatExceptionIsThrownForUnknownProfile() {
|
||||
ServerTransportFilters serverTransportFilters = new ServerTransportFilters(settingsBuilder().build(), filters);
|
||||
assertThat(serverTransportFilters.getTransportFilterForProfile("unknown"), instanceOf(TestAuthenticateTransportFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatClientFilterIsReturnedOnClientNodes() {
|
||||
Settings settings = settingsBuilder()
|
||||
.put("node.client", true)
|
||||
.put("client.type", "transport")
|
||||
.build();
|
||||
|
||||
ServerTransportFilters serverTransportFilters = new ServerTransportFilters(settings, filters);
|
||||
|
||||
// no matter the profile, client node means client filter
|
||||
ServerTransportFilter expectedDummyFilter = serverTransportFilters.getTransportFilterForProfile("a");
|
||||
assertThat(expectedDummyFilter, instanceOf(ServerTransportFilter.TransportClient.class));
|
||||
expectedDummyFilter = serverTransportFilters.getTransportFilterForProfile("b");
|
||||
assertThat(expectedDummyFilter, instanceOf(ServerTransportFilter.TransportClient.class));
|
||||
expectedDummyFilter = serverTransportFilters.getTransportFilterForProfile("c");
|
||||
assertThat(expectedDummyFilter, instanceOf(ServerTransportFilter.TransportClient.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.cluster.ClusterService;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.multibindings.MapBinder;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
|
@ -44,7 +43,7 @@ public class TransportFilterTests extends ElasticsearchIntegrationTest {
|
|||
return ImmutableSettings.settingsBuilder()
|
||||
.put("plugins.load_classpath_plugins", false)
|
||||
.put("plugin.types", InternalPlugin.class.getName())
|
||||
.put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, SecuredTransportService.class.getName())
|
||||
.put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, SecuredServerTransportService.class.getName())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -68,11 +67,9 @@ public class TransportFilterTests extends ElasticsearchIntegrationTest {
|
|||
targetService.sendRequest(sourceNode, "_action", new Request("trgt_to_src"), new ResponseHandler(new Response("src_to_trgt"), latch));
|
||||
await(latch);
|
||||
|
||||
ServerTransportFilters sourceFilters = internalCluster().getInstance(ServerTransportFilters.class, source);
|
||||
ServerTransportFilter sourceServerFilter = sourceFilters.getTransportFilterForProfile("default");
|
||||
ServerTransportFilter.NodeProfile sourceServerFilter = internalCluster().getInstance(ServerTransportFilter.NodeProfile.class, source);
|
||||
ClientTransportFilter sourceClientFilter = internalCluster().getInstance(ClientTransportFilter.class, source);
|
||||
ServerTransportFilters targetFilters = internalCluster().getInstance(ServerTransportFilters.class, target);
|
||||
ServerTransportFilter targetServerFilter = targetFilters.getTransportFilterForProfile("default");
|
||||
ServerTransportFilter.NodeProfile targetServerFilter = internalCluster().getInstance(ServerTransportFilter.NodeProfile.class, target);
|
||||
ClientTransportFilter targetClientFilter = internalCluster().getInstance(ClientTransportFilter.class, target);
|
||||
InOrder inOrder = inOrder(sourceServerFilter, sourceClientFilter, targetServerFilter, targetClientFilter);
|
||||
inOrder.verify(sourceClientFilter).outbound("_action", new Request("src_to_trgt"));
|
||||
|
@ -103,13 +100,8 @@ public class TransportFilterTests extends ElasticsearchIntegrationTest {
|
|||
@Override
|
||||
protected void configure() {
|
||||
bind(ClientTransportFilter.class).toInstance(mock(ClientTransportFilter.class));
|
||||
|
||||
// bind all to our dummy impls
|
||||
MapBinder<String, ServerTransportFilter> mapBinder = MapBinder.newMapBinder(binder(), String.class, ServerTransportFilter.class);
|
||||
mapBinder.addBinding(ServerTransportFilters.SERVER_TRANSPORT_FILTER_TRANSPORT_CLIENT).toInstance(mock(ServerTransportFilter.class));
|
||||
mapBinder.addBinding(ServerTransportFilters.SERVER_TRANSPORT_FILTER_AUTHENTICATE_ONLY).toInstance(mock(ServerTransportFilter.class));
|
||||
mapBinder.addBinding(ServerTransportFilters.SERVER_TRANSPORT_FILTER_AUTHENTICATE_REJECT_INTERNAL_ACTIONS).toInstance(mock(ServerTransportFilter.class));
|
||||
bind(ServerTransportFilters.class).asEagerSingleton();
|
||||
bind(ServerTransportFilter.NodeProfile.class).toInstance(mock(ServerTransportFilter.NodeProfile.class));
|
||||
bind(ServerTransportFilter.ClientProfile.class).toInstance(mock(ServerTransportFilter.ClientProfile.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue