Search in sources :

Example 61 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class AbstractAuthorization method testBulkReadUsersCanQuery.

@Test
public void testBulkReadUsersCanQuery() {
    org.infinispan.configuration.cache.ConfigurationBuilder builder = prepareIndexedCache();
    for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.DEPLOYER, TestUser.APPLICATION, TestUser.OBSERVER)) {
        RemoteCache<Integer, User> userCache = getServerTest().hotrod().withClientConfiguration(clientConfigurationWithProtostreamMarshaller(user)).withServerConfiguration(builder).get();
        User fromCache = userCache.get(1);
        HotRodCacheQueries.assertUser1(fromCache);
        QueryFactory qf = Search.getQueryFactory(userCache);
        Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'Tom'");
        List<User> list = query.execute().list();
        assertNotNull(list);
        assertEquals(1, list.size());
        assertEquals(User.class, list.get(0).getClass());
        HotRodCacheQueries.assertUser1(list.get(0));
    }
    for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.DEPLOYER, TestUser.APPLICATION, TestUser.OBSERVER)) {
        RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
        assertStatus(OK, userCache.query("FROM sample_bank_account.User WHERE name = 'Tom'"));
        assertStatus(OK, userCache.searchStats());
        assertStatus(OK, userCache.indexStats());
        assertStatus(OK, userCache.queryStats());
    }
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) TestUser(org.infinispan.server.test.api.TestUser) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 62 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class AbstractAuthorization method testRestAdminCanDoEverything.

@Test
public void testRestAdminCanDoEverything() {
    RestCacheClient adminCache = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ADMIN)).withCacheMode(CacheMode.DIST_SYNC).create().cache(getServerTest().getMethodName());
    sync(adminCache.put("k", "v"));
    assertEquals("v", sync(adminCache.get("k")).getBody());
}
Also used : RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.junit.Test)

Example 63 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class AbstractAuthorization method testRestReaderCannotWrite.

private void testRestReaderCannotWrite(String... explicitRoles) {
    restCreateAuthzCache(explicitRoles);
    RestCacheClient readerCache = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.OBSERVER)).get().cache(getServerTest().getMethodName());
    assertStatus(FORBIDDEN, readerCache.put("k1", "v1"));
    for (TestUser user : EnumSet.of(TestUser.APPLICATION, TestUser.DEPLOYER)) {
        RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
        assertStatus(NO_CONTENT, userCache.put(user.name(), user.name()));
    }
}
Also used : RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser)

Example 64 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class AbstractAuthorization method assertXSiteOps.

private void assertXSiteOps(TestUser user, int status, int noContentStatus, int notModifiedStatus) {
    RestClientConfigurationBuilder userConfig = restBuilders.get(user);
    RestClient client = getServerTest().rest().withClientConfiguration(userConfig).get();
    RestCacheClient xsiteCache = client.cache("xsite");
    assertStatus(status, xsiteCache.takeSiteOffline("NYC"));
    assertStatus(status, xsiteCache.bringSiteOnline("NYC"));
    assertStatus(status, xsiteCache.cancelPushState("NYC"));
    assertStatus(status, xsiteCache.cancelReceiveState("NYC"));
    assertStatus(status, xsiteCache.clearPushStateStatus());
    assertStatus(status, xsiteCache.pushSiteState("NYC"));
    assertStatus(status, xsiteCache.pushStateStatus());
    assertStatus(status, xsiteCache.xsiteBackups());
    assertStatus(status, xsiteCache.backupStatus("NYC"));
    assertStatus(status, xsiteCache.getXSiteTakeOfflineConfig("NYC"));
    assertStatus(noContentStatus, xsiteCache.updateXSiteTakeOfflineConfig("NYC", 10, 1000));
    assertStatus(status, xsiteCache.xSiteStateTransferMode("NYC"));
    assertStatus(notModifiedStatus, xsiteCache.xSiteStateTransferMode("NYC", XSiteStateTransferMode.MANUAL));
    RestCacheManagerClient xsiteCacheManager = client.cacheManager("default");
    assertStatus(status, xsiteCacheManager.bringBackupOnline("NYC"));
    assertStatus(status, xsiteCacheManager.takeOffline("NYC"));
    assertStatus(status, xsiteCacheManager.backupStatuses());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 65 with RestCacheClient

use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.

the class AbstractAuthorization method testRestNonAdminsMustNotPerformSearchActions.

@Test
public void testRestNonAdminsMustNotPerformSearchActions() {
    String schema = Exceptions.unchecked(() -> Util.getResourceAsString("/sample_bank_account/bank.proto", this.getClass().getClassLoader()));
    assertStatus(OK, getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ADMIN)).get().schemas().put(BANK_PROTO, schema));
    org.infinispan.configuration.cache.ConfigurationBuilder builder = new org.infinispan.configuration.cache.ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC);
    builder.indexing().enable().addIndexedEntity("sample_bank_account.User").statistics().enable();
    RestClient restClient = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ADMIN)).withServerConfiguration(builder).create();
    String indexedCache = getServerTest().getMethodName();
    RestCacheClient cache = restClient.cache(indexedCache);
    for (TestUser user : TestUser.NON_ADMINS) {
        searchActions(user, indexedCache, FORBIDDEN, FORBIDDEN);
    }
    searchActions(TestUser.ADMIN, indexedCache, OK, NO_CONTENT);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) AuthorizationConfigurationBuilder(org.infinispan.configuration.cache.AuthorizationConfigurationBuilder) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Aggregations

RestCacheClient (org.infinispan.client.rest.RestCacheClient)66 RestResponse (org.infinispan.client.rest.RestResponse)41 Test (org.testng.annotations.Test)34 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)16 RestEntity (org.infinispan.client.rest.RestEntity)14 Json (org.infinispan.commons.dataconversion.internal.Json)13 RestClient (org.infinispan.client.rest.RestClient)11 Test (org.junit.Test)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)5 TestClass (org.infinispan.rest.TestClass)5 TestUser (org.infinispan.server.test.api.TestUser)5 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 HashMap (java.util.HashMap)2 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)2 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2