Search in sources :

Example 1 with NetworkAddress

use of org.infinispan.server.network.NetworkAddress in project infinispan by infinispan.

the class SocketBindingsConfiguration method applySocketBinding.

public void applySocketBinding(String bindingName, ProtocolServerConfigurationBuilder builder, SinglePortServerConfigurationBuilder singlePort) {
    if (!socketBindings.containsKey(bindingName)) {
        throw Server.log.unknownSocketBinding(bindingName);
    }
    SocketBindingConfiguration binding = socketBindings.get(bindingName);
    NetworkAddress networkAddress = binding.interfaceConfiguration().getNetworkAddress();
    String host = networkAddress.getAddress().getHostAddress();
    int port = binding.port() + offset();
    if (builder != singlePort) {
        // Ensure we are using a different socket binding than the one used by the single-port endpoint
        if (builder.startTransport() && singlePort.host().equals(host) && singlePort.port() == port) {
            throw Server.log.protocolCannotUseSameSocketBindingAsEndpoint();
        }
    }
    builder.socketBinding(bindingName).host(host).port(port);
}
Also used : NetworkAddress(org.infinispan.server.network.NetworkAddress)

Example 2 with NetworkAddress

use of org.infinispan.server.network.NetworkAddress in project infinispan by infinispan.

the class ProtocolManagementIT method testIpFilter.

@Test
public void testIpFilter() throws IOException {
    NetworkAddress loopback = NetworkAddress.loopback("loopback");
    RestClientConfigurationBuilder loopbackBuilder = new RestClientConfigurationBuilder();
    loopbackBuilder.addServer().host(loopback.getAddress().getHostAddress()).port(11222);
    RestClient loopbackClient = SERVER_TEST.rest().withClientConfiguration(loopbackBuilder).get();
    assertStatus(200, loopbackClient.server().connectorNames());
    NetworkAddress siteLocal = NetworkAddress.match("sitelocal", iF -> !iF.getName().startsWith("docker"), InetAddress::isSiteLocalAddress);
    RestClientConfigurationBuilder siteLocalBuilder0 = new RestClientConfigurationBuilder();
    siteLocalBuilder0.addServer().host(siteLocal.getAddress().getHostAddress()).port(11222);
    RestClient siteLocalClient0 = SERVER_TEST.rest().withClientConfiguration(siteLocalBuilder0).get();
    assertStatus(200, siteLocalClient0.server().connectorNames());
    RestClientConfigurationBuilder siteLocalBuilder1 = new RestClientConfigurationBuilder();
    siteLocalBuilder1.addServer().host(siteLocal.getAddress().getHostAddress()).port(11322);
    RestClient siteLocalClient1 = SERVER_TEST.rest().withClientConfiguration(siteLocalBuilder1).get();
    assertStatus(200, siteLocalClient1.server().connectorNames());
    List<IpFilterRule> rules = new ArrayList<>();
    rules.add(new IpFilterRule(IpFilterRule.RuleType.REJECT, siteLocal.cidr()));
    assertStatus(204, loopbackClient.server().connectorIpFilterSet("endpoint-default", rules));
    Exceptions.expectException(RuntimeException.class, ExecutionException.class, SocketException.class, () -> sync(siteLocalClient0.server().connectorNames()));
    Exceptions.expectException(RuntimeException.class, ExecutionException.class, SocketException.class, () -> sync(siteLocalClient1.server().connectorNames()));
    assertStatus(204, loopbackClient.server().connectorIpFiltersClear("endpoint-default"));
    assertStatus(200, siteLocalClient0.server().connectorNames());
    assertStatus(200, siteLocalClient1.server().connectorNames());
    // Attempt to lock ourselves out
    assertStatus(409, siteLocalClient0.server().connectorIpFilterSet("endpoint-default", rules));
    // Apply the filter just on the Hot Rod endpoint
    assertStatus(204, loopbackClient.server().connectorIpFilterSet("HotRod-hotrod", rules));
    ConfigurationBuilder hotRodSiteLocalBuilder = new ConfigurationBuilder();
    hotRodSiteLocalBuilder.addServer().host(siteLocal.getAddress().getHostAddress()).port(11222).clientIntelligence(ClientIntelligence.BASIC);
    RemoteCacheManager siteLocalRemoteCacheManager = SERVER_TEST.hotrod().withClientConfiguration(hotRodSiteLocalBuilder).createRemoteCacheManager();
    Exceptions.expectException(TransportException.class, siteLocalRemoteCacheManager::getCacheNames);
    // REST should still work, so let's clear the rules
    assertStatus(204, siteLocalClient0.server().connectorIpFiltersClear("HotRod-hotrod"));
    // And retry
    assertNotNull(siteLocalRemoteCacheManager.getCacheNames());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) NetworkAddress(org.infinispan.server.network.NetworkAddress) RestClient(org.infinispan.client.rest.RestClient) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) IpFilterRule(org.infinispan.client.rest.IpFilterRule) Test(org.junit.Test)

Example 3 with NetworkAddress

use of org.infinispan.server.network.NetworkAddress in project infinispan by infinispan.

the class ProtocolManagementIT method testConnectorStartStop.

@Test
public void testConnectorStartStop() throws IOException {
    NetworkAddress loopback = NetworkAddress.loopback("loopback");
    RestClientConfigurationBuilder defaultBuilder = new RestClientConfigurationBuilder();
    defaultBuilder.addServer().host(loopback.getAddress().getHostAddress()).port(11222);
    RestClient defaultClient = SERVER_TEST.rest().withClientConfiguration(defaultBuilder).get();
    assertStatus(200, defaultClient.caches());
    RestClientConfigurationBuilder alternateBuilder = new RestClientConfigurationBuilder();
    alternateBuilder.addServer().host(loopback.getAddress().getHostAddress()).port(11223);
    RestClient alternateClient = SERVER_TEST.rest().withClientConfiguration(alternateBuilder).get();
    assertStatus(200, alternateClient.caches());
    assertStatus(204, defaultClient.server().connectorStop("endpoint-alternate-1"));
    Exceptions.expectException(RuntimeException.class, ExecutionException.class, SocketException.class, () -> sync(alternateClient.caches()));
    assertStatus(204, defaultClient.server().connectorStart("endpoint-alternate-1"));
    assertStatus(200, alternateClient.caches());
    // Attempt to lock ourselves out
    assertStatus(409, defaultClient.server().connectorStop("endpoint-default"));
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) NetworkAddress(org.infinispan.server.network.NetworkAddress) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 4 with NetworkAddress

use of org.infinispan.server.network.NetworkAddress in project infinispan by infinispan.

the class ServerConfigurationParserTest method validateConfiguration.

private void validateConfiguration(ServerConfiguration configuration) {
    // Interfaces
    assertEquals(2, configuration.networkInterfaces().size());
    NetworkAddress defaultInterface = configuration.networkInterfaces().get("default").getNetworkAddress();
    assertNotNull(defaultInterface);
    assertTrue(defaultInterface.getAddress().isLoopbackAddress());
    // Socket bindings
    Map<String, SocketBindingConfiguration> socketBindings = configuration.socketBindings();
    assertEquals(5, socketBindings.size());
    assertEquals(11221, socketBindings.get("memcached").port());
    assertEquals(12221, socketBindings.get("memcached-2").port());
    assertEquals(11222, socketBindings.get("default").port());
    assertEquals(11223, socketBindings.get("hotrod").port());
    assertEquals(8080, socketBindings.get("rest").port());
    // Security realms
    Map<String, RealmConfiguration> realms = configuration.security().realms().realms();
    assertEquals(3, realms.size());
    RealmConfiguration realmConfiguration = realms.get("default");
    assertEquals("default", realmConfiguration.name());
    realmConfiguration = realms.get("using-credentials");
    assertEquals("using-credentials", realmConfiguration.name());
    // Data Sources
    Map<String, DataSourceConfiguration> dataSources = configuration.dataSources();
    assertEquals(2, dataSources.size());
    DataSourceConfiguration dataSource = dataSources.get("database");
    assertEquals("jdbc/database", dataSource.jndiName());
    assertEquals("jdbc:h2:tcp://${org.infinispan.test.host.address}:1521/test", dataSource.url());
    assertEquals("test", dataSource.username());
    assertEquals("test", new String(dataSource.password()));
    assertEquals("SELECT 1", dataSource.initialSql());
    assertEquals("org.h2.Driver", dataSource.driver());
    assertEquals(10, dataSource.maxSize());
    assertEquals(1, dataSource.minSize());
    assertEquals(1, dataSource.initialSize());
    assertEquals(1, dataSource.connectionProperties().size());
    assertEquals(10000, dataSource.leakDetection());
    assertEquals(1000, dataSource.backgroundValidation());
    assertEquals(500, dataSource.validateOnAcquisition());
    assertEquals("somevalue", dataSource.connectionProperties().get("someproperty"));
    dataSource = dataSources.get("database-with-credential");
    assertEquals("test", new String(dataSource.password()));
    // Connectors
    List<ProtocolServerConfiguration> connectors = configuration.endpoints().endpoints().get(0).connectors();
    assertEquals(3, connectors.size());
    assertTrue(connectors.get(0) instanceof HotRodServerConfiguration);
    assertTrue(connectors.get(1) instanceof RestServerConfiguration);
    assertTrue(connectors.get(2) instanceof MemcachedServerConfiguration);
    // Ensure endpoints are bound to the interfaces
    SinglePortRouterConfiguration singlePortRouter = configuration.endpoints().endpoints().get(0).singlePortRouter();
    assertEquals(socketBindings.get("default").interfaceConfiguration().getNetworkAddress().getAddress().getHostAddress(), singlePortRouter.host());
    assertEquals(socketBindings.get("default").port(), singlePortRouter.port());
    assertEquals(socketBindings.get("memcached").port(), configuration.endpoints().endpoints().get(0).connectors().get(2).port());
    assertEquals("strongPassword", new String(((Supplier<char[]>) realmProvider(realmConfiguration, LdapRealmConfiguration.class).attributes().attribute(Attribute.CREDENTIAL).get()).get()));
    assertEquals("secret", new String(((Supplier<char[]>) realmConfiguration.serverIdentitiesConfiguration().sslConfiguration().trustStore().attributes().attribute(Attribute.PASSWORD).get()).get()));
    assertEquals("1fdca4ec-c416-47e0-867a-3d471af7050f", new String(((Supplier<char[]>) realmProvider(realmConfiguration, TokenRealmConfiguration.class).oauth2Configuration().attributes().attribute(Attribute.CLIENT_SECRET).get()).get()));
}
Also used : HotRodServerConfiguration(org.infinispan.server.hotrod.configuration.HotRodServerConfiguration) SinglePortRouterConfiguration(org.infinispan.server.router.configuration.SinglePortRouterConfiguration) RealmConfiguration(org.infinispan.server.configuration.security.RealmConfiguration) LdapRealmConfiguration(org.infinispan.server.configuration.security.LdapRealmConfiguration) TokenRealmConfiguration(org.infinispan.server.configuration.security.TokenRealmConfiguration) ProtocolServerConfiguration(org.infinispan.server.core.configuration.ProtocolServerConfiguration) MemcachedServerConfiguration(org.infinispan.server.memcached.configuration.MemcachedServerConfiguration) NetworkAddress(org.infinispan.server.network.NetworkAddress) TokenRealmConfiguration(org.infinispan.server.configuration.security.TokenRealmConfiguration) RestServerConfiguration(org.infinispan.rest.configuration.RestServerConfiguration) ElytronPasswordProviderSupplier(org.infinispan.server.security.ElytronPasswordProviderSupplier) Supplier(java.util.function.Supplier)

Aggregations

NetworkAddress (org.infinispan.server.network.NetworkAddress)4 RestClient (org.infinispan.client.rest.RestClient)2 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)2 Test (org.junit.Test)2 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Supplier (java.util.function.Supplier)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 IpFilterRule (org.infinispan.client.rest.IpFilterRule)1 RestServerConfiguration (org.infinispan.rest.configuration.RestServerConfiguration)1 LdapRealmConfiguration (org.infinispan.server.configuration.security.LdapRealmConfiguration)1 RealmConfiguration (org.infinispan.server.configuration.security.RealmConfiguration)1 TokenRealmConfiguration (org.infinispan.server.configuration.security.TokenRealmConfiguration)1 ProtocolServerConfiguration (org.infinispan.server.core.configuration.ProtocolServerConfiguration)1 HotRodServerConfiguration (org.infinispan.server.hotrod.configuration.HotRodServerConfiguration)1 MemcachedServerConfiguration (org.infinispan.server.memcached.configuration.MemcachedServerConfiguration)1 SinglePortRouterConfiguration (org.infinispan.server.router.configuration.SinglePortRouterConfiguration)1 ElytronPasswordProviderSupplier (org.infinispan.server.security.ElytronPasswordProviderSupplier)1