我可以使用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?

UPDATE :我知道在ASP.net中有一种方法可以设置Windows身份验证以访问webapp,这正是我想要的,除了我想将该令牌传递给SQL Server以访问数据库。 / p>

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,那么你可以使用微软的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>使用以下方式连接到SQL Server JDBC驱动程序>构建连接URL