简体   繁体   English

如何以与驱动程序无关的方式与 DB(SQL Server、PG)建立 SSL 连接?

[英]How to establish SSL connection with DB (SQL Server, PG), in a driver agnostic way?

I have an application that connects with a Database.我有一个与数据库连接的应用程序。 The DB could be SQL Server, PG, etc. I need to configure the application to use SSL now. DB 可以是 SQL Server、PG 等。我现在需要将应用程序配置为使用 SSL。

I am using hibernate and configuring the datasources accordingly.我正在使用休眠并相应地配置数据源。 I am using org.apache.commons.dbcp2.BasicDataSource as of now.到目前为止,我正在使用org.apache.commons.dbcp2.BasicDataSource

I understand that in order to connect to SQL Server using SSL, I need to use SQLServerDataSource .我知道为了使用 SSL 连接到 SQL Server,我需要使用SQLServerDataSource But then it would not work if someone decides to use PG database.但是如果有人决定使用 PG 数据库,它就行不通了。

Is there any way to configure the individual datasources dynamically?有没有办法动态配置单个数据源? Or is there a common datasource that I can use irrespective of the jdbc driver (mssql or pg) provided at the runtime?或者是否有一个我可以使用的通用数据源,而不管运行时提供的 jdbc 驱动程序(mssql 或 pg)如何?

Passing the JVM parameters like -Djavax.net.ssl.trustStore and -Djavax.net.ssl.trustStorePassword modifying the jdbc connection string are not an option.传递 JVM 参数如-Djavax.net.ssl.trustStore-Djavax.net.ssl.trustStorePassword修改 jdbc 连接字符串不是一个选项。

I am using Spring (mostly XML configs) to bootstrap the application.我正在使用 Spring(主要是 XML 配置)来引导应用程序。

In Spring you can replace the used data source class using profiles .在 Spring 中,您可以使用配置文件替换使用过的数据源类。

The key idea is that you can provide multiple definition of the same bean.关键思想是您可以提供同一个 bean 的多个定义。 Those definitions would be enclosed in separate <beans> element with different profile attribute.这些定义将包含在具有不同配置文件属性的单独<beans>元素中。

<beans profile="embedded-db">
    <jdbc:embedded-database id="dataSource">
        <jdbc:script location="classpath:com/bank/config/sql/schema.sql"/>
        <jdbc:script location="classpath:com/bank/config/sql/test-data.sql"/>
    </jdbc:embedded-database>
</beans>
<beans profile="sql-server">
    <!-- Configuration of you SQL Server data source -->
</beans>
<beans profile="postgresql">
    <!-- Configuration of you PostgreSQL data source -->
</beans>

When running the application the configuration property spring.profiles.active needs to be set to choose one or more of the profiles.运行应用程序时,需要设置配置属性spring.profiles.active以选择一个或多个配置文件。

Unfortunately, modern Spring documentation doesn't provide much help in setting up XML configs.不幸的是,现代 Spring 文档在设置 XML 配置方面没有提供太多帮助。 I think they are now considered legacy.我认为他们现在被认为是遗产。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 驱动程序无法使用 SSL 与 SQL 服务器建立安全连接 - The driver could not establish a secure connection to SQL Server by using SSL 如何修复“驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server 建立安全连接”错误 - How to fix " The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption" error 驱动程序无法使用安全 Sockets 层 (SSL) 加密建立与 SQL 服务器的安全连接。 如何解决这个错误? - The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. How to solve this error? JDBC SQL Server无法建立SSL连接 - JDBC SQL Server Unable to Establish SSL Connection 驱动程序无法使用安全套接字层(SSL)加密与SQL Server建立安全连接 - The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption SQL 服务器 JDBC 错误:驱动程序无法使用安全 Sockets 层 (SSL) 加密与 SQL 服务器建立安全连接 - SQL Server JDBC Error: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption SQL Server JDBC Error on Java 8: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption - SQL Server JDBC Error on Java 8: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption 驱动程序无法使用安全 Sockets 层 (SSL) 加密建立与 SQL 服务器的安全连接。 错误:“意外重新抛出” - The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "Unexpected rethrowing" 驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server 建立安全连接。 错误:“PKIX 路径构建失败: - The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "PKIX path building failed: 如何建立与mail.google.com的单向SSL连接? - How to establish a one way SSL connection to mail.google.com?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM