我可以从 Java EE webapp 使用 Windows 身份验证连接到 SQL Server 吗? [英] Can I connect to SQL Server using Windows Authentication from Java EE webapp?

查看:25
本文介绍了我可以从 Java EE webapp 使用 Windows 身份验证连接到 SQL Server 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究如何使用 Windows 身份验证而不是 SQL Server 身份验证从我的 Java EE Web 应用程序连接到 SQL Server 数据库.我在 Tomcat 6.0 上运行此应用程序,并使用 Microsoft JDBC 驱动程序.我的连接属性文件如下所示:

I am currently investigating how to make a connection to a SQL Server database from my Java EE web application using Windows Authentication instead of SQL Server authentication. I am running this app off of Tomcat 6.0, and am utilizing the Microsoft JDBC driver. My connection properties file looks as follows:

dbDriver              = com.microsoft.sqlserver.jdbc.SQLServerDriver
dbUser                = user
dbPass                = password
dbServer              = localhost:1433;databaseName=testDb
dbUrl                 = jdbc:sqlserver://localhost:1433

我在使用 SQL Server 身份验证时以这种方式连接到 SQL Server 数据库的问题为零.

I have zero problems with connecting to a SQL Server database in this fashion when using SQL Server authentication.

有什么方法可以检索用户的 Windows 身份验证凭据并使用那个身份验证用于 SQL Server?

Is there any way I can retrieve the credentials of the user's Windows Authentication and use that authentication for SQL Server?

更新:我知道在 ASP.net 中有一种方法可以设置 Windows 身份验证以访问 web 应用程序,这正是我正在寻找的,但我想传递该令牌到 SQL Server 以访问数据库.

UPDATE: I know in ASP.net there is a way to set up Windows Authentication for access to the webapp, which is exactly what I am looking for, except I want to pass that token off to SQL Server for access to the database.

推荐答案

我不认为可以将用户凭据从浏览器推送到数据库(这是否有意义?我认为不是)

I do not think one can push the user credentials from the browser to the database (and does it makes sense ? I think not)

但是如果您想使用运行 Tomcat 的用户的凭据连接到 SQL Server,那么您可以使用 Microsoft 的 JDBC 驱动程序.只需像这样构建您的 JDBC URL:

But if you want to use the credentials of the user running Tomcat to connect to SQL Server then you can use Microsoft's JDBC Driver. Just build your JDBC URL like this:

jdbc:sqlserver://localhost;integratedSecurity=true;

并将相应的DLL拷贝到Tomcat的bin目录下(驱动自带的sqljdbc_auth.dll)

And copy the appropriate DLL to Tomcat's bin directory (sqljdbc_auth.dll provided with the driver)

MSDN > 使用 JDBC 驱动程序连接到 SQL Server > 构建连接 URL

这篇关于我可以从 Java EE webapp 使用 Windows 身份验证连接到 SQL Server 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