Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I connect to SQL Server using Windows Authentication from Java EE webapp?

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 

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

Is there any way I can retrieve the credentials of the user's Windows Authentication and use that authentication for 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.

like image 820
karlgrz Avatar asked Oct 03 '08 15:10

karlgrz


People also ask

How do I connect to SQL Server Remote using Windows Authentication?

Security & ConnectionsRight-click on your server name and click 'Properties'. Go to the Security page for Server Authentication, and select 'SQL Server and Windows Authentication' mode. Then, go to the Connections page and ensure that "Allow remote connections to this server" is checked, and click OK.

Can a SQL Server login use Windows Authentication?

A connection made using Windows Authentication is sometimes called a trusted connection, because SQL Server trusts the credentials provided by Windows. By using Windows Authentication, Windows groups can be created at the domain level, and a login can be created on SQL Server for the entire group.

How do I connect to SQL Server with SQL authentication?

Right-click the server you wish to modify and then click Properties. Select the Security Page. Under the Server authentication heading choose either the desired authentication: Windows Authentication or SQL Server and Windows Authentication mode. Click OK.


1 Answers

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

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; 

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

MSDN > Connecting to SQL Server with the JDBC Driver > Building the Connection URL

like image 149
Jerome Delattre Avatar answered Oct 21 '22 07:10

Jerome Delattre