是否Kerberos连接到SQL Server需要在连接属性提供密码?(Does Kerberos

2019-10-29 05:22发布

我试图通过使用密钥表连接到SQL Server和它下面抛出错误

com.microsoft.sqlserver.jdbc.SQLServerException:不能与Kerberos主体域\用户登录,检查您的凭证。 Kerberos的登录失败:集成身份验证失败。 ClientConnectionId:6f436f49-b0bf-441E-bab3-e6af86ac8361由于javax.security.auth.login.LoginException(不能得到任何属性:[密码后,密码]从不可用,以争取从用户认证信息CON属性)在COM。 microsoft.sqlserver.jdbc.KerbAuthentication.intAuthInit(KerbAuthentication.java:108)在com.microsoft.sqlserver.jdbc.KerbAuthentication.GenerateClientContext(KerbAuthentication.java:399)在com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection。 Java的:4049)在com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3157)维持在com.microsoft.sqlserver com.microsoft.sqlserver.jdbc.SQLServerConnection.access $ 100(SQLServerConnection.java:82)。 jdbc.SQLServerConnection $ LogonCommand.doExecute(SQLServerConnection.java:3121)在com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7151)在com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java: 2478)在com.microsof t.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2026)在com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1687)在com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection。的java:1528)在com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:866)在com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:569)在java.sql.DriverManager.getConnection (未知来源)在java.sql.DriverManager.getConnection(未知来源)在com.adventnet.appmanager.server.mssql.datacollection.MSSQLKerberosAuthenticationTest.main(MSSQLKerberosAuthenticationTest.java:47)产生的原因:javax.security.auth.login中。 LoginException异常:无法获得任何属性:[密码后,密码]从不可用,以争取从com.sun.security.auth.module.Krb5LoginModule.promptForPass(来源不明)在com.sun.security用户认证信息CON性能。 auth.module.Krb5LoginModu le.attemptAuthentication(来源不明)在com.sun.security.auth.module.Krb5LoginModule.login(来源不明)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeMethodAccessorImpl.invoke(来源不明)在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)在java.lang.reflect.Method.invoke(未知来源)在javax.security.auth.login.LoginContext.invoke(未知来源)在javax.security.auth.login中。 LoginContext.access $ 000(来源不明)处java.security.AccessController.doPrivileged javax.security.auth.login.LoginContext中$ 4.run(来源不明)在javax.security.auth.login.LoginContext中$ 4.run(来源不明) (本机方法)在javax.security.auth.login.LoginContext.invokePriv(来源不明)在javax.security.auth.login.LoginContext.login(来源不明)在com.microsoft.sqlserver.jdbc.KerbAuthentication.intAuthInit(KerbAuthentication的.java:87)... 15个

当我试着使用密码连接成功。

String home = System.getProperty("user.dir");
String  filePath = home + File.separator + "conf" + File.separator + "KerberosConfigurations" + File.separator + "MSSQL";// NO I18N
System.setProperty("java.security.krb5.debug", "true");
System.setProperty("java.security.auth.login.config", filePath+File.separator+"login.conf");
System.setProperty("java.security.krb5.conf", filePath+File.separator+"krb5.ini");
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
String connectionUrl = "jdbc:sqlserver://"+hostName+":"+port+";databaseName=master;sendStringParametersAsUnicode=true;applicationName=test;"; //NO I18N
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Properties dbConProp = new Properties();
dbConProp.put("integratedSecurity", "true");
dbConProp.put("authenticationScheme", "JavaKerberos");
dbConProp.put("instanceName",instanceName);
dbConProp.put("user",user);
//dbConProp.put("password",pwd);
con = DriverManager.getConnection(connectionUrl,dbConProp);

请问在连接属性的密码是强制性的Kerberos连接? 单独密钥表还不够?

Answer 1:

客户端需要先进行身份验证到域。 例如Linux和MacOS下使用MIT Kerberos的 ,你可以使用kinit命令获取Kerberos票据。

一旦批准,那么你可以通过验证该票到SQL,而无需提供其他任何东西。

[更新]

如果你的主机和目标都在Windows域他们是在同一个域,那么你应该已经是好去。

这就是说,则SQL将允许您使用Kerberos 如果运行引擎服务帐户有权限创建一个验证服务主体名称 (或具有相应权限的用户创建与一个SPN setSPN命令)。

你可以告诉如果SQL一直能够通过在SQL错误日志寻找像文本注册SPN

The SQL Server Network Interface library successfully registered the Service Principal Name (SPN) [ MSSQLSvc/MySqlServerHostName:1433 ] for the SQL Server service

有很多的Kerberos比可以在短短的StackOverflow的答案被覆盖。



文章来源: Does Kerberos connection to the SQL server needs password to be supplied in connection properties?