Search in sources :

Example 51 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ThinClientPermissionCheckTest method testSysOperation.

/**
 */
@Test
public void testSysOperation() throws Exception {
    try (IgniteClient sysPrmClnt = startClient(CLIENT_SYS_PERM)) {
        sysPrmClnt.createCache(DYNAMIC_CACHE);
        assertTrue(sysPrmClnt.cacheNames().contains(DYNAMIC_CACHE));
        sysPrmClnt.destroyCache(DYNAMIC_CACHE);
        assertFalse(sysPrmClnt.cacheNames().contains(DYNAMIC_CACHE));
    }
    List<IgniteBiTuple<Consumer<IgniteClient>, String>> ops = Arrays.asList(t(c -> c.createCache(DYNAMIC_CACHE), "createCache"), t(c -> c.destroyCache(CACHE), "destroyCache"));
    for (IgniteBiTuple<Consumer<IgniteClient>, String> op : ops) assertThrowsWithCause(() -> runOperation(CLIENT, op), ClientAuthorizationException.class);
}
Also used : Arrays(java.util.Arrays) CACHE_PUT(org.apache.ignite.plugin.security.SecurityPermission.CACHE_PUT) IgniteEx(org.apache.ignite.internal.IgniteEx) TestObject(org.apache.ignite.internal.processors.cache.eviction.paged.TestObject) ClientCache(org.apache.ignite.client.ClientCache) Map(java.util.Map) CacheEvent(org.apache.ignite.events.CacheEvent) ImmutableSet(com.google.common.collect.ImmutableSet) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) SecurityPermissionSetBuilder(org.apache.ignite.plugin.security.SecurityPermissionSetBuilder) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) TASK_EXECUTE(org.apache.ignite.plugin.security.SecurityPermission.TASK_EXECUTE) PlatformExpiryPolicyFactory(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory) Collectors(java.util.stream.Collectors) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) EVT_CACHE_OBJECT_EXPIRED(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_EXPIRED) CACHE_REMOVE(org.apache.ignite.plugin.security.SecurityPermission.CACHE_REMOVE) TestSecurityData(org.apache.ignite.internal.processors.security.impl.TestSecurityData) IntStream(java.util.stream.IntStream) ClusterState(org.apache.ignite.cluster.ClusterState) RunWith(org.junit.runner.RunWith) RANDOM_LRU(org.apache.ignite.configuration.DataPageEvictionMode.RANDOM_LRU) ALLOW_ALL(org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.ALLOW_ALL) CACHE_READ(org.apache.ignite.plugin.security.SecurityPermission.CACHE_READ) ArrayList(java.util.ArrayList) AbstractSecurityTest(org.apache.ignite.internal.processors.security.AbstractSecurityTest) CACHE_CREATE(org.apache.ignite.plugin.security.SecurityPermission.CACHE_CREATE) Config(org.apache.ignite.client.Config) IgniteClient(org.apache.ignite.client.IgniteClient) AbstractTestSecurityPluginProvider(org.apache.ignite.internal.processors.security.AbstractTestSecurityPluginProvider) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Collections.singletonMap(java.util.Collections.singletonMap) ClientAuthorizationException(org.apache.ignite.client.ClientAuthorizationException) TestSecurityPluginProvider(org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider) G(org.apache.ignite.internal.util.typedef.G) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) JUnit4(org.junit.runners.JUnit4) CACHE_DESTROY(org.apache.ignite.plugin.security.SecurityPermission.CACHE_DESTROY) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) GridFunc.t(org.apache.ignite.internal.util.lang.GridFunc.t) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ClientAuthorizationException(org.apache.ignite.client.ClientAuthorizationException) IgniteClient(org.apache.ignite.client.IgniteClient) Consumer(java.util.function.Consumer) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) AbstractSecurityTest(org.apache.ignite.internal.processors.security.AbstractSecurityTest) Test(org.junit.Test)

Example 52 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class IgniteClientContainSubjectAddressTest method testAuthenticate.

/**
 */
@Test
public void testAuthenticate() throws Exception {
    startGrid();
    try (IgniteClient client = Ignition.startClient(getClientConfiguration())) {
        client.cluster().state(ACTIVE);
    }
    Assert.assertTrue(containsAddr);
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 53 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class AdditionalSecurityCheckTest method testClientInfoIgniteClientFail.

/**
 */
@Test
public void testClientInfoIgniteClientFail() throws Exception {
    Ignite ignite = startGrids(2);
    assertEquals(2, ignite.cluster().topologyVersion());
    startGrid(2);
    assertEquals(3, ignite.cluster().topologyVersion());
    fail = true;
    try (IgniteClient client = Ignition.startClient(getClientConfiguration())) {
        fail();
    } catch (ClientAuthenticationException e) {
        assertTrue(e.getMessage().contains("Client version is not found"));
    }
}
Also used : GridClientAuthenticationException(org.apache.ignite.internal.client.GridClientAuthenticationException) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) IgniteClient(org.apache.ignite.client.IgniteClient) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 54 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class AdditionalSecurityCheckTest method testClientInfo.

/**
 */
@Test
public void testClientInfo() throws Exception {
    Ignite ignite = startGrids(2);
    assertEquals(2, ignite.cluster().topologyVersion());
    startGrid(2);
    assertEquals(3, ignite.cluster().topologyVersion());
    assertFalse(ignite.cluster().active());
    try (GridClient client = GridClientFactory.start(getGridClientConfiguration())) {
        assertTrue(client.connected());
        client.state().state(ACTIVE, false);
    }
    try (IgniteClient client = Ignition.startClient(getClientConfiguration())) {
        client.createCache("test_cache");
        assertEquals(1, client.cacheNames().size());
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Ignite(org.apache.ignite.Ignite) GridClient(org.apache.ignite.internal.client.GridClient) Test(org.junit.Test)

Example 55 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class MultipleSSLContextsTest method testThinClients.

/**
 * Checks that thin clients with SSL enabled can join the cluster and perform some work on it.
 *
 * @throws Exception If failed.
 */
@Test
public void testThinClients() throws Exception {
    int clientsNum = 3;
    int keysNum = 1000;
    String cacheName = "thinClientCache";
    List<IgniteClient> clients = new ArrayList<>(clientsNum);
    try {
        for (int i = 0; i < clientsNum; i++) {
            IgniteClient client = Ignition.startClient(clientConfiguration("127.0.0.1:1080" + i));
            clients.add(client);
        }
        Map<Integer, Integer> expMap = new HashMap<>();
        for (int i = 0; i < keysNum; i++) {
            int clientId = keysNum % clientsNum;
            ClientCache<Integer, Integer> cache = clients.get(clientId).getOrCreateCache(cacheName);
            cache.put(i, i);
            expMap.put(i, i);
        }
        IgniteCache<Integer, Integer> cache = grid(0).cache(cacheName);
        assertCacheContent(expMap, cache);
    } catch (ClientException ex) {
        ex.printStackTrace();
        fail("Failed to start thin Java clients: " + ex.getMessage());
    } finally {
        for (IgniteClient client : clients) client.close();
        IgniteCache cache = grid(0).cache(cacheName);
        if (cache != null)
            cache.destroy();
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) ClientException(org.apache.ignite.client.ClientException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteClient (org.apache.ignite.client.IgniteClient)106 Test (org.junit.Test)76 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)43 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)26 UUID (java.util.UUID)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Ignite (org.apache.ignite.Ignite)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 HashSet (java.util.HashSet)13 T2 (org.apache.ignite.internal.util.typedef.T2)13 Set (java.util.Set)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 List (java.util.List)10 BinaryObject (org.apache.ignite.binary.BinaryObject)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)10 GridTestUtils.assertThrowsWithCause (org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause)10 Map (java.util.Map)9 Duration (javax.cache.expiry.Duration)9 ClientCacheConfiguration (org.apache.ignite.client.ClientCacheConfiguration)9