Java Code Examples for org.apache.ignite.configuration.IgniteConfiguration#setClientConnectorConfiguration()

The following examples show how to use org.apache.ignite.configuration.IgniteConfiguration#setClientConnectorConfiguration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientConnectorConfigurationValidationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Test SQL connector conversion.
 *
 * @throws Exception If failed.
 */
@Test
public void testIgnoreOdbcAndSqlWhenClientSet() throws Exception {
    int cliPort = ClientConnectorConfiguration.DFLT_PORT - 1;
    int sqlPort = ClientConnectorConfiguration.DFLT_PORT - 2;
    int odbcPort = ClientConnectorConfiguration.DFLT_PORT - 3;

    IgniteConfiguration cfg = baseConfiguration();

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setPort(cliPort));
    cfg.setSqlConnectorConfiguration(new SqlConnectorConfiguration().setPort(sqlPort));
    cfg.setOdbcConfiguration(new OdbcConfiguration().setEndpointAddress("127.0.0.1:" + odbcPort));

    Ignition.start(cfg);

    checkJdbc(null, cliPort);
}
 
Example 2
Source File: MultipleSSLContextsTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration igniteCfg = super.getConfiguration(igniteInstanceName);

    if (clientMode) {
        igniteCfg.setClientMode(true);

        igniteCfg.setSslContextFactory(clientSSLFactory());
    }
    else
        igniteCfg.setSslContextFactory(serverSSLFactory());

    ClientConnectorConfiguration clientConnectorCfg = new ClientConnectorConfiguration()
        .setSslEnabled(true)
        .setSslClientAuth(true)
        .setUseIgniteSslContextFactory(false)
        .setSslContextFactory(clientConnectorSSLFactory());
    igniteCfg.setClientConnectorConfiguration(clientConnectorCfg);

    ConnectorConfiguration connectorConfiguration = new ConnectorConfiguration()
        .setSslEnabled(true)
        .setSslFactory(connectorSSLFactory());
    igniteCfg.setConnectorConfiguration(connectorConfiguration);

    return igniteCfg;
}
 
Example 3
Source File: ClientConnectorConfigurationValidationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Test disabled client.
 *
 * @throws Exception If failed.
 */
@Test
public void testDisabled() throws Exception {
    IgniteConfiguration cfg = baseConfiguration();

    cfg.setClientConnectorConfiguration(null);

    Ignition.start(cfg);

    GridTestUtils.assertThrows(log, new Callable<Void>() {
        @Override public Void call() throws Exception {
            checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT);

            return null;
        }
    }, SQLException.class, null);
}
 
Example 4
Source File: JdbcThinStatementCancelSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<?,?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setSqlFunctionClasses(TestSQLFunctions.class);
    cache.setIndexedTypes(Integer.class, Integer.class, Long.class, Long.class, String.class,
        JdbcThinAbstractDmlStatementSelfTest.Person.class);

    cfg.setCacheConfiguration(cache);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(disco);

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().
        setThreadPoolSize(SERVER_THREAD_POOL_SIZE));

    return cfg;
}
 
Example 5
Source File: ClientConnectorConfigurationValidationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if JDBC connection disabled and others are enabled, JDBC doesn't work.
 *
 * @throws Exception If failed.
 */
@Test
public void testJdbcConnectionDisabled() throws Exception {
    IgniteConfiguration cfg = baseConfiguration();

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration()
        .setJdbcEnabled(false)
        .setOdbcEnabled(true)
        .setThinClientEnabled(true));

    Ignition.start(cfg);

    GridTestUtils.assertThrows(log, new Callable<Void>() {
        @Override public Void call() throws Exception {
            checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT);

            return null;
        }
    }, SQLException.class, "JDBC connection is not allowed, see ClientConnectorConfiguration.jdbcEnabled");
}
 
Example 6
Source File: ClientConnectorConfigurationValidationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 *  Checks if JDBC connection disabled for daemon node.
 *
 * @throws Exception If failed.
 */
@Test
public void testJdbcConnectionDisabledForDaemon() throws Exception {
    final IgniteConfiguration cfg = baseConfiguration().setDaemon(true);

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration()
        .setJdbcEnabled(true)
        .setThinClientEnabled(true));

    Ignition.start(cfg);

    GridTestUtils.assertThrows(log, new Callable<Void>() {
        @Override public Void call() throws Exception {
            checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT);
            return null;
        }
    }, SQLException.class, "Failed to connect");
}
 
Example 7
Source File: ClientConnectorConfigurationValidationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Perform check.
 *
 * @param cliConnCfg Client connector configuration.
 * @param success Success flag. * @throws Exception If failed.
 */
private void check(ClientConnectorConfiguration cliConnCfg, boolean success) throws Exception {
    final IgniteConfiguration cfg = baseConfiguration();

    cfg.setClientConnectorConfiguration(cliConnCfg);

    if (success)
        startGrid(cfg.getIgniteInstanceName(), cfg);
    else {
        GridTestUtils.assertThrows(log, new Callable<Void>() {
            @Override public Void call() throws Exception {
                startGrid(cfg.getIgniteInstanceName(), cfg);

                return null;
            }
        }, IgniteException.class, null);
    }
}
 
Example 8
Source File: JdbcThinConnectionSSLTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setMarshaller(new BinaryMarshaller());

    cfg.setClientConnectorConfiguration(
        new ClientConnectorConfiguration()
            .setSslEnabled(true)
            .setUseIgniteSslContextFactory(setSslCtxFactoryToIgnite)
            .setSslClientAuth(true)
            .setSslContextFactory(setSslCtxFactoryToCli ? sslCtxFactory : null));

    cfg.setSslContextFactory(setSslCtxFactoryToIgnite ? sslCtxFactory : null);

    return cfg;
}
 
Example 9
Source File: JdbcThinConnectionAdditionalSecurityTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setMarshaller(new BinaryMarshaller());

    cfg.setPluginProviders(new TestAdditionalSecurityPluginProvider("srv_" + igniteInstanceName, null, ALLOW_ALL,
        false, true, clientData()));

    cfg.setClientConnectorConfiguration(
        new ClientConnectorConfiguration()
            .setSslEnabled(true)
            .setUseIgniteSslContextFactory(setSslCtxFactoryToIgnite)
            .setSslClientAuth(true)
            .setSslContextFactory(setSslCtxFactoryToCli ? sslCtxFactory : null));

    cfg.setSslContextFactory(setSslCtxFactoryToIgnite ? sslCtxFactory : null);

    return cfg;
}
 
Example 10
Source File: CommonSecurityCheckTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param instanceName Instance name.
 */
@Override protected IgniteConfiguration getConfiguration(String instanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(instanceName);

    cfg.setActiveOnStart(false);

    boolean isClient = instanceName.endsWith("2");
    String name = isClient ? "client_" + instanceName : "srv_" + instanceName;

    cfg.setPluginProviders(getPluginProvider(name));

    SslContextFactory sslFactory = (SslContextFactory) GridTestUtils.sslFactory();

    cfg.setSslContextFactory(sslFactory);
    cfg.setConnectorConfiguration(new ConnectorConfiguration()
        .setSslEnabled(true)
        .setSslClientAuth(true)
        .setSslClientAuth(true)
        .setSslFactory(sslFactory));

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration()
        .setSslEnabled(true)
        .setSslClientAuth(true)
        .setUseIgniteSslContextFactory(false)
        .setSslContextFactory(sslFactory));

    if (instanceName.endsWith("0"))
        cfg.setGridLogger(listeningLog);

    if (isClient)
        cfg.setClientMode(true);

    if (!fail) {
        Map<String, String> attrs = new UserAttributesFactory().create();

        cfg.setUserAttributes(attrs);
    }

    return cfg;
}
 
Example 11
Source File: LocalIgniteCluster.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
private static IgniteConfiguration getConfiguration(NodeConfiguration nodeCfg) {
    IgniteConfiguration igniteCfg = Config.getServerConfiguration();

    igniteCfg.setClientConnectorConfiguration(new ClientConnectorConfiguration()
        .setHost(HOST)
        .setPort(nodeCfg.getClientPort())
    );

    return igniteCfg;
}
 
