【问题标题】:Spring Boot: Connect to MSSQL by means of an Active Directory userSpring Boot:通过 Active Directory 用户连接到 MSSQL
【发布时间】:2021-11-20 19:45:31
【问题描述】:

我喜欢将 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$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 数据库的连接的任何想法?

【问题讨论】:

  • 我不相信jtds驱动支持AD认证。 Microsoft JDBC 驱动程序允许 AD 身份验证,但有一个 number of prerequisites 可能来自容器的问题。
  • 您好 Jan,如果我的回答对您有帮助,您可以接受它作为答案(单击答案旁边的复选标记,将其从灰色切换为已填充。)。这对其他社区成员可能是有益的。谢谢

标签: sql-server spring spring-boot active-directory


【解决方案1】:

感谢Dan Guzman 的评论。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多