首页 > 解决方案 > Spring Boot:通过 Active Directory 用户连接到 MSSQL

问题描述

我喜欢将 Spring Boot 应用程序部署到 K8s 集群并连接到 MSSQL 数据库。驱动定义为:

spring.datasource.driverClassName=net.sourceforge.jtds.jdbc.Driver

目前,我通过数据库本身实现的用户进行连接。这是连接字符串:

datasourceUrl: jdbc:jtds:sqlserver://server-host/db-name;instance=MSSQL

现在,我想使用 Actice Directory 用户。因此,我更新了凭据。然后,无法再建立连接。一些研究表明,向连接字符串添加domain=domain-nameintegratedSecurity=true应该启用连接。不幸的是,两者都不起作用。

使用domain=domain-name导致:

登录来自不受信任的域,不能用于 Windows 身份验证

使用integratedSecurity=true导致:

ConfigServletWebServerApplicationContext:上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源 [org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfiguration$ 中定义名称为“jdbcConverter”的 bean 创建错误SpringBootJdbcConfiguration.class]:通过方法'jdbcConverter'参数4表示的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfiguration$SpringBootJdbcConfiguration.class] 中定义名称为“jdbcDialect”的 bean 创建时出错:通过工厂进行 Bean 实例化方法失败;嵌套异常是 org.springframework.beans。BeanInstantiationException:无法实例化[org.springframework.data.relational.core.dialect.Dialect]:工厂方法'jdbcDialect'抛出异常;嵌套异常是 org.springframework.jdbc.CannotGetJdbcConnectionException: 获取 JDBC 连接失败;嵌套异常是 java.sql.SQLException: Login failed for user 'ad-username'

关于如何通过 Active Directory 用户建立与 MSSQL 数据库的连接的任何想法?

标签: sql-serverspringspring-bootactive-directory

解决方案


谢谢丹·古兹曼的评论。

还有另一种方法,您可以通过将 Active Directory 用户组添加为登录名来通过 Active Directory 用户建立与 MSSQL 数据库的连接。它描述了如何使用 SQL Server Management Studio 或 Transact-SQL 在 SQL Server 或 SQL 数据库中创建登录。登录名是连接到 SQL Server 实例的人员或进程的身份。

请参考这里讨论过的这个 MS Q&A:https ://docs.microsoft.com/en-us/answers/questions/131424/how-to-add-active-directory-user-group-as-login-在.html

https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-login?view=sql-server-ver15


推荐阅读