[英]How come I'm getting authenticate error, but when I login via the app, I am able to log in
com.microsoft.sqlserver.jdbc.SQLServerException: Failed to authenticate the user fakeaccount@gmail.com in Active Directory (Authentication=ActiveDirectoryPassword).
com.microsoft.sqlserver.jdbc.SQLServerException:无法在 Active Directory 中对用户 fakeaccount@gmail.com 进行身份验证(Authentication=ActiveDirectoryPassword)。 at com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken(SQLServerADAL4JUtils.java:62) ~[mssql-jdbc-8.4.1.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerConnection.getFedAuthToken(SQLServerConnection.java:4442) ~[mssql-jdbc-8.4.1.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerConnection.onFedAuthInfo(SQLServerConnection.java:4415) ~[mssql-jdbc-8.4.1.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken(SQLServerADAL4JUtils.java:62) ~[mssql-jdbc-8.4.1.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerConnection.getFedAuthToken(SQLServerConnection. java:4442) ~[mssql-jdbc-8.4.1.jre8.jar:na] at com.microsoft.sqlserver.jdbc.SQLServerConnection.onFedAuthInfo(SQLServerConnection.java:4415) ~[mssql-jdbc-8.4.1.jre8 .jar:na]
As Suggested by Jatin .正如Jatin所建议的那样。 You could refer to Azure Active Directory authentication document , where you could find different authentication methods and below is the sample example of connecting Azure Active Directory with MSI authentication method.
您可以参考 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));
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.