Search in sources :

Example 41 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class SecurityTest method testUserCannotCreateUser.

/**
 * Test user cannot create user.
 */
@Test
public void testUserCannotCreateUser() throws Exception {
    final String USER = "joe";
    final String PWD = "password";
    try (Ignite ignored = igniteWithAuthentication(new SimpleEntry<>(USER, PWD));
        IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER).setUserName(USER).setUserPassword(PWD))) {
        Exception authError = null;
        try {
            client.query(new SqlFieldsQuery(String.format("CREATE USER \"%s\" WITH PASSWORD '%s'", "joe2", "password"))).getAll();
        } catch (Exception e) {
            authError = e;
        }
        assertNotNull("User created another user", authError);
    }
}
Also used : Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) IgniteClientException(org.apache.ignite.internal.processors.platform.client.IgniteClientException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ExecutionException(java.util.concurrent.ExecutionException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Test(org.junit.Test)

Example 42 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class SecurityTest method testEncryption.

/**
 * Test SSL/TLS encryption.
 */
@Test
public void testEncryption() throws Exception {
    // Server-side security configuration
    IgniteConfiguration srvCfg = Config.getServerConfiguration();
    SslContextFactory sslCfg = new SslContextFactory();
    Function<String, String> rsrcPath = rsrc -> Paths.get(IGNITE_HOME == null ? "." : IGNITE_HOME, "modules", "core", "src", "test", "resources", rsrc).toString();
    sslCfg.setKeyStoreFilePath(rsrcPath.apply("/server.jks"));
    sslCfg.setKeyStorePassword("123456".toCharArray());
    sslCfg.setTrustStoreFilePath(rsrcPath.apply("/trust.jks"));
    sslCfg.setTrustStorePassword("123456".toCharArray());
    srvCfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setSslEnabled(true).setSslClientAuth(true));
    srvCfg.setSslContextFactory(sslCfg);
    // Client-side security configuration
    ClientConfiguration clientCfg = new ClientConfiguration().setAddresses(Config.SERVER);
    try (Ignite ignored = Ignition.start(srvCfg)) {
        boolean failed;
        try (IgniteClient client = Ignition.startClient(clientCfg)) {
            client.<Integer, String>cache(Config.DEFAULT_CACHE_NAME).put(1, "1");
            failed = false;
        } catch (Exception ex) {
            failed = true;
        }
        assertTrue("Client connection without SSL must fail", failed);
        // Not using user-supplied SSL Context Factory:
        try (IgniteClient client = Ignition.startClient(clientCfg.setSslMode(SslMode.REQUIRED).setSslClientCertificateKeyStorePath(rsrcPath.apply("/client.jks")).setSslClientCertificateKeyStoreType(DFLT_STORE_TYPE).setSslClientCertificateKeyStorePassword("123456").setSslTrustCertificateKeyStorePath(rsrcPath.apply("/trust.jks")).setSslTrustCertificateKeyStoreType(DFLT_STORE_TYPE).setSslTrustCertificateKeyStorePassword("123456").setSslKeyAlgorithm(DFLT_KEY_ALGORITHM).setSslTrustAll(false).setSslProtocol(SslProtocol.TLS))) {
            client.<Integer, String>cache(Config.DEFAULT_CACHE_NAME).put(1, "1");
        }
        // Using user-supplied SSL Context Factory
        try (IgniteClient client = Ignition.startClient(clientCfg.setSslMode(SslMode.REQUIRED).setSslContextFactory(sslCfg))) {
            client.<Integer, String>cache(Config.DEFAULT_CACHE_NAME).put(1, "1");
        }
    }
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) U(org.apache.ignite.internal.util.typedef.internal.U) DFLT_STORE_TYPE(org.apache.ignite.ssl.SslContextFactory.DFLT_STORE_TYPE) Function(java.util.function.Function) SslContextFactory(org.apache.ignite.ssl.SslContextFactory) Timeout(org.junit.rules.Timeout) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) SimpleEntry(java.util.AbstractMap.SimpleEntry) Before(org.junit.Before) IgniteClientException(org.apache.ignite.internal.processors.platform.client.IgniteClientException) Assert.assertNotNull(org.junit.Assert.assertNotNull) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DFLT_KEY_ALGORITHM(org.apache.ignite.ssl.SslContextFactory.DFLT_KEY_ALGORITHM) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) Rule(org.junit.Rule) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Paths(java.nio.file.Paths) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) SslContextFactory(org.apache.ignite.ssl.SslContextFactory) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) IgniteClientException(org.apache.ignite.internal.processors.platform.client.IgniteClientException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 43 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class SecurityTest method testValidUserAuthentication.

/**
 * Test valid user authentication.
 */
@Test
public void testValidUserAuthentication() throws Exception {
    final String USER = "joe";
    final String PWD = "password";
    try (Ignite ignored = igniteWithAuthentication(new SimpleEntry<>(USER, PWD));
        IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER).setUserName(USER).setUserPassword(PWD))) {
        client.getOrCreateCache("testAuthentication");
    }
}
Also used : Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Example 44 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class IgniteBinaryQueryTest method testBinaryQueries.

/**
 * Test queries in Ignite binary.
 */
@Test
public void testBinaryQueries() throws Exception {
    try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
        IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
        final String TYPE_NAME = "Person";
        QueryEntity qryPerson = new QueryEntity().setKeyType(Integer.class.getName()).setValueType(TYPE_NAME).setFields(Stream.of(new SimpleEntry<>("id", Integer.class.getName()), new SimpleEntry<>("name", String.class.getName())).collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue, (a, b) -> a, LinkedHashMap::new))).setIndexes(Collections.singletonList(new QueryIndex("id")));
        ClientCacheConfiguration cacheCfg = new ClientCacheConfiguration().setName("testBinaryQueries").setQueryEntities(qryPerson);
        ClientCache<Integer, BinaryObject> cache = client.getOrCreateCache(cacheCfg).withKeepBinary();
        final IgniteBinary binary = client.binary();
        Map<Integer, BinaryObject> data = IntStream.range(0, 100).boxed().collect(Collectors.toMap(i -> i, i -> binary.builder(TYPE_NAME).setField("id", i, int.class).setField("name", String.format("Person %s", i), String.class).build()));
        cache.putAll(data);
        Cache.Entry<Integer, BinaryObject> p1 = cache.query(new SqlQuery<Integer, BinaryObject>(TYPE_NAME, "id = 1")).getAll().iterator().next();
        assertEquals(Integer.valueOf(1), p1.getKey());
        assertBinaryObjectsEqual(data.get(1), p1.getValue());
    }
}
Also used : IntStream(java.util.stream.IntStream) BinaryObject(org.apache.ignite.binary.BinaryObject) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) LinkedHashMap(java.util.LinkedHashMap) Stream(java.util.stream.Stream) Ignition(org.apache.ignite.Ignition) BinaryType(org.apache.ignite.binary.BinaryType) Rule(org.junit.Rule) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Map(java.util.Map) SqlQuery(org.apache.ignite.cache.query.SqlQuery) Cache(javax.cache.Cache) Timeout(org.junit.rules.Timeout) IgniteBinary(org.apache.ignite.IgniteBinary) QueryEntity(org.apache.ignite.cache.QueryEntity) SimpleEntry(java.util.AbstractMap.SimpleEntry) Collections(java.util.Collections) QueryIndex(org.apache.ignite.cache.QueryIndex) Assert.assertEquals(org.junit.Assert.assertEquals) SqlQuery(org.apache.ignite.cache.query.SqlQuery) SimpleEntry(java.util.AbstractMap.SimpleEntry) QueryEntity(org.apache.ignite.cache.QueryEntity) IgniteBinary(org.apache.ignite.IgniteBinary) BinaryObject(org.apache.ignite.binary.BinaryObject) QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 45 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class PerformanceStatisticsQueryTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();
    stopAllGrids();
    cleanPersistenceDir();
    srv = startGrids(2);
    thinClient = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER));
    client = startClientGrid("client");
    client.cluster().state(ACTIVE);
    cache = client.getOrCreateCache(new CacheConfiguration<Integer, Integer>().setName(DEFAULT_CACHE_NAME).setSqlSchema(DFLT_SCHEMA).setQueryEntities(Collections.singletonList(new QueryEntity(Integer.class, Integer.class).setTableName(DEFAULT_CACHE_NAME))));
    IgniteCache<Object, Object> cache2 = client.getOrCreateCache(new CacheConfiguration<>().setName(CACHE_2).setSqlSchema(DFLT_SCHEMA).setQueryEntities(Collections.singletonList(new QueryEntity(Long.class, Long.class).setTableName(CACHE_2))));
    for (int i = 0; i < ENTRY_COUNT; i++) {
        cache.put(i, i);
        cache2.put(i, i * 2);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryEntity(org.apache.ignite.cache.QueryEntity) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)83 Test (org.junit.Test)44 IgniteClient (org.apache.ignite.client.IgniteClient)42 Ignite (org.apache.ignite.Ignite)28 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)23 BinaryObject (org.apache.ignite.binary.BinaryObject)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 List (java.util.List)11 Ignition (org.apache.ignite.Ignition)10 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)9 Collections (java.util.Collections)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 IgniteBinary (org.apache.ignite.IgniteBinary)7 Connection (java.sql.Connection)6 Arrays (java.util.Arrays)6 Map (java.util.Map)6 Consumer (java.util.function.Consumer)6 ScanQuery (org.apache.ignite.cache.query.ScanQuery)6