Search in sources :

Example 36 with RestClientConfigurationBuilder

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

the class RestConnectorTest method testUrlWithoutCredentials.

@Test
public void testUrlWithoutCredentials() {
    RestConnector connector = new RestConnector();
    RestConnection connection = (RestConnection) connector.getConnection("http://localhost:11222", null);
    RestClientConfigurationBuilder builder = connection.getBuilder();
    RestClientConfiguration configuration = builder.build();
    assertEquals(11222, configuration.servers().get(0).port());
    assertEquals("localhost", configuration.servers().get(0).host());
    assertFalse(configuration.security().authentication().enabled());
}
Also used : RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) Test(org.junit.Test)

Example 37 with RestClientConfigurationBuilder

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

the class RestConnectorTest method testUrlWithSSL.

@Test
public void testUrlWithSSL() throws NoSuchAlgorithmException {
    RestConnector connector = new RestConnector();
    RestConnection connection = (RestConnection) connector.getConnection("https://localhost", null);
    RestClientConfigurationBuilder builder = connection.getBuilder();
    builder.security().ssl().sslContext(SSLContext.getDefault()).trustManagers(new TrustManager[] { new ZeroSecurityTrustManager() });
    RestClientConfiguration configuration = builder.build();
    assertEquals(443, configuration.servers().get(0).port());
    assertEquals("localhost", configuration.servers().get(0).host());
    assertFalse(configuration.security().authentication().enabled());
    assertTrue(configuration.security().ssl().enabled());
}
Also used : RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) ZeroSecurityTrustManager(org.infinispan.cli.util.ZeroSecurityTrustManager) Test(org.junit.Test)

Example 38 with RestClientConfigurationBuilder

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

the class RestConnectorTest method testPlainHostPort.

@Test
public void testPlainHostPort() {
    RestConnector connector = new RestConnector();
    RestConnection connection = (RestConnection) connector.getConnection("my.host.com:12345", null);
    RestClientConfigurationBuilder builder = connection.getBuilder();
    RestClientConfiguration configuration = builder.build();
    assertEquals(12345, configuration.servers().get(0).port());
    assertEquals("my.host.com", configuration.servers().get(0).host());
}
Also used : RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) Test(org.junit.Test)

Example 39 with RestClientConfigurationBuilder

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

the class CertificateTest method shouldAllowProperCertificate.

@Test
public void shouldAllowProperCertificate() throws Exception {
    restServer = RestServerHelper.defaultRestServer().withAuthenticator(new ClientCertAuthenticator()).withKeyStore(SERVER_KEY_STORE, STORE_PASSWORD, STORE_TYPE).withTrustStore(SERVER_KEY_STORE, STORE_PASSWORD, STORE_TYPE).withClientAuth().start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder config = new RestClientConfigurationBuilder();
    config.security().ssl().enable().trustStoreFileName(CLIENT_KEY_STORE).trustStorePassword(STORE_PASSWORD).trustStoreType(STORE_TYPE).keyStoreFileName(CLIENT_KEY_STORE).keyStorePassword(STORE_PASSWORD).keyStoreType(STORE_TYPE).hostnameVerifier((hostname, session) -> true).addServer().host("localhost").port(restServer.getPort());
    client = RestClient.forConfiguration(config.build());
    // when
    CompletionStage<RestResponse> response = client.raw().get("/rest/v2/caches/default/test", Collections.emptyMap());
    // then
    assertEquals(404, response.toCompletableFuture().get(10, TimeUnit.MINUTES).getStatus());
}
Also used : TestResourceTracker(org.infinispan.commons.test.TestResourceTracker) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Test(org.testng.annotations.Test) CLIENT_KEY_STORE(org.infinispan.rest.helper.RestServerHelper.CLIENT_KEY_STORE) ClientCertAuthenticator(org.infinispan.rest.authentication.impl.ClientCertAuthenticator) AfterMethod(org.testng.annotations.AfterMethod) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) STORE_PASSWORD(org.infinispan.rest.helper.RestServerHelper.STORE_PASSWORD) TimeUnit(java.util.concurrent.TimeUnit) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) STORE_TYPE(org.infinispan.rest.helper.RestServerHelper.STORE_TYPE) CompletionStage(java.util.concurrent.CompletionStage) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest) SERVER_KEY_STORE(org.infinispan.rest.helper.RestServerHelper.SERVER_KEY_STORE) AfterSuite(org.testng.annotations.AfterSuite) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Collections(java.util.Collections) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) ClientCertAuthenticator(org.infinispan.rest.authentication.impl.ClientCertAuthenticator) RestResponse(org.infinispan.client.rest.RestResponse) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 40 with RestClientConfigurationBuilder

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

the class StaticResourceTest method createBeforeClass.

@BeforeClass(alwaysRun = true)
public void createBeforeClass() throws Throwable {
    super.createBeforeClass();
    RestClientConfigurationBuilder builder = super.getClientConfig("admin", "admin");
    builder.followRedirects(false).addServer().host(restServer().getHost()).port(restServer().getPort());
    noRedirectsClient = RestClient.forConfiguration(builder.build());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) BeforeClass(org.testng.annotations.BeforeClass)

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