为什么我收到身份验证错误,但是当我通过应用程序登录时,我可以登录



com.microsoft.sqlserver.jdbc.SQLServerException:未能验证用户fakeaccount@gmail.com在Active Directory中(身份验证=ActiveDirectoryPassword(。在com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken(SQLServerADAL4JUtils.java:62(~[mssql-jdbc-8.4.1.jre8.jar:na]com.microsoft.sqlserver.jdbc.SQLServerConnection.getFedAuthToken(SQLServerConnection.java:4442(~[mssql-jdbc-8.4.1.jre8.jar:na]com.microsoft.sqlserver.jdbc.SQLServerConnection.onFedAuthInfo(SQLServerConnection.java:4115(~[mssql-jdbc-8.4.1.jre8.jar:na]

Jatin建议。你可以参考Azure Active Directory身份验证文档,在那里你可以找到不同的身份验证方法,下面是将Azure Active Directory与MSI身份验证方法连接的示例。

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
public class AAD_MSI {
public static void main(String[] args) throws Exception {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName("aad-managed-demo.database.windows.net"); // Replace with your server name
ds.setDatabaseName("demo"); // Replace with your database name
ds.setAuthentication("ActiveDirectoryMSI");
// Optional
ds.setMSIClientId("94de34e9-8e8c-470a-96df-08110924b814"); // Replace with Client ID of User-Assigned Managed Identity to be used
try (Connection connection = ds.getConnection();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT SUSER_SNAME()")) {
if (rs.next()) {
System.out.println("You have successfully logged on as: " + rs.getString(1));
}
}
}
}

相关内容

最新更新