Apache Ignite JDBC(可能是 ODBC 和瘦客户端)禁用设置不会阻止 JDBC 连接或查询

问题描述 投票:0回答:1

为了禁用通过 JDBC/ODBC/瘦客户端的访问,如文档中所述,我已将 IgniteConfiguration#clientConnectorConfiguration 配置为将 odbcEnabledjdbcEnabledthinClientEnabled 设置为 false。

<property name="clientConnectorConfiguration">
<bean class="org.apache.ignite.configuration.ClientConnectorConfiguration">
    <!-- Disabling all three.. -->
    <property name="jdbcEnabled" value="false"/>
    <property name="odbcEnabled" value="false"/>
    <property name="thinClientEnabled" value="false"/>
</bean>
</property>

但是,当我尝试使用简单的 JDBC 测试程序(请参见下文)验证这一点时,尽管 JDBC 被禁用,我还是能够成功连接并执行查询...

这是一个错误吗?有谁知道还需要做什么来禁用这些?

IgniteReachabilityChecker.java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.Set;

import org.apache.ignite.IgniteJdbcThinDriver;

public class IgniteReachabilityChecker {
    private static final String IGNITE_QUERY = "SELECT count(1) FROM TEST.USER";
    private static final String IGNITE_URL = "jdbc:ignite:thin://%s";

    public static void main(String...arg) {
        if (arg == null || arg.length < 1) {
            System.out.println("Please specify server IP");
            return;
        }
        String igniteJdbcConnectUrl = String.format(IGNITE_URL, arg[0]);
        System.out.println("The Ignite jdbc connect url is " + igniteJdbcConnectUrl);
        boolean isReachable = false;
        try (
                Connection connection = DriverManager.getConnection(igniteJdbcConnectUrl);
                Statement statement = connection.createStatement();
                ResultSet rs = statement.executeQuery(IGNITE_QUERY)
                ) {
            isReachable = rs.next();
            System.out.println("Test query result is " + rs.getInt(1));
        } catch (SQLException sqlException) {
            System.out.println("Got SQL Exception reaching ignite-grid-node. Exception is : " + sqlException);
        }
        System.out.println("Is ignite-grid-node reachable (t/f) : " + isReachable);
    }
}
java jdbc odbc ignite gridgain
1个回答
0
投票

我无法重现该问题。以下代码抛出一个

JDBC connection is not allowed
异常

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

Ignition.start(cfg);

String connStr = "jdbc:ignite:thin://127.0.0.1:10800";

try (Connection conn = DriverManager.getConnection(connStr)) {
    conn.setSchema(CACHE_NAME);

    try (Statement stmt = conn.createStatement()) {
        ResultSet rs = stmt.executeQuery("SELECT 1");
        rs.next();
    }
}

确保 Ignite 正确加载配置文件。

© www.soinside.com 2019 - 2024. All rights reserved.