Search in sources :

Example 16 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class AbstractAuthorization method addClientBuilders.

protected void addClientBuilders(TestUser user) {
    ConfigurationBuilder hotRodBuilder = new ConfigurationBuilder();
    hotRodBuilder.security().authentication().saslMechanism(System.getProperty(HOTROD_CLIENT_SASL_MECHANISM, "SCRAM-SHA-1")).serverName("infinispan").realm("default").username(user.getUser()).password(user.getPassword());
    hotRodBuilders.put(user, hotRodBuilder);
    RestClientConfigurationBuilder restBuilder = new RestClientConfigurationBuilder();
    restBuilder.security().authentication().mechanism("AUTO").username(user.getUser()).password(user.getPassword());
    restBuilders.put(user, restBuilder);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) AuthorizationConfigurationBuilder(org.infinispan.configuration.cache.AuthorizationConfigurationBuilder) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)

Example 17 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class AuthorizationCertIT method addClientBuilders.

@Override
protected void addClientBuilders(TestUser user) {
    ConfigurationBuilder hotRodBuilder = new ConfigurationBuilder();
    SERVERS.getServerDriver().applyTrustStore(hotRodBuilder, "ca");
    if (user == TestUser.ANONYMOUS) {
        SERVERS.getServerDriver().applyKeyStore(hotRodBuilder, "server");
    } else {
        SERVERS.getServerDriver().applyKeyStore(hotRodBuilder, user.getUser());
    }
    hotRodBuilder.security().authentication().saslMechanism("EXTERNAL").serverName("infinispan").realm("default");
    hotRodBuilders.put(user, hotRodBuilder);
    RestClientConfigurationBuilder restBuilder = new RestClientConfigurationBuilder();
    SERVERS.getServerDriver().applyTrustStore(restBuilder, "ca");
    if (user == TestUser.ANONYMOUS) {
        SERVERS.getServerDriver().applyKeyStore(restBuilder, "server");
    } else {
        SERVERS.getServerDriver().applyKeyStore(restBuilder, user.getUser());
    }
    restBuilder.security().authentication().ssl().sniHostName("infinispan").hostnameVerifier((hostname, session) -> true).connectionTimeout(120_000).socketTimeout(120_000);
    restBuilders.put(user, restBuilder);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)

Example 18 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class GracefulShutdownRestartIT method testGracefulShutdownRestart.

@Test
public void testGracefulShutdownRestart() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC).persistence().addSingleFileStore().segmented(false);
    RemoteCache<Object, Object> hotRod = SERVER_TEST.hotrod().withServerConfiguration(builder).create();
    for (int i = 0; i < 100; i++) {
        hotRod.put(String.format("k%03d", i), String.format("v%03d", i));
    }
    RestClientConfigurationBuilder restClientBuilder = new RestClientConfigurationBuilder().socketTimeout(RestClientConfigurationProperties.DEFAULT_SO_TIMEOUT * 60).connectionTimeout(RestClientConfigurationProperties.DEFAULT_CONNECT_TIMEOUT * 60);
    RestClient rest = SERVER_TEST.rest().withClientConfiguration(restClientBuilder).get();
    sync(rest.cluster().stop(), 5, TimeUnit.MINUTES);
    ContainerInfinispanServerDriver serverDriver = (ContainerInfinispanServerDriver) SERVER.getServerDriver();
    Eventually.eventually("Cluster did not shutdown within timeout", () -> (!serverDriver.isRunning(0) && !serverDriver.isRunning(1)), serverDriver.getTimeout(), 1, TimeUnit.SECONDS);
    serverDriver.restartCluster();
    for (int i = 0; i < 100; i++) {
        assertEquals(String.format("v%03d", i), hotRod.get(String.format("k%03d", i)));
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) ContainerInfinispanServerDriver(org.infinispan.server.test.core.ContainerInfinispanServerDriver) Test(org.junit.Test)

Example 19 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class RestAuthentication method testRestReadWrite.

@Test
public void testRestReadWrite() {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    if (!mechanism.isEmpty()) {
        builder.protocol(protocol).security().authentication().mechanism(mechanism).realm("default").username("all_user").password("all");
    }
    if (mechanism.isEmpty()) {
        Exceptions.expectException(SecurityException.class, () -> SERVER_TEST.rest().withClientConfiguration(builder).create());
    } else {
        RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
        RestResponse response = sync(client.cache(SERVER_TEST.getMethodName()).post("k1", "v1"));
        assertEquals(204, response.getStatus());
        assertEquals(protocol, response.getProtocol());
        response = sync(client.cache(SERVER_TEST.getMethodName()).get("k1"));
        assertEquals(200, response.getStatus());
        assertEquals(protocol, response.getProtocol());
        assertEquals("v1", response.getBody());
    }
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 20 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class AuthenticationMultiEndpointIT method testRest.

private void testRest() {
    Protocol proto = Protocol.valueOf(protocol);
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder().followRedirects(false);
    if (useAuth) {
        builder.protocol(proto).security().authentication().mechanism(mechanism).realm(realm).username(userPrefix + "all_user").password("all");
    }
    try {
        RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).withPort(port).create();
        validateSuccess();
        RestResponse response = sync(client.cache(SERVER_TEST.getMethodName()).post("k1", "v1"));
        assertEquals(204, response.getStatus());
        assertEquals(proto, response.getProtocol());
        response = sync(client.cache(SERVER_TEST.getMethodName()).get("k1"));
        assertEquals(200, response.getStatus());
        assertEquals(proto, response.getProtocol());
        assertEquals("v1", response.getBody());
        response = sync(client.raw().get("/"));
        assertEquals(isAdmin ? 307 : 404, response.getStatus());
        response = sync(client.server().info());
        assertEquals(isAdmin ? 200 : 404, response.getStatus());
    } catch (SecurityException e) {
        validateException(e);
    }
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Protocol(org.infinispan.client.rest.configuration.Protocol)

Aggregations

RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)56 Test (org.junit.Test)26 RestClient (org.infinispan.client.rest.RestClient)25 RestResponse (org.infinispan.client.rest.RestResponse)22 RestClientConfiguration (org.infinispan.client.rest.configuration.RestClientConfiguration)8 RestServerHelper (org.infinispan.rest.helper.RestServerHelper)6 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)5 InetSocketAddress (java.net.InetSocketAddress)4 RestCacheClient (org.infinispan.client.rest.RestCacheClient)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 RestServer (org.infinispan.rest.RestServer)4 RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)4 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)4 DummyServerManagement (org.infinispan.server.core.DummyServerManagement)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RestEntity (org.infinispan.client.rest.RestEntity)3 Json (org.infinispan.commons.dataconversion.internal.Json)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 Router (org.infinispan.server.router.Router)3