java 使用集成安全(Windows 身份验证)通过 JDBC 从 Linux 连接到 SQL Server?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30914061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:49:20  来源:igfitidea点击:

Connect to SQL Server from Linux via JDBC using integratedSecurity (Windows authentication)?

javasqllinuxsql-server-2008jdbc

提问by fulhamHead

Hey I am having trouble connecting to an SQL Server with Java code that is running on Linux.

嘿,我无法使用在 Linux 上运行的 Java 代码连接到 SQL Server。

If I set integratedSecurity=true, then the java code fails with the following error:

如果我设置integratedSecurity=true,则 java 代码失败并出现以下错误:

WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:b030b480-453d-4007-8151-a552150f74cd

which makes sense as there will be no sqljdbc.dllfile on Linux.

这是有道理的,因为sqljdbc.dllLinux上没有文件。

But if I set integratedSecurity=false, then I get the following error:

但是如果我设置了integratedSecurity=false,则会出现以下错误:

 com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'IT_DEV_USER'.

So does anyone know how I can connect to SQL Server with integratedSecurityset to false? (Note that I cant even connect when the Java code is running on Windows when integratedSecurityis set to false.)

那么有谁知道我如何在integratedSecurity设置为 false 的情况下连接到 SQL Server ?(请注意,当 Java 代码在 Windows 上运行时integratedSecurity设置为 false时,我什至无法连接。)

If not, is there any way I can get integratedSecurityworking on Linux?

如果没有,有什么方法可以让我integratedSecurity在 Linux 上工作?

回答by hamnix

If you want to use integrated security and using JDBC Driver 4.0 or greater then you add the following in your jdbc connection string.

如果要使用集成安全性并使用 JDBC 驱动程序 4.0 或更高版本,则在 jdbc 连接字符串中添加以下内容。

integratedSecurity=true;authenticationScheme=JavaKerberos

More information: http://blogs.msdn.com/b/psssql/archive/2015/01/09/jdbc-this-driver-is-not-configured-for-integrated-authentication.aspx

更多信息:http: //blogs.msdn.com/b/psssql/archive/2015/01/09/jdbc-this-driver-is-not-configured-for-integrated-authentication.aspx

回答by K C

Adding authenticationScheme=JavaKerberosworks for me in Linux, but make sure to remove integratedSecurity=truesince you are not using Windows.

authenticationScheme=JavaKerberos在 Linux 中添加对我有用,但请确保删除,integratedSecurity=true因为您没有使用 Windows。

回答by navin_rai

If you dont want Integrated Security connection, then set that parameter to false and instead provide user and password in the connURL as below:

如果您不需要集成安全连接,则将该参数设置为 false 并在 connURL 中提供用户和密码,如下所示:

String connectionUrl = "jdbc:sqlserver://localhost:port;databaseName=DB_NAME;integratedSecurity=false;user=login_user;password=login_pwd;";

回答by Vardan Shahinyan

You can't use integratedSecurity feature from Linux system, as it tied to windows system and uses your windows authentication. However, if you enable both SQL Server and Windows Authentication mode on your SQL Server, then you can create a login, map to corresponding database and use it in java from Linux.

您不能使用 Linux 系统的集成安全功能,因为它绑定到 Windows 系统并使用您的 Windows 身份验证。但是,如果您在 SQL Server 上同时启用 SQL Server 和 Windows 身份验证模式,那么您可以创建一个登录名,映射到相应的数据库并在 Linux 的 java 中使用它。

To enable SQL Server authentication:

要启用 SQL Server 身份验证:

  1. Right click on your server in management studio
  2. Properties
  3. Security
  4. Server authentication -> SQL Server and Windows Authentication mode
  1. 在管理工作室中右键单击您的服务器
  2. 特性
  3. 安全
  4. 服务器身份验证 -> SQL Server 和 Windows 身份验证模式