gpt4 book ai didi

ruby-on-rails - 如何为 Jruby Oracle 连接设置 SSL?

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:57 25 4
gpt4 key购买 nike

在 Rails、Jruby 等中。我创建了一个功能调用,用于在网页中查询 Oracle 数据库。我需要在 SSL 中保护该功能调用。

<%
require 'jdbc_connection'

# Database settings
user = "***REMOVED***"
passwd = "***REMOVED***"
url = "jdbc:oracle:thin:@***REMOVED***:1521/test"
output = ""
error = ""

select_stmt, rest, select_sql = nil
error = "No Errors."
begin
conn = OracleConnection.create(user, passwd, url)
select_sql = "select columnA from test.tableA WHERE name='"+@subject["name"].first+"'"
select_stmt = conn.create_statement
rset = select_stmt.execute_query select_sql
while (rset.next)
output = output + rset.getString(1)
end

rescue
error = "Failed executing Oracle demo from JRuby ", $!, "\n"

ensure
# We have to ensure everything is closed here.
if (!select_stmt.nil?)
select_stmt.close
end
if (!rset.nil?)
rset.close
end
conn.close_connection
end
%>

我想我需要对 keystore 、用户名、密码和连接字符串的引用。

我在这个网站上找到了一个示例连接字符串:https://blogs.oracle.com/dev2dev/ssl-connection-to-oracle-db-using-jdbc,-tlsv12,-jks-or-oracle-wallets

DB_USER = "hr", DB_PASSWORD ="hr", and 
DB_URL = "jdbc:oracle:thin:@(DESCRIPTION= (ADDRESS=
(PROTOCOL=TCPS)(PORT=1522)(HOST=myhost))
(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename))
(SECURITY=(ssl_server_cert_dn="CN=testcert.oracle.com, O=Oracle Corporation,L=Redwood City,ST=California,C=US")))"

我在哪里引用 keystore ?我觉得 OracleConnection 类应该类似于 OracleConnectionSSL?

最佳答案

抱歉,这只是回答的一半 - 我对 JRuby 了解不多,但从 Oracle 方面来看 - this Oracle PDF describes how to set up SSL with the Oracle JDBC Thin driver .您可能想要阅读全部内容,但这是他们使用 JKS keystore 的 Java 示例(对于 Oracle Wallets 略有不同):

String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps(HOST=servername)(PORT=2484))(CONNECT_DATA=(SERVICE_NAME=servicename))))";
Properties props = new Properties();
props.setProperty("user", "scott");
props.setProperty("password", "tiger");
props.setProperty("javax.net.ssl.keyStore",
"D:\\client_jks\\keystore.jks");
props.setProperty("javax.net.ssl.keyStoreType","JKS");
props.setProperty("javax.net.ssl.keyStorePassword","welcome123");
Connection conn = DriverManager.getConnection(url, props);

您看到它在调用 DriverManager.getConnection 之前如何设置 Java 属性了吗?我认为这需要在您的 jdbc_connection 界面中进行相同的 getConnection 调用。但我对 Ruby 不够熟悉,不知道该怎么做。

关于ruby-on-rails - 如何为 Jruby Oracle 连接设置 SSL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55008333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com