简体   繁体   English

我怎么会出现身份验证错误,但是当我通过应用程序登录时,我能够登录

[英]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.

相关问题 我收到一个依赖项解析错误,但我无法解决这个问题 - i am getting an dependency resolution error but i'm not able to fix this 我无法登录 Tomcat Manager App - I'm not able to log in Tomcat Manager App 进入页面后为什么无法按按钮? - Why am I not able to press the buttons when I come into the page? 为什么我不能使用JavaMail(IMAP协议)连接到我的邮箱,并收到“没有身份验证失败”错误消息? - Why am I not able to connect to my mail box using JavaMail (IMAP protocol) and getting NO AUTHENTICATE failed error? 为什么在运行应用程序时出现此错误? - Why am I getting this error when I run my app? 尝试使用Selenium单击按钮时,如何得到InvalidSelectorException? - How come I am getting InvalidSelectorException when trying to click a button using Selenium? 当我在 localhost 上运行我的应用程序时,我能够在 html 上显示图像,但是当我部署到云平台时,图像显示为 404 - when I run my app on localhost am able to display images on html but when I deploy to a cloud platform am getting 404 for the images 不使用时为什么会出现SLF4J错误? - Why am I getting a SLF4J Error when I'm not using it? 我正在尝试第一次学习方法,但是在尝试编译时遇到了一个错误 - i'm trying to learn methods for the first time but i am just getting an error when trying to compile 当我通过 JUnit 和 Mockito 测试 web 应用程序时,Log4j2 出现很多错误 - When I'm testing a web app by JUnit and Mockito I get many error with Log4j2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM