Search in sources :

Example 66 with ClientCache

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);
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 67 with ClientCache

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();
}
Also used : SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 68 with ClientCache

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();
}
Also used : SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 69 with ClientCache

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();
}
Also used : Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 70 with ClientCache

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();
    });
}
Also used : Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

ClientCache (org.apache.geode.cache.client.ClientCache)112 Test (org.junit.Test)74 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)73 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)65 Region (org.apache.geode.cache.Region)64 VM (org.apache.geode.test.dunit.VM)43 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)42 Host (org.apache.geode.test.dunit.Host)40 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)31 QueryService (org.apache.geode.cache.query.QueryService)26 SelectResults (org.apache.geode.cache.query.SelectResults)25 SecurityTestUtil.createClientCache (org.apache.geode.security.SecurityTestUtil.createClientCache)25 SecurityTestUtil.createProxyRegion (org.apache.geode.security.SecurityTestUtil.createProxyRegion)23 CacheServer (org.apache.geode.cache.server.CacheServer)22 Cache (org.apache.geode.cache.Cache)20 CacheException (org.apache.geode.cache.CacheException)15 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)13 IOException (java.io.IOException)12 Properties (java.util.Properties)12 IgnoredException (org.apache.geode.test.dunit.IgnoredException)12