use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientRegionClearAuthDUnitTest method testRegionClear.
@Test
public void testRegionClear() throws InterruptedException {
// Verify that an unauthorized user can't clear the region
SerializableRunnable clearUnauthorized = new SerializableRunnable() {
@Override
public void run() {
ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.clear(), "DATA:WRITE:AuthRegion");
}
};
client1.invoke(clearUnauthorized);
// Verify that an authorized user can clear the region
SerializableRunnable clearAuthorized = new SerializableRunnable() {
@Override
public void run() {
ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.clear();
}
};
client2.invoke(clearAuthorized);
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientRegisterInterestAuthDUnitTest method testRegisterInterestRegex.
@Test
public void testRegisterInterestRegex() 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 = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
assertNotAuthorized(() -> region.registerInterestRegex("key.*"), "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:key3;
region.registerInterestRegex("key[0-9]+");
});
// 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.registerInterestRegex("key[0-9]+"), "DATA:READ:AuthRegion");
assertNotAuthorized(() -> region.registerInterestRegex("key1"), "DATA:READ:AuthRegion");
});
ai1.await();
ai2.await();
ai3.await();
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientRemoveAllAuthDUnitTest method testRemoveAll.
@Test
public void testRemoveAll() throws Exception {
AsyncInvocation ai1 = client1.invokeAsync(() -> {
ClientCache cache = createClientCache("authRegionReader", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.removeAll(Arrays.asList("key1", "key2", "key3", "key4")), "DATA:WRITE:AuthRegion");
});
AsyncInvocation ai2 = client2.invokeAsync(() -> {
ClientCache cache = createClientCache("authRegionWriter", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.removeAll(Arrays.asList("key1", "key2", "key3", "key4"));
assertFalse(region.containsKey("key1"));
assertNotAuthorized(() -> region.containsKeyOnServer("key1"), "DATA:READ:AuthRegion:key1");
});
ai1.await();
ai2.await();
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientDestroyInvalidateAuthDUnitTest method testDestroyInvalidate.
@Test
public void testDestroyInvalidate() throws Exception {
// Delete one key and invalidate another key with an authorized user.
AsyncInvocation ai1 = client1.invokeAsync(() -> {
ClientCache cache = SecurityTestUtil.createClientCache("dataUser", "1234567", server.getPort());
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
assertTrue(region.containsKeyOnServer("key1"));
// Destroy key1
region.destroy("key1");
assertFalse(region.containsKeyOnServer("key1"));
// Invalidate key2
assertNotNull("Value of key2 should not be null", region.get("key2"));
region.invalidate("key2");
assertNull("Value of key2 should have been null", region.get("key2"));
});
// Delete one key and invalidate another key with an unauthorized user.
AsyncInvocation ai2 = client2.invokeAsync(() -> {
ClientCache cache = SecurityTestUtil.createClientCache("authRegionReader", "1234567", server.getPort());
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
assertTrue(region.containsKeyOnServer("key3"));
// Destroy key1
SecurityTestUtil.assertNotAuthorized(() -> region.destroy("key3"), "DATA:WRITE:AuthRegion");
assertTrue(region.containsKeyOnServer("key3"));
// Invalidate key2
assertNotNull("Value of key4 should not be null", region.get("key4"));
SecurityTestUtil.assertNotAuthorized(() -> region.invalidate("key4"), "DATA:WRITE:AuthRegion");
assertNotNull("Value of key4 should not be null", region.get("key4"));
});
ai1.await();
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientDestroyRegionAuthDUnitTest method testDestroyRegion.
@Test
public void testDestroyRegion() throws InterruptedException {
client1.invoke(() -> {
ClientCache cache = SecurityTestUtil.createClientCache("dataWriter", "1234567", server.getPort());
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
SecurityTestUtil.assertNotAuthorized(() -> region.destroyRegion(), "DATA:MANAGE");
});
client2.invoke(() -> {
ClientCache cache = SecurityTestUtil.createClientCache("authRegionManager", "1234567", server.getPort());
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
SecurityTestUtil.assertNotAuthorized(() -> region.destroyRegion(), "DATA:MANAGE");
});
client3.invoke(() -> {
ClientCache cache = SecurityTestUtil.createClientCache("super-user", "1234567", server.getPort());
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
region.destroyRegion();
assertThat(region.isDestroyed()).isTrue();
});
}
Aggregations