Search in sources :

Example 6 with ClientCache

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();
    });
}
Also used : CqEvent(org.apache.geode.cache.query.CqEvent) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqListener(org.apache.geode.cache.query.CqListener) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Region(org.apache.geode.cache.Region) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) Pool(org.apache.geode.cache.client.Pool) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) CqQuery(org.apache.geode.cache.query.CqQuery) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 7 with ClientCache

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);
}
Also used : Pool(org.apache.geode.cache.client.Pool) ClientCache(org.apache.geode.cache.client.ClientCache) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory)

Example 8 with ClientCache

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();
}
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 9 with ClientCache

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();
}
Also used : ArrayList(java.util.ArrayList) 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 10 with ClientCache

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

Aggregations

ClientCache (org.apache.geode.cache.client.ClientCache)115 Test (org.junit.Test)74 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)73 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)67 Region (org.apache.geode.cache.Region)65 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)27 SelectResults (org.apache.geode.cache.query.SelectResults)26 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