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());
}
}
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());
}
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()));
}
}
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());
}
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);
}
Aggregations