当前位置: 首页>>代码示例>>Java>>正文


Java Util.getJVMVersion方法代码示例

本文整理汇总了Java中com.mysql.jdbc.Util.getJVMVersion方法的典型用法代码示例。如果您正苦于以下问题:Java Util.getJVMVersion方法的具体用法?Java Util.getJVMVersion怎么用?Java Util.getJVMVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mysql.jdbc.Util的用法示例。


在下文中一共展示了Util.getJVMVersion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTLSVersion

import com.mysql.jdbc.Util; //导入方法依赖的package包/类
/**
 * Tests fix for WL#8196, Support for TLSv1.2 Protocol.
 * 
 * This test requires community server (with yaSSL) in -Dcom.mysql.jdbc.testsuite.url and
 * commercial server (with OpenSSL) in -Dcom.mysql.jdbc.testsuite.url.sha256default
 * 
 * Test certificates from testsuite/ssl-test-certs must be installed on both servers.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testTLSVersion() throws Exception {

    final String[] testDbUrls;
    Properties props = new Properties();
    props.setProperty("allowPublicKeyRetrieval", "true");
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("trustCertificateKeyStoreUrl", "file:src/testsuite/ssl-test-certs/ca-truststore");
    props.setProperty("trustCertificateKeyStoreType", "JKS");
    props.setProperty("trustCertificateKeyStorePassword", "password");

    if (this.sha256Conn != null && ((MySQLConnection) this.sha256Conn).versionMeetsMinimum(5, 5, 7)) {
        testDbUrls = new String[] { BaseTestCase.dbUrl, sha256Url };
    } else {
        testDbUrls = new String[] { BaseTestCase.dbUrl };
    }

    for (String testDbUrl : testDbUrls) {
        System.out.println(testDbUrl);
        System.out.println(System.getProperty("java.version"));
        Connection sslConn = getConnectionWithProps(testDbUrl, props);
        assertTrue(((MySQLConnection) sslConn).getIO().isSSLEstablished());

        ResultSet rset = sslConn.createStatement().executeQuery("SHOW STATUS LIKE 'ssl_version'");
        assertTrue(rset.next());
        String tlsVersion = rset.getString(2);
        System.out.println("TLS version: " + tlsVersion);
        System.out.println();
        System.out.println("MySQL version: " + ((MySQLConnection) sslConn).getServerVersion());
        String etp = ((MySQLConnection) sslConn).getEnabledTLSProtocols();
        System.out.println("enabledTLSProtocols: " + etp);
        System.out.println();
        System.out.println("JVM version: " + Util.getJVMVersion());
        System.out.println();

        if (((MySQLConnection) sslConn).versionMeetsMinimum(5, 7, 10) && Util.getJVMVersion() > 6) {
            if (Util.isEnterpriseEdition(((MySQLConnection) sslConn).getServerVersion())) {
                assertEquals("TLSv1.2", tlsVersion);
            } else {
                assertEquals("TLSv1.1", tlsVersion);
            }
        } else {
            assertEquals("TLSv1", tlsVersion);
        }

        sslConn.close();
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:60,代码来源:ConnectionRegressionTest.java

示例2: testEnableTLSVersion

import com.mysql.jdbc.Util; //导入方法依赖的package包/类
/**
 * Tests fix for Bug#87379. This allows TLS version to be overridden through a new configuration
 * option - enabledTLSProtocols. When set to some combination of TLSv1, TLSv1.1, or TLSv1.2 (comma-
 * separated, no spaces), the default behaviour restricting the TLS version based on JRE and MySQL
 * Server version is bypassed to enable or restrict specific TLS versions.
 * 
 * This test requires community server (with yaSSL) in -Dcom.mysql.jdbc.testsuite.url and
 * commercial server (with OpenSSL) in -Dcom.mysql.jdbc.testsuite.url.sha256default
 * 
 * Test certificates from testsuite/ssl-test-certs must be installed on both servers.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testEnableTLSVersion() throws Exception {

    final String[] testDbUrls;
    Properties props = new Properties();
    props.setProperty("allowPublicKeyRetrieval", "true");
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("trustCertificateKeyStoreUrl", "file:src/testsuite/ssl-test-certs/ca-truststore");
    props.setProperty("trustCertificateKeyStoreType", "JKS");
    props.setProperty("trustCertificateKeyStorePassword", "password");

    if (this.sha256Conn != null && ((MySQLConnection) this.sha256Conn).versionMeetsMinimum(5, 5, 7)) {
        testDbUrls = new String[] { BaseTestCase.dbUrl, sha256Url };
    } else {
        testDbUrls = new String[] { BaseTestCase.dbUrl };
    }

    for (String testDbUrl : testDbUrls) {
        System.out.println(testDbUrl);
        System.out.println(System.getProperty("java.version"));
        Connection sslConn = getConnectionWithProps(testDbUrl, props);
        assertTrue(((MySQLConnection) sslConn).getIO().isSSLEstablished());
        List<String> expectedProtocols = new ArrayList<String>();
        expectedProtocols.add("TLSv1");
        if (Util.getJVMVersion() > 6 && ((MySQLConnection) sslConn).versionMeetsMinimum(5, 7, 10)) {
            ResultSet rs1 = sslConn.createStatement().executeQuery("SELECT @@global.tls_version");
            assertTrue(rs1.next());
            String supportedTLSVersions = rs1.getString(1);
            System.out.println("Server reported TLS version support: " + supportedTLSVersions);
            expectedProtocols.addAll(Arrays.asList(supportedTLSVersions.split("\\s*,\\s*")));
        }

        String[] testingProtocols = { "TLSv1.2", "TLSv1.1", "TLSv1" };
        for (String protocol : testingProtocols) {
            Properties testProps = new Properties();
            testProps.putAll(props);
            testProps.put("enabledTLSProtocols", protocol);
            System.out.println("Testing " + protocol + " expecting connection: " + expectedProtocols.contains(protocol));
            try {
                Connection tlsConn = getConnectionWithProps(testDbUrl, testProps);
                if (!expectedProtocols.contains(protocol)) {
                    fail("Expected to fail connection with " + protocol + " due to lack of server support.");
                }
                ResultSet rset = tlsConn.createStatement().executeQuery("SHOW STATUS LIKE 'ssl_version'");
                assertTrue(rset.next());
                String tlsVersion = rset.getString(2);
                assertEquals(protocol, tlsVersion);
                tlsConn.close();
            } catch (Exception e) {
                if (expectedProtocols.contains(protocol)) {
                    e.printStackTrace();
                    fail("Expected to be able to connect with " + protocol + " protocol, but failed.");
                }
            }
        }
        sslConn.close();
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:73,代码来源:ConnectionRegressionTest.java

示例3: testTLSVersion

import com.mysql.jdbc.Util; //导入方法依赖的package包/类
/**
 * Tests fix for WL#8196, Support for TLSv1.2 Protocol.
 * 
 * This test requires community server (with yaSSL) in -Dcom.mysql.jdbc.testsuite.url and
 * commercial server (with OpenSSL) in -Dcom.mysql.jdbc.testsuite.url.sha256default
 * 
 * Test certificates from testsuite/ssl-test-certs must be installed on both servers.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testTLSVersion() throws Exception {

    final String[] testDbUrls;
    Properties props = new Properties();
    props.setProperty("allowPublicKeyRetrieval", "true");
    props.setProperty("useSSL", "true");
    props.setProperty("requireSSL", "true");
    props.setProperty("trustCertificateKeyStoreUrl", "file:src/testsuite/ssl-test-certs/ca-truststore");
    props.setProperty("trustCertificateKeyStoreType", "JKS");
    props.setProperty("trustCertificateKeyStorePassword", "password");

    if (this.sha256Conn != null && ((MySQLConnection) this.sha256Conn).versionMeetsMinimum(5, 5, 7)) {
        testDbUrls = new String[] { BaseTestCase.dbUrl, sha256Url };
    } else {
        testDbUrls = new String[] { BaseTestCase.dbUrl };
    }

    for (String testDbUrl : testDbUrls) {
        System.out.println(testDbUrl);
        System.out.println(System.getProperty("java.version"));
        Connection sslConn = getConnectionWithProps(testDbUrl, props);
        assertTrue(((MySQLConnection) sslConn).getIO().isSSLEstablished());

        ResultSet rset = sslConn.createStatement().executeQuery("SHOW STATUS LIKE 'ssl_version'");
        assertTrue(rset.next());
        String tlsVersion = rset.getString(2);
        System.out.println(tlsVersion);
        System.out.println();

        if (((MySQLConnection) sslConn).versionMeetsMinimum(5, 7, 10) && Util.getJVMVersion() > 6) {
            if (Util.isEnterpriseEdition(((MySQLConnection) sslConn).getServerVersion())) {
                assertEquals("TLSv1.2", tlsVersion);
            } else {
                assertEquals("TLSv1.1", tlsVersion);
            }
        } else {
            assertEquals("TLSv1", tlsVersion);
        }

        sslConn.close();
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:54,代码来源:ConnectionRegressionTest.java


注:本文中的com.mysql.jdbc.Util.getJVMVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。