macos 在 Mac 上使用 JBDC 对 SQL Server 进行 Windows 身份验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11234931/
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-10-21 09:16:56  来源:igfitidea点击:

Windows Authentication for SQL Server using JBDC on a Mac

javasqlsql-servermacoswindows-authentication

提问by user1406416

Is it possible to connect to SQL Server using Windows authentication/integrated security from a Mac? I am using the type 4 JDBC driver provided by Microsoft. The front end (a form application) is coded in Java. Everything works perfectly on Windows but one person in the office uses a Mac.

是否可以从 Mac 使用 Windows 身份验证/集成安全性连接到 SQL Server?我正在使用 Microsoft 提供的类型 4 JDBC 驱动程序。前端(一个表单应用程序)是用 Java 编码的。一切都在 Windows 上完美运行,但办公室里的一个人使用 Mac。

Is this possible? FYI, I have never used Macs so I am very much the novice with them. I have searched all over the Internet but have not found a solution. Thank you in advance.

这可能吗?仅供参考,我从未使用过 Mac,所以我对它们非常陌生。我已经搜索了整个互联网,但没有找到解决方案。先感谢您。

回答by Ray Morris

This information is hard to come by in my experience. All of my searches turned up wrong (outdated) information since Microsoft changed the rules and added the authenticationSchemeparameter. In the interest of helping the next person, here is an example of a connection string that works:

根据我的经验,这些信息很难获得。由于 Microsoft 更改了规则并添加了authenticationScheme参数,我所有的搜索都出现了错误(过时)的信息。为了帮助下一个人,以下是一个有效的连接字符串示例:

jdbc:jtds:sqlserver://123.123.123;instance=server1;databaseName=students;integratedSecurity=true;authenticationScheme=JavaKerberos

Also in driver properties set "Domain". Do not include the domain in any user name setting.

同样在驱动程序属性设置中"Domain"。不要在任何用户名设置中包含域。

This was tested using Squirrel SQL (Java) with jtds on Mac OSX. Hopefully the previous sentence has the search terms someone might use who needs to know this information.

这是在 Mac OSX 上使用带有 jtds 的 Squirrel SQL (Java) 测试的。希望前面的句子有一些需要知道这些信息的人可能会使用的搜索词。

回答by James Allman

Using Kerberos Integrated Authentication to Connect to SQL Server

使用 Kerberos 集成身份验证连接到 SQL Server

Beginning in Microsoft JDBC Driver 4.0 for SQL Server, an application can use the authenticationSchemeconnection property to indicate that it wants to connect to a database using type 4 Kerberos integrated authentication.

从 Microsoft JDBC Driver 4.0 for SQL Server 开始,应用程序可以使用authenticationScheme连接属性来指示它想要使用类型 4 Kerberos 集成身份验证连接到数据库。



The jTDSJDBC driver for SQL Server supports Windows authentication simply using the domainproperty as described in the FAQ.

SQL Server的jTDSJDBC 驱动程序支持 Windows 身份验证,只需使用FAQ 中所述的属性即可。

domain

Specifies the Windows domain to authenticate in. If present and the user name and password are provided, jTDS uses Windows (NTLM) authentication instead of the usual SQL Server authentication (i.e. the user and password provided are the domain user and password). This allows non-Windows clients to log in to servers which are only configured to accept Windows authentication.

If the domain parameter is present but no user name and password are provided, jTDS uses its native Single-Sign-On library and logs in with the logged Windows user's credentials (for this to work one would obviously need to be on Windows, logged into a domain, and also have the SSO library installed -- consult README.SSO in the distribution on how to do this).

领域

指定要在其中进行身份验证的 Windows 域。如果存在并且提供了用户名和密码,jTDS 将使用 Windows (NTLM) 身份验证而不是通常的 SQL Server 身份验证(即提供的用户和密码是域用户和密码)。这允许非 Windows 客户端登录到仅配置为接受 Windows 身份验证的服务器。

如果存在域参数但未提供用户名和密码,jTDS 将使用其本机单点登录库并使用登录的 Windows 用户凭据登录(为此,显然需要在 Windows 上登录域,并且还安装了 SSO 库——请参阅发行版中的 README.SSO 以了解如何执行此操作)。

回答by Matt

I use jTDS on a mac (10.9).

我在 mac (10.9) 上使用 jTDS。

Using this driver you need to specify the username and password like always, the only difference is that you need to specify domain=WHATEVERTHENTDOMAIN in the connection string (or connection properties if you rather).

使用此驱动程序,您需要像往常一样指定用户名和密码,唯一的区别是您需要在连接字符串中指定 domain=WHATEVERTHENTDOMAIN(或连接属性,如果您愿意)。

So a sample connection string is:

所以一个示例连接字符串是:

jdbc:jtds:sqlserver://db_server:1433/DB_NAME;domain=NT_DOMAIN_NAME

The jTDS driver then uses NTLM to login to the specified domain with the username and password.

jTDS 驱动程序然后使用 NTLM 使用用户名和密码登录到指定的域。

回答by zuckermanori

This is an old post but may be relevant for some people. See this other SO postthat describes how to connect to a SQL Server with Windows Authentication from a Linux machine through JDBC. This will work on mac as well.

这是一个旧帖子,但可能与某些人相关。请参阅此其他SO 帖子,其中描述了如何通过 JDBC 从 Linux 机器连接到具有 Windows 身份验证的 SQL Server。这也适用于 mac。

回答by Neil McGuigan

jTDS is inferior to Microsoft's JDBC driver (in particular, it cannot figure out the types of parameters in a prepared statement)

jTDS不如微软的JDBC驱动(尤其是在prepared statement中无法判断参数的类型)

Yes, you can authenticate to MS SQL Server using Active Directory authentication, as Active Directory is just Kerberos + LDAP, which are open source and implemented on Mac

是的,您可以使用 Active Directory 身份验证对 MS SQL Server 进行身份验证,因为 Active Directory 只是 Kerberos + LDAP,它们是开源的并在 Mac 上实现

Kerberos config /etc/krb5.conf:

Kerberos 配置/etc/krb5.conf

[libdefaults]
default_realm = YOUR_REALM.NET

[realms]
YOUR_REALM.NET = {
    kdc = host.your-domain.net
}

I needed to use the fully qualified domain name of the KDC, not just the domain name

我需要使用 KDC 的完全限定域名,而不仅仅是域名

JDBC Connection String:

JDBC 连接字符串:

jdbc:sqlserver://$host;database=$db;integratedSecurity=true;authenticationScheme=JavaKerberos

If $hostdoes not have an SPN of MSSQLSrv/$host, add serverSp=$SPNto the JDBC connection string

如果$host没有 的 SPN MSSQLSrv/$host,则添加serverSp=$SPN到 JDBC 连接字符串

回答by Ray Morris

It is not correct to say that one driver can determine the data types and another driver can't. Anydriver has to look at the implied type based on the arguments passed. Both jTDS and Microsoft's driver do this. This is a limitation of the protocol - the database cannot tell the driver which type is correct, because in many queries it can't know what you intend.

说一个驱动程序可以确定数据类型而另一个驱动程序不能确定是不正确的。 任何驱动程序都必须根据传递的参数查看隐含类型。jTDS 和微软的驱动程序都这样做。这是协议的限制 - 数据库无法告诉驱动程序哪种类型是正确的,因为在许多查询中它无法知道您的意图。

In each version, jTDS and Microsoft's driver each have different issues and different advantages. The "best" choice depends on exactly which version of each you look at, and exactly what your needs are. I've had to switch back and forth as different versions come out - Microsoft breaking in a certain way, then later adding something I wanted.

在每个版本中,jTDS 和微软的驱动都有不同的问题和不同的优势。“最佳”选择取决于您查看的每个版本的确切版本以及您的需求。随着不同版本的出现,我不得不来回切换 - 微软以某种方式突破,然后添加了我想要的东西。