use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientQueryAuthDUnitTest method testCQ.
@Test
public void testCQ() {
String query = "select * from /AuthRegion";
client1.invoke(() -> {
ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
Pool pool = PoolManager.find(region);
QueryService qs = pool.getQueryService();
CqAttributes cqa = new CqAttributesFactory().create();
// Create the CqQuery
CqQuery cq = qs.newCq("CQ1", query, cqa);
assertNotAuthorized(() -> cq.executeWithInitialResults(), "DATA:READ:AuthRegion");
assertNotAuthorized(() -> cq.execute(), "DATA:READ:AuthRegion");
assertNotAuthorized(() -> cq.close(), "DATA:MANAGE");
});
client2.invoke(() -> {
ClientCache cache = createClientCache("authRegionReader", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
Pool pool = PoolManager.find(region);
QueryService qs = pool.getQueryService();
CqAttributes cqa = new CqAttributesFactory().create();
// Create the CqQuery
CqQuery cq = qs.newCq("CQ1", query, cqa);
cq.execute();
assertNotAuthorized(() -> cq.stop(), "DATA:MANAGE");
assertNotAuthorized(() -> qs.getAllDurableCqsFromServer(), "CLUSTER:READ");
});
client3.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
Pool pool = PoolManager.find(region);
QueryService qs = pool.getQueryService();
CqAttributesFactory factory = new CqAttributesFactory();
factory.addCqListener(new CqListener() {
@Override
public void onEvent(final CqEvent aCqEvent) {
System.out.println(aCqEvent);
}
@Override
public void onError(final CqEvent aCqEvent) {
}
@Override
public void close() {
}
});
CqAttributes cqa = factory.create();
// Create the CqQuery
CqQuery cq = qs.newCq("CQ1", query, cqa);
System.out.println("query result: " + cq.executeWithInitialResults());
cq.stop();
});
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class TestClientIdsDUnitTest method createClientCache.
private void createClientCache(final String host, final int serverPort) {
ClientCache cache = this.managementTestRule.getClientCache();
Pool pool = PoolManager.createFactory().addServer(host, serverPort).setSubscriptionEnabled(false).setThreadLocalConnections(true).setMinConnections(1).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(1).setSubscriptionEnabled(true).setStatisticInterval(1000).create(getClass().getSimpleName());
ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
factory.setPoolName(pool.getName());
factory.create(REGION_NAME);
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientRegisterInterestAuthDUnitTest method testRegisterInterest.
@Test
public void testRegisterInterest() throws Exception {
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.registerInterest("key3"), "DATA:READ:AuthRegion:key3");
});
// client2 connects to user as a user authorized to use AuthRegion region
AsyncInvocation ai2 = client2.invokeAsync(() -> {
ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// DATA:READ:AuthRegion:key3;
region.registerInterest("key3");
});
// client3 connects to user as a user authorized to use key1 in AuthRegion region
AsyncInvocation ai3 = client3.invokeAsync(() -> {
ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.registerInterest("key2"), "DATA:READ:AuthRegion:key2");
});
ai1.await();
ai2.await();
ai3.await();
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientRegisterInterestAuthDUnitTest method testRegisterInterestList.
@Test
public void testRegisterInterestList() throws Exception {
List<String> keys = new ArrayList<>();
keys.add("key1");
keys.add("key2");
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
assertNotAuthorized(() -> region.registerInterest(keys), "DATA:READ:AuthRegion");
});
// client2 connects to user as a user authorized to use AuthRegion region
AsyncInvocation ai2 = client2.invokeAsync(() -> {
ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
// DATA:READ:AuthRegion;
region.registerInterest(keys);
});
// client3 connects to user as a user authorized to use key1 in AuthRegion region
AsyncInvocation ai3 = client3.invokeAsync(() -> {
ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
assertNotAuthorized(() -> region.registerInterest(keys), "DATA:READ:AuthRegion");
});
ai1.await();
ai2.await();
ai3.await();
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientUnregisterInterestAuthDUnitTest method testUnregisterInterest.
@Test
public void testUnregisterInterest() throws Exception {
// client2 connects to user as a user authorized to use AuthRegion region
AsyncInvocation ai1 = client2.invokeAsync(() -> {
ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.registerInterest("key3");
// DATA:READ:AuthRegion:key3;
region.unregisterInterest("key3");
});
ai1.await();
}
Aggregations