Grails 3.1.6 DataSource插件无法配置为处理PKI以保护数据通信

时间:2016-05-25 13:05:56

标签: grails ssl

我使用Grails 3.1.6创建了一个简单的index.gsp,其内容是通过SSL / TLS连接到Oracle 12c的嵌入式Java代码。 URL是一个调用TCPS协议的字符串,使用瘦JDBC驱动程序连接到Oracle 12c。密码,用户名,信任库路径/类型/密码,密钥库路径/类型/密码,密码套件由Java实用程序属性指定。 建立安全连接后,Grails GSP将查询数据库服务器的当前日期和时间。 这有效。

以下是我的GSP内容。

<%@ page import = "java.sql.*" %>
<%@ page import = "java.util.Properties" %>
<%
String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=jreportdbsvr)" +
        "(PORT=1525))(CONNECT_DATA=(SERVICE_NAME=sid.mydomain)))";
Driver driver = new oracle.jdbc.OracleDriver();
Properties props = new Properties();
props.setProperty("user", "username");
props.setProperty("password", "userpassword");
props.setProperty("javax.net.ssl.trustStore","H:/minh_workspace/pki/my-grails-app.jks");
props.setProperty("javax.net.ssl.trustStoreType","JKS");
props.setProperty("javax.net.ssl.trustStorePassword","my-grails-password");
props.setProperty("javax.net.ssl.keyStore","H:/minh_workspace/pki/my-grails-app.jks");
props.setProperty("javax.net.ssl.keyStoreType","JKS");
props.setProperty("javax.net.ssl.keyStorePassword","my-grails-password");
props.setProperty("oracle.net.ssl_cipher_suites", "SSL_RSA_WITH_3DES_EDE_CBC_SHA");
ResultSet rs = null;
Statement stmt = null;
Connection conn = driver.connect(url, props);
stmt = conn.createStatement();
rs = stmt.executeQuery("select sysdate from dual");
while (rs.next()) {
%>
<table>
<tr>
    <td><h3><"Current date and time from Oracle 12c : "></h3></td>
    <td><h3><%=rs.getString(1)%></h3></td>
</tr>
<%
    }
rs.close();
stmt.close();
conn.close();
%>

我已经尝试 徒劳 来配置Grails application.yml来实现上述设置,尤其是在以下环境中:development:datasource:....
方案1:

environments:
development:
    dataSource:
        dbCreate: update
        url: jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=jreportdbsvr)(PORT=1525))(CONNECT_DATA=(SERVICE_NAME=sid.mydomain)))
        properties:
        .... no specification of trust / key stores, ciphersuite ....

错误消息:

&#34; java.sql.SQLRecoverableException:IO错误:sun.security.validator.ValidatorException:PKIX路径构建失败: sun.security.provider.certpath.SunCertPathBuilderException:无法找到所请求目标的有效证书路径&#34;

注释: 显然,它正在寻找我在这种情况下故意省略的有效认证。

方案2:

environments:
development:
    dataSource:
        dbCreate: update
        url: jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=jreportdbsvr)(PORT=1525))(CONNECT_DATA=(SERVICE_NAME=sid.mydomain)))
        properties:
          javax.net.ssl.trustStore:  /local/tomcat/certificates/my-grails-app.jks
          javax.net.ssl.trustStoreType: JKS
          javax.net.ssl.trustStorePassword: my-grails-password
          javax.net.ssl.keyStore: /local/tomcat/certificates/my-grails-app.jks
          javax.net.ssl.keyStoreType: JKS
          javax.net.ssl.keyStorePassword: my-grails-password
          javax.net.ssl.ssl_cipher_suites: (SSL_RSA_WITH_3DES_EDE_CBC_SHA)

错误消息:     &#34; ........引起:org.springframework.beans.NotWritablePropertyException:无效的属性&#39; javax&#39; bean类[org.apache.tomcat.jdbc.pool.DataSource]: Bean property&#39; javax&#39;不可写或具有无效的setter方法。 setter的参数类型是否与getter的返回类型匹配?...&#34;

注释:     Grails无法识别这些属性... javax.net.ssl.trustStore

方案3:

            development:
    dataSource:
        dbCreate: update
        url: jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=jreportdbsvr)(PORT=1525))(CONNECT_DATA=(SERVICE_NAME=sid.mydomain)))
        properties:
           ......
            ssl:
              trust-store: H:/minh_workspace/pki/my-grails-app.jks
              trust-store-type: JKS
              trust-store-password: my-grails-password
              key-store: H:/minh_workspace/pki/my-grails-app.jks
              key-store-type: JKS
              key-store-password: my-grails-password
              cipher-suites: SSL_RSA_WITH_3DES_EDE_CBC_SHA

错误消息:     &#34;由以下原因引起:org.springframework.beans.NotWritablePropertyException:无效的属性&#39; ssl&#39; bean类[org.apache.tomcat.jdbc.pool.DataSource]: Bean property&#39; ssl&#39;不可写或具有无效的setter方法。你的意思是&#39; url&#39;? &#34;

评论:Grails确实识别了我指定这些属性的方式。

我的问题是我如何将index.gsp中的属性指定为application.yml或configuration.groovy?

提前致谢,

胡志明

HPCMPO

弗吉尼亚州洛顿

0 个答案:

没有答案