通过kerberos身份验证连接Java中的SQL Server

时间:2019-03-12 11:39:52

标签: java sql-server kerberos

有人可以帮助我如何通过Java中的Kerberos身份验证连接SQL Server吗?我正在按照此链接中建议的步骤进行操作,但出现以下错误

https://docs.microsoft.com/en-us/sql/connect/jdbc/using-kerberos-integrated-authentication-to-connect-to-sql-server?view=sql-server-2017

  

原因:javax.security.auth.login.LoginException:无法获取   身份验证的主体名称   com.sun.security.auth.module.Krb5LoginModule.promptForName(Krb5LoginModule.java:841)   在   com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:704)   在   com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:617)   在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)   在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   在java.lang.reflect.Method.invoke(Method.java:498)在   javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)   在   javax.security.auth.login.LoginContext.access $ 000(LoginContext.java:195)   在javax.security.auth.login.LoginContext $ 4.run(LoginContext.java:682)   在javax.security.auth.login.LoginContext $ 4.run(LoginContext.java:680)   在java.security.AccessController.doPrivileged(本机方法)在   javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)   在javax.security.auth.login.LoginContext.login(LoginContext.java:587)

这是我正在尝试的代码

  

字符串connectionUrl =   “ jdbc:sqlserver:// MYHOST; databaseName = master; integratedSecurity = true; authenticationScheme = JavaKerberos”;

     

连接con = null;语句stmt = null; ResultSet rs = null;   System.setProperty(“ java.security.krb5.conf”,   “ C:\ KRB \ krb5.conf”);   System.setProperty(“ sun.security.krb5.debug”,“ true”);   System.setProperty(“ java.security.auth.login.config”,   “ C:\ KRB \ SQLJDBCDriver.config”);

     

尝试{       Class.forName(“ com.microsoft.sqlserver.jdbc.SQLServerDriver”);       con = DriverManager.getConnection(connectionUrl);       DatabaseMetaData dbmd = con.getMetaData();       System.out.println(“ dbmd:driver version =” + dbmd.getDriverVersion());       System.out.println(“ dbmd:driver name =” + dbmd.getDriverName());       System.out.println(“ db name =” + dbmd.getDatabaseProductName());       System.out.println(“ db ver =” + dbmd.getDatabaseProductVersion());   } catch(异常e)   {       e.printStackTrace();   }

0 个答案:

没有答案