Search in sources :

Example 11 with RestClientConfigurationBuilder

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

the class IgnoreCaches method testIgnoreCaches.

@Test
public void testIgnoreCaches() {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
    String testCache = SERVER_TEST.getMethodName();
    assertTrue(getIgnoredCaches(client, CACHE_MANAGER).isEmpty());
    assertCacheResponse(client, testCache, 404);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 404);
    ignoreCache(client, testCache);
    assertEquals(singleton(testCache), getIgnoredCaches(client, CACHE_MANAGER));
    assertCacheResponse(client, testCache, 503);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 404);
    ignoreCache(client, PROTOBUF_METADATA_CACHE_NAME);
    assertEquals(asSet(testCache, PROTOBUF_METADATA_CACHE_NAME), getIgnoredCaches(client, CACHE_MANAGER));
    assertCacheResponse(client, testCache, 503);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 503);
    unIgnoreCache(client, testCache);
    assertEquals(singleton(PROTOBUF_METADATA_CACHE_NAME), getIgnoredCaches(client, CACHE_MANAGER));
    assertCacheResponse(client, testCache, 404);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 503);
    unIgnoreCache(client, PROTOBUF_METADATA_CACHE_NAME);
    assertTrue(getIgnoredCaches(client, CACHE_MANAGER).isEmpty());
    assertCacheResponse(client, testCache, 404);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 404);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 12 with RestClientConfigurationBuilder

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

the class RestOperations method testCounter.

@Test
public void testCounter() {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.protocol(protocol);
    RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
    CounterConfiguration configuration = CounterConfiguration.builder(CounterType.WEAK).initialValue(5).concurrencyLevel(1).build();
    AbstractCounterConfiguration config = ConvertUtil.configToParsedConfig("test-counter", configuration);
    String configJson = AbstractRestResourceTest.counterConfigToJson(config);
    RestCounterClient counter = client.counter("test");
    RestResponse rsp = sync(counter.create(RestEntity.create(MediaType.APPLICATION_JSON, configJson)));
    assertEquals(HttpResponseStatus.OK.code(), rsp.getStatus());
    rsp = sync(counter.get());
    assertEquals("5", rsp.getBody());
}
Also used : RestCounterClient(org.infinispan.client.rest.RestCounterClient) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) CounterConfiguration(org.infinispan.counter.api.CounterConfiguration) AbstractRestResourceTest(org.infinispan.rest.resources.AbstractRestResourceTest) Test(org.junit.Test)

Example 13 with RestClientConfigurationBuilder

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

the class KeyCloakServerRule method getAccessTokenForCredentials.

public String getAccessTokenForCredentials(String realm, String client, String secret, String username, String password, Path trustStore, String trustStorePassword) {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    int port;
    if (trustStore != null) {
        builder.security().ssl().trustStoreFileName(trustStore.toString()).trustStorePassword(trustStorePassword.toCharArray()).hostnameVerifier((hostname, session) -> true);
        port = 8443;
    } else {
        port = 8080;
    }
    builder.addServer().host(container.getContainerIpAddress()).port(container.getMappedPort(port)).connectionTimeout(5000).socketTimeout(5000);
    try (RestClient c = RestClient.forConfiguration(builder.build())) {
        String url = String.format("/auth/realms/%s/protocol/openid-connect/token", realm);
        Map<String, List<String>> form = new HashMap<>();
        form.put("client_id", Collections.singletonList(client));
        form.put("client_secret", Collections.singletonList(secret));
        form.put("username", Collections.singletonList(username));
        form.put("password", Collections.singletonList(password));
        form.put("grant_type", Collections.singletonList("password"));
        RestResponse response = c.raw().postForm(url, Collections.singletonMap("Content-Type", "application/x-www-form-urlencoded"), form).toCompletableFuture().get(5, TimeUnit.SECONDS);
        Map<String, Json> map = Json.read(response.getBody()).asJsonMap();
        return map.get("access_token").asString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) HashMap(java.util.HashMap) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) ArrayList(java.util.ArrayList) List(java.util.List) Json(org.infinispan.commons.dataconversion.internal.Json) IOException(java.io.IOException)

Example 14 with RestClientConfigurationBuilder

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

the class AbstractAuthorization method testRestAdminsShouldBeAbleToAdminServer.

@Test
public void testRestAdminsShouldBeAbleToAdminServer() {
    RestClientConfigurationBuilder adminConfig = restBuilders.get(TestUser.ADMIN);
    RestClient client = getServerTest().rest().withClientConfiguration(adminConfig).get();
    assertStatus(NO_CONTENT, client.server().connectorStop("endpoint-alternate-1"));
    assertStatus(NO_CONTENT, client.server().connectorStart("endpoint-alternate-1"));
    assertStatus(NO_CONTENT, client.server().connectorIpFilterSet("endpoint-alternate-1", Collections.emptyList()));
    assertStatus(NO_CONTENT, client.server().connectorIpFiltersClear("endpoint-alternate-1"));
    assertStatus(OK, client.server().memory());
    assertStatus(OK, client.server().env());
    assertStatus(OK, client.server().configuration());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 15 with RestClientConfigurationBuilder

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

the class AbstractAuthorization method testRestNonAdminsMustNotAdminServer.

@Test
public void testRestNonAdminsMustNotAdminServer() {
    for (TestUser user : TestUser.NON_ADMINS) {
        RestClientConfigurationBuilder userConfig = restBuilders.get(user);
        RestClient client = getServerTest().rest().withClientConfiguration(userConfig).get();
        assertStatus(FORBIDDEN, client.server().report());
        assertStatus(FORBIDDEN, client.server().connectorStop("endpoint-default"));
        assertStatus(FORBIDDEN, client.server().connectorStart("endpoint-default"));
        assertStatus(FORBIDDEN, client.server().connectorIpFilterSet("endpoint-default", Collections.emptyList()));
        assertStatus(FORBIDDEN, client.server().connectorIpFiltersClear("endpoint-default"));
        assertStatus(FORBIDDEN, client.server().memory());
        assertStatus(FORBIDDEN, client.server().env());
        assertStatus(FORBIDDEN, client.server().configuration());
    }
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

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