简体   繁体   English

JDBC MS SQL Server Kerberos身份验证

[英]JDBC MS SQL Server Kerberos Auth

I have a MS SQL Server RDBMS which uses Kerberos to authenticate the users. 我有一个使用Kerberos验证用户身份的MS SQL Server RDBMS。

From a Windows machine if I set the database URL to 在Windows计算机上,如果我将数据库URL设置为

jdbc:sqlserver://DB_NAME:DB_PORT;integratedSecurity=true

and add the appropriate sqljdbc_auth.dll to the path, everything works. 并将适当的sqljdbc_auth.dll添加到路径,一切正常。

However I would like to use the Java Kerberos authentication, in order to be able to use the same code in *nix machines too. 但是,我想使用Java Kerberos身份验证,以便也可以在* nix机器中使用相同的代码。

So my DB URL becomes 所以我的数据库URL变成

jdbc:sqlserver://DB_NAME:DB_PORT;integratedSecurity=true;authenticationScheme=JavaKerberos

When I am running the code I am getting the following exception: 当我运行代码时,出现以下异常:

Exception in thread "main" javax.security.auth.login.LoginException: Unable to obtain Princpal Name for authentication 
    at com.sun.security.auth.module.Krb5LoginModule.promptForName(Krb5LoginModule.java:796)
    at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:667)
    at com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:580)

Does anyone know why this is happening? 有人知道为什么会这样吗?

I have to add that I am using the default Krb5LoginModule that is provided by the JDBC driver. 我必须补充一点,我使用的是JDBC驱动程序提供的默认Krb5LoginModule

Thank you in advance. 先感谢您。

The MS JDBC docs states MS JDBC文档状态

When using authenticationScheme=JavaKerberos, you must specify the fully-qualified domain name (FQDN) in the serverName property. 使用authenticationScheme = JavaKerberos时,必须在serverName属性中指定标准域名(FQDN)。 Otherwise, an error will occur (Server not found in Kerberos database). 否则,将发生错误(在Kerberos数据库中找不到服务器)。

So your URL becomes 所以你的网址变成

jdbc:sqlserver://DB_NAME.domain.net:DB_PORT;integratedSecurity=true;authenticationScheme=JavaKerberos

您未能提供login.conf或该配置文件中使用Krb5LoginModule

Do you have a Kerberos subsystem (preferably the MIT Kerberos ) configured on your *NIX system? 您在* NIX系统上是否配置了Kerberos子系统 (最好是MIT Kerberos )? It is required in order to obtain a Ticket Granting Ticket (from a Key Distribution Centre ) to further authenticate to an SQL Server. 为了获得票证授予票证 (从密钥分配中心 )以进一步向SQL Server进行身份验证,这是必需的。 See also Wikipedia entry on Kerberos protocol , some guide from MS . 另请参阅Kerberos协议上的Wikipedia条目MS的一些指南

Are you executing the code in a Windows system? 您是否在Windows系统中执行代码? If this is your scenario, the problem could be related to the registry entry AllowTgtSessionKey. 如果这是您的情况,则问题可能与注册表项AllowTgtSessionKey有关。

In this link https://msdn.microsoft.com/en-us/library/gg558122%28v=sql.110%29.aspx you can find the next intruction: 在此链接https://msdn.microsoft.com/zh-cn/library/gg558122%28v=sql.110%29.aspx中,您可以找到下一个指令:

  1. Set AllowTgtSessionKey to 1 in the registry for Windows. 在Windows注册表中,将AllowTgtSessionKey设置为1。 For more information, see Kerberos protocol registry entries and KDC configuration keys in Windows Server 2003. 有关更多信息,请参见Windows Server 2003中的Kerberos协议注册表项和KDC配置项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM