通过JDBC从Linux机器上使用Windows身份验证连接到SQL Server

时间:2022-09-09 01:44:39

I want to be able to connect to a SQL Server using jdbc and windows authentication. I saw some answers on the internet saying i should add the following property to the connection string:

我希望能够使用jdbc和windows身份验证连接到SQL服务器。我在网上看到一些答案,说我应该在连接字符串中添加以下属性:

integratedSecurity=true;

And also add

并添加

sqljdbc_auth.dll

To the java path.

java的道路。

But this, as far as i understand applies only when i'm connecting from a Windows machine. When i try this on a Linux machine i get:

但据我所知,这只适用于从Windows机器连接的情况。当我在Linux机器上尝试这个时,我得到:

java.sql.SQLException: This driver is not configured for integrated authentication

My question is how do I do it from a Linux machine.

我的问题是如何从Linux机器上完成它。

Thanks

谢谢

2 个解决方案

#1


21  

Well, eventually I answer my own question: This is not possible to use Windows authentication from a linux machine using the Microsoft JDBC driver. This is possible using the jTDS JDBC driver using the following connection string:

最后,我回答了我自己的问题:使用Microsoft JDBC驱动程序从linux机器上使用Windows身份验证是不可能的。可以使用jTDS JDBC驱动程序使用以下连接字符串:

jdbc:jtds:sqlserver://host:port;databaseName=dbname;domain=domainName;useNTLMv2=true;

Thank you all for all the comments

谢谢大家的评论

#2


3  

TL;DR

博士TL;

It is not possible to use native Windows Authentication for JDBC connections to MSSQL from a JVM running on Linux.

在Linux上运行的JVM连接到MSSQL时,不可能使用本机Windows JDBC验证。


This MSDN article explains the authentiation methods with JDBC on Linux, potential errors, and available options:

这篇MSDN文章解释了JDBC在Linux上的认证方法、潜在的错误和可用的选项:

https://blogs.msdn.microsoft.com/psssql/2015/01/09/jdbc-this-driver-is-not-configured-for-integrated-authentication/

https://blogs.msdn.microsoft.com/psssql/2015/01/09/jdbc-this-driver-is-not-configured-for-integrated-authentication/

...in the JDBC 4.0 driver, you can use the authenticationScheme connection property to indicate how you want to use Kerberos to connect to SQL. There are two settings here.

…在JDBC 4.0驱动程序中,您可以使用authenticationScheme连接属性来指示如何使用Kerberos连接SQL。这里有两个设置。

  • NativeAuthentication (default) – This uses the sqljdbc_auth.dll and is specific to the Windows platform. This was the only option prior to the JDBC 4.0 driver.

    NativeAuthentication(默认)——它使用sqljdbc_auth。dll是特定于Windows平台的。在JDBC 4.0驱动程序之前,这是唯一的选择。

  • JavaKerberos – Makes use of the Java API’s to invoke kerberos and does not rely on the Windows Platform. This is java specific and not bound to the underlying operating system, so this can be used on both Windows and Linux platforms.

    JavaKerberos——使用Java API调用kerberos,不依赖于Windows平台。这是特定于java的,不绑定到底层操作系统,因此可以在Windows和Linux平台上使用。

...

The following document outlines how to use Kerberos with the JDBC Driver and walks through what is needed to get JavaKerberos working properly.

下面的文档概述了如何在驱动程序中使用Kerberos JDBC,以及如何使JavaKerberos正常工作。

Using Kerberos Integrated Authentication to Connect to SQL Server http://msdn.microsoft.com/en-us/library/gg558122%28v=sql.110%29.aspx

使用Kerberos集成身份验证连接到SQL服务器http://msdn.microsoft.com/en-us/library/gg558122%28

#1


21  

Well, eventually I answer my own question: This is not possible to use Windows authentication from a linux machine using the Microsoft JDBC driver. This is possible using the jTDS JDBC driver using the following connection string:

最后,我回答了我自己的问题:使用Microsoft JDBC驱动程序从linux机器上使用Windows身份验证是不可能的。可以使用jTDS JDBC驱动程序使用以下连接字符串:

jdbc:jtds:sqlserver://host:port;databaseName=dbname;domain=domainName;useNTLMv2=true;

Thank you all for all the comments

谢谢大家的评论

#2


3  

TL;DR

博士TL;

It is not possible to use native Windows Authentication for JDBC connections to MSSQL from a JVM running on Linux.

在Linux上运行的JVM连接到MSSQL时,不可能使用本机Windows JDBC验证。


This MSDN article explains the authentiation methods with JDBC on Linux, potential errors, and available options:

这篇MSDN文章解释了JDBC在Linux上的认证方法、潜在的错误和可用的选项:

https://blogs.msdn.microsoft.com/psssql/2015/01/09/jdbc-this-driver-is-not-configured-for-integrated-authentication/

https://blogs.msdn.microsoft.com/psssql/2015/01/09/jdbc-this-driver-is-not-configured-for-integrated-authentication/

...in the JDBC 4.0 driver, you can use the authenticationScheme connection property to indicate how you want to use Kerberos to connect to SQL. There are two settings here.

…在JDBC 4.0驱动程序中,您可以使用authenticationScheme连接属性来指示如何使用Kerberos连接SQL。这里有两个设置。

  • NativeAuthentication (default) – This uses the sqljdbc_auth.dll and is specific to the Windows platform. This was the only option prior to the JDBC 4.0 driver.

    NativeAuthentication(默认)——它使用sqljdbc_auth。dll是特定于Windows平台的。在JDBC 4.0驱动程序之前,这是唯一的选择。

  • JavaKerberos – Makes use of the Java API’s to invoke kerberos and does not rely on the Windows Platform. This is java specific and not bound to the underlying operating system, so this can be used on both Windows and Linux platforms.

    JavaKerberos——使用Java API调用kerberos,不依赖于Windows平台。这是特定于java的,不绑定到底层操作系统,因此可以在Windows和Linux平台上使用。

...

The following document outlines how to use Kerberos with the JDBC Driver and walks through what is needed to get JavaKerberos working properly.

下面的文档概述了如何在驱动程序中使用Kerberos JDBC,以及如何使JavaKerberos正常工作。

Using Kerberos Integrated Authentication to Connect to SQL Server http://msdn.microsoft.com/en-us/library/gg558122%28v=sql.110%29.aspx

使用Kerberos集成身份验证连接到SQL服务器http://msdn.microsoft.com/en-us/library/gg558122%28