Example 12
Source File: JdbcThinConnectionMultipleAddressesTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override protected IgniteConfiguration getConfiguration(String name) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(name);

    cfg.setCacheConfiguration(cacheConfiguration(DEFAULT_CACHE_NAME));

    cfg.setMarshaller(new BinaryMarshaller());

    cfg.setClientConnectorConfiguration(
        new ClientConnectorConfiguration()
            .setPort(jdbcPorts.get(getTestIgniteInstanceIndex(name))));

    return cfg;
}
 
Example 13
Source File: ClientConnectorConfigurationValidationSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if JDBC connection enabled and others are disabled, JDBC still works.
 *
 * @throws Exception If failed.
 */
@Test
public void testJdbcConnectionEnabled() throws Exception {
    IgniteConfiguration cfg = baseConfiguration();

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration()
        .setJdbcEnabled(true)
        .setOdbcEnabled(false)
        .setThinClientEnabled(false));

    Ignition.start(cfg);

    checkJdbc(null, ClientConnectorConfiguration.DFLT_PORT);
}
 
Example 14
Source File: ClientConnectorConfigurationValidationSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Test SQL connector conversion.
 *
 * @throws Exception If failed.
 */
@Test
public void testIgnoreSqlWhenClientSet() throws Exception {
    int cliPort = ClientConnectorConfiguration.DFLT_PORT - 1;
    int sqlPort = ClientConnectorConfiguration.DFLT_PORT - 2;

    IgniteConfiguration cfg = baseConfiguration();

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setPort(cliPort));
    cfg.setSqlConnectorConfiguration(new SqlConnectorConfiguration().setPort(sqlPort));

    Ignition.start(cfg);

    checkJdbc(null, cliPort);
}
 
Example 15
Source File: ClientConnectorConfigurationValidationSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Test SQL connector conversion.
 *
 * @throws Exception If failed.
 */
@Test
public void testIgnoreOdbcWhenClientSet() throws Exception {
    int cliPort = ClientConnectorConfiguration.DFLT_PORT - 1;
    int odbcPort = ClientConnectorConfiguration.DFLT_PORT - 2;

    IgniteConfiguration cfg = baseConfiguration();

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setPort(cliPort));
    cfg.setOdbcConfiguration(new OdbcConfiguration().setEndpointAddress("127.0.0.1:" + odbcPort));

    Ignition.start(cfg);

    checkJdbc(null, cliPort);
}
 
Example 16
Source File: JdbcThinStatementTimeoutSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<?,?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setSqlFunctionClasses(TestSQLFunctions.class);
    cache.setIndexedTypes(Integer.class, Integer.class, Long.class, Long.class, String.class,
        JdbcThinAbstractDmlStatementSelfTest.Person.class);

    cfg.setCacheConfiguration(cache);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(disco);

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setThreadPoolSize(SERVER_THREAD_POOL_SIZE));

    return cfg;
}
 
Example 17
Source File: JdbcThinConnectionTimeoutSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<?, ?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setSqlFunctionClasses(JdbcThinConnectionTimeoutSelfTest.class);
    cache.setIndexedTypes(Integer.class, Integer.class);

    cfg.setCacheConfiguration(cache);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    cfg.setDiscoverySpi(disco);

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setThreadPoolSize(SERVER_THREAD_POOL_SIZE));

    return cfg;
}
 
Example 18
Source File: SslParametersTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration()
        .setSslEnabled(true)
        .setUseIgniteSslContextFactory(true));

    cfg.setSslContextFactory(createSslFactory());

    CacheConfiguration ccfg = new CacheConfiguration(TEST_CACHE_NAME);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 19
Source File: SecurityTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** 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("JKS")
            .setSslClientCertificateKeyStorePassword("123456")
            .setSslTrustCertificateKeyStorePath(rsrcPath.apply("/trust.jks"))
            .setSslTrustCertificateKeyStoreType("JKS")
            .setSslTrustCertificateKeyStorePassword("123456")
            .setSslKeyAlgorithm("SunX509")
            .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");
        }
    }
}
 
Example 20
Source File: JdbcThinSelectAfterAlterTable.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setCacheConfiguration(cacheConfiguration(DEFAULT_CACHE_NAME));

    cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setPort(cliPort++));

    return cfg;
}