【发布时间】:2021-11-30 17:49:30
【问题描述】:
我在尝试使用 JDBC 和 authentication=ActiveDirectoryPassword 连接到 Azure Synapse DB 时遇到问题。
我正在使用 Java 8 进行开发。以下是我正在使用的 pom 依赖项:
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.4.0.jre8</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.11.0</version>
</dependency>
</dependencies>
这是我用来连接 Synapse DB 的代码:
SQLServerDataSource sqlServerDataSource = new SQLServerDataSource();
sqlServerDataSource.setServerName("someserver.database.windows.net");
sqlServerDataSource.setDatabaseName("somedbname");
sqlServerDataSource.setUser("someuser@some.com");
sqlServerDataSource.setPassword("somepwd");
sqlServerDataSource.setAuthentication("ActiveDirectoryPassword");
sqlServerDataSource.setEncrypt(true);
sqlServerDataSource.setTrustServerCertificate(true);
sqlServerDataSource.setUseBulkCopyForBatchInsert(true);
Connection connection = sqlServerDataSource.getConnection();
这是我为上述代码引用的 MSFT 链接:
问题是,对sqlServerDataSource.getConnection() 的调用失败并出现以下错误:
com.microsoft.sqlserver.jdbc.SQLServerException: Failed to authenticate the user someuser@some.com in Active Directory (Authentication=ActiveDirectoryPassword). javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.microsoft.sqlserver.jdbc.SQLServerMSAL4JUtils.getCorrectedException(SQLServerMSAL4JUtils.java:228)
at com.microsoft.sqlserver.jdbc.SQLServerMSAL4JUtils.getSqlFedAuthToken(SQLServerMSAL4JUtils.java:65)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getFedAuthToken(SQLServerConnection.java:4751)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.onFedAuthInfo(SQLServerConnection.java:4724)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.processFedAuthInfo(SQLServerConnection.java:4680)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onFedAuthInfo(tdsparser.java:289)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:125)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:37)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:5560)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:4289)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:88)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:4227)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7417)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3488)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2978)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2628)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:2471)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1470)
at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnectionInternal(SQLServerDataSource.java:1317)
at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnection(SQLServerDataSource.java:100)
我不确定除了上面提到的 2 之外我是否需要任何其他依赖项。
如果有人遇到过类似的问题并愿意分享他们的解决方案,那真的很有帮助。
提前致谢。
【问题讨论】:
标签: maven jdbc java-8 azure-active-directory azure-synapse