JDBC URL connection to SQL Server using Windows Authentication in JIRA plugin - sql-server

I am currently at my wits end. I am trying to connect a JIRA plugin (Atlassian Java SDK) to a SQL Server 2012 database. It's required that I use Windows Authentication, but JIRA is logging:
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication.
I've read that this can be combatted by adding the sqljdbc_auth.dll file to the program's library path, but there are no references specifically for JIRA plugins on how to do this other than for the base JIRA dbconfig.xml, which I am not using. This is a connection made within the plugin using the code:
String url = String.format("jdbc:sqlserver://%s:1433;databaseName=%s;integratedSecurity=true;domain=XXXX;", server, database);
I have tried to add the dll file to the following locations, all to no avail:
C:/{JIRA INSTALL PATH}/bin
C:/{JIRA INSTALL PATH}/jre/bin
C:/{JAVA INSTALL PATH}/jre_8.x.x/bin
What gives?
UPDATE:
I have gone in and added the JDBC JAR/DLL to the classpath/library path respectively in the JIRA Windows service configuration tool. Still getting the same error.
UPDATE 2:
I have switched to using the JTDS driver to see if JIRA was just not able to use the standard JDBC driver for some reason, but getting a similar error:
java.sql.SQLException: I/O Error: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.
I have also created a new Java app to test this in a controlled environment, but do not get this error after adding the ntlmauth.dll file to the C:\Windows\System32 directory. This leads me to believe this may be a bug within JIRA or I have something configured improperly.

Here is my own conclusion after many weeks of searching:
It is (currently) impossible to do this without the use of a password (which is sometimes the entire point of using Windows/Active Directory credentials). You can however use the JTDS driver in junction with a domain, username, and password to authenticate to servers that require windows authentication. This does not solve the core issue, but from what I can tell is the only current solution close enough to it.

Related

Microsoft SQL server as Atrifactory 7.38.10 metadata database

We have installed Atrifactory 7.38.10 on a windows server, Microsoft SQL server configured in System.yml as a database for metadata.
String connectionUrl =
"jdbc:sqlserver://localhost:1433;" +
"databaseName=AdventureWorks;integratedSecurity=true;" +
"encrypt=true;trustServerCertificate=true";
Artifactory.bat start throwing below mentioned error.
Could not initialize database (db config: {mssql jdbc:sqlserver://dev.tfs2017sql.xyz.com:55300;databaseName=JFROGPOC;encrypt=false;sendStringParametersAsUnicode=false;applicationName=Artifactory Binary Repository;integratedSecurity=true;}): TLS Handshake failed: x509: certificate signed by unknown authority
error connecting to database. giving up
jfrog.com/metadata/v7/services/common/db.(*databaseBearer).init
jfrog.com/metadata/v7#v7.37.0/services/common/db/database_bearer.go:152
Java version is 11 and JDBC driver is “mssql-jdbc_auth-10.2.1.x64.dll” for windows integrated authentication
From the way it looks, the issue is on the metadata service as you said.
I suggest trying to follow this article I wrote in the past about it and try to provide to the metadata service an additional golang connection URL(as it's possible that the script conversion from the Java doesn't support all the parameters), and make sure you have added the certificate to the /etc/ssl/certs folder as metadata service is written in Golang and usually load the certificates from the OS and not from the Java trust store.

How to connect to sql DB from soapUI using connection string?

I would like to ask someone who already tried to connect to SQL database from soapUI opensource version.
I have a test step JDBC request where I try to test and connect to my sql database. I use opensource version of soapUI. I read how it should be set up but still experience some problems.
This is what I do:
I installed java 8 and jdbc driver version 4.1. Added jdbc jar file to SoapUi/jre/bin folder as it is said in documentation for soapUI. This version of driver should work with Java 8.
Then in Driver field I write
com.microsoft.sqlserver.jdbc.SQLServerDriver
In connection string:
jdbc:sqlserver://Sservername:portnumber;databaseName=Consumption;username=alyona.kovalyova;password=mypassword
I get error saying
Can't get the Connection for specified properties; com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'alyona.kovalyova'. ClientConnectionId...
I use my domain account because in our company the policy does not allow us to use database user. Because of this I tried to add integratedSecurity parameter to the string which should allow to login with windows account like this:
jdbc:sqlserver://S23-AS:1433;databaseName=Consumption;integratedSecurity=true
I also get error:
Can't get the Connection for specified properties; com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId..
Does anyone encountered the same issue before? Could you give some recommendation?
For integrated authentication to work you'll need sqljdbc_auth.dll matching your environment (32bit / 64bit) in your library path (putting it in bin as well might help already)

Authenticating to a SQL Server instance as a Windows User via JDBC

I'm having to support multiple database types for my tenant-enabled web application. Among others, I have successfully supported Microsoft's SQL Server, by using the net.sourceforge.jtds.jdbc.Driver class with a connection String like "jdbc:jtds:sqlserver://192.168.1.189:1433/ApplicationName". This works, but it requires that the user explicitly defines a user in the SQL Server instance and enables SQL Server authentication.
Now, inevitably, requirements changed, and we're supposed to support connecting to SQL Server via Windows Authentication. Evidently this requires some sort of change to the connection string, since the data base server must somehow be able to distinguish whether the credentials passed into the data base connection are for a user defined in the SQL Server installation or in the Windows OS. But what is it?
Acting on advice from the internet, if progressed as far as extending the connection string with ;useNTLMv2=true;domain=WORKGROUP. That seems to make the data base server aware that I want to authenticate as a Windows user, but the actual log-in fails with
The login is from an untrusted domain and cannot be used with Windows authentication. (code 18452, state 28000)
Now im my testing set-up, both the J2EE app and the SQL server instance are in fact on the same machine (although in production they may not be), and still this computer isn't trusted enough to log on to itself? Evidently I'm missing a big part of the puzzle here. What does one have to do to convince an SQL Server instance that the user who started it can in fact log on to it via JDBC?
Edit
Since we have already sunk too much unsuccessful effort trying to integrate our web application with a full Microsoft infrastructure stack (SQL Server, Active Directory, Domain Name Service...), I have to restrict this question:
Does anyone know a way to access an SQL Server installation with a user account defined as a "Windows User" via JDBC form a J2EE application, without having to use Active Directory, a Windows machine running the web application and a proprietary DLL? The bounty is for any solution of that sub-problem. The entire problem is clearly too broad to be answered in one forum post.
I ran into the error
The login is from an untrusted domain and cannot be used with Windows
authentication
when a 2012 SQL Server DB instance was recently upgraded to 2016. In order to use AD based authentication with the JTDS driver and SQL Server 2016, it seems necessary to specify both the useNTLMv2=true and the domain=example.com suffix in order to establish a connection. The name of the domain is absolutely necessary and I confirmed that through testing. This is with JTDS driver version 1.3.1.
Example of a working connection string using AD based authentication to SQL Server 2016 DB with JTDS 1.3.1:
jdbc:jtds:sqlserver://sqlserver2016db.example.com/MY_DB_NAME;domain=example.com;prepareSQL=2;useNTLMv2=true
UPDATE
Recently (due to the pandemic lockdown), I found myself also having to connect to SQL Server using Windows authentication from a non-domain computer (over VPN). This can be accomplished by starting the Windows process initiating the SQL Server connection, e.g. Eclipse / Spring Tool Suite, with the following command:
C:\Windows\System32\runas.exe /netonly /user:domain\user "path_to_executable.exe"
Source: https://www.mssqltips.com/sqlservertip/3250/connect-to-sql-servers-in-another-domain-using-windows-authentication/
In discovering that gem, I also discovered that encryption needed to be used. Here are the settings I'm using (in addition to now running the executable with /netonly and a domain account):
spring.datasource.url=jdbc:jtds:sqlserver://fqdn_of_server_including_domain/DBNAME;domain=mydomain;useNTLMv2=true;ssl=require;prepareSQL=2;
spring.datasource.username=domainaccountname_without_domain_prefix
spring.datasource.password=password
spring.datasource.testOnBorrow=true
spring.datasource.hikari.connection-test-query=SELECT 1
spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect
What you describe certainly appears to be feasible. I have SQL Server 2008 R2 Express running on a stand-alone server and I was able to connect using a Windows username/password on that server via jTDS 1.3.1 from a separate Windows machine and from an Xubuntu 14.04 box.
On the machine running SQL Server I created a Windows user named 'kilian'. In SQL Server itself I created a SQL Login for NT AUTHORITY\Authenticated Users. Then in the database (named 'myDb') I created a User named 'AuthenticatedUsers' for that SQL Login. Just to keep things simple I gave that user db_owner rights on the database.
There is no SQL Login for 'kilian' and no database User with that name.
Then, from the other two machines (the Windows workstation and the Xubuntu box) I just ran this:
package com.example.jtdstest;
import java.sql.*;
public class JtdsTestMain {
public static void main(String[] args) {
try (Connection con = DriverManager.getConnection(
"jdbc:jtds:sqlserver://192.168.1.137:52865/myDb" +
";domain=whatever",
"kilian",
"4theBounty")) {
try (Statement s = con.createStatement()) {
String sql = "SELECT LastName FROM Clients WHERE ID=1";
try (ResultSet rs = s.executeQuery(sql)) {
rs.next();
System.out.println(rs.getString("LastName"));
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
Additional notes:
I did not have to include useNTLMv2=true. I was able to connect with or without that parameter.
I did have to include domain= to tell the SQL Server not to use SQL authentication, but the actual value I supplied made no difference. (I literally used 'whatever', which was not the name of the server or the name of the workgroup to which it belongs.)
Alternative Method
The alternative solution is to utilize integrated security. This enables your application to connect to the database as the user in which the application is currently running as. This is enabled by adding integratedSecurity=true; into the connection string properties. If you run into any trouble, make sure the sqljdbc_auth.dll is accessible via classpath or within your app library.
Security Note
You're probably already aware, but just have to say make sure not to grant access to "Authenticated Users" to your database as previously suggested as part of the demonstration. Identify which user account your application runs as and grant access to only that specific user in your database server.
Sources / Additional Info
MSDN Doc on JDBC Connection String Configuration (http://technet.microsoft.com/en-us/library/ms378428(v=sql.110).aspx)
The main problem is the windows authentication with a full java solution (no DLL). So you could use one of the libs below:
NTLM authentication: http://ioplex.com/jespa.html
spring based Kerberos authentication: http://projects.spring.io/spring-security-kerberos/
another integrated windows auth lib is SPNEGO (don't know much about this one)
So once your app is authenticated with one of the lib above, your JDBC should run fine using "integratedSecurity=true;" and if needed "authenticationScheme=JavaKerberos".
Firstly you should write the jdbc connection like this:
String url ="jdbc:sqlserver://PC01\inst01;databaseName=DB01;integratedSecurity=true";
then
you need to enable the SQL Server TCP/IP Protocol in Sql Server Configuration Manager app. You can see the protocol in SQL Server Network Configuration.
I can see two possibilities,
1. You are using a local system account which the server won't understand
In this case, switch to a domain account.
Windows authentication has different credential requirements and you might not be meeting those.
In this case try changing the password to match the requirements.
It is very well possible that both are happening.
see this other SO post that describes how to connect to a SQL Server with Windows Authentication from a Linux machine through JDBC
This is my NiFi setup for jTDS driver:
Database Connection URL: jdbc:jtds:sqlserver://192.168.1.189:1433;DOMAIN=domain_name
I didn't need to add useNTLMv2=true, but most people need to, so if it doesn't work you can try also:
jdbc:jtds:sqlserver://192.168.1.189:1433;DOMAIN=domain_name;useNTLMv2=true
Database Driver Class Name: net.sourceforge.jtds.jdbc.Driver
Database User: domain_user_name (**without** #domain)
Password: domain_password
Validation query: select 1
One of the possible reasons for this error to appear is when you configure you data source to use windows authentication and SQL Server is using Extended Protection mode together with SSL (i'm not sure if SSL is required though). This mode requires the client to send additional information - signed service principal name (SPN) and channel binding token (CBT). See more information about Extended Protection Mode here. Currently both JTDS JDBC and Microsoft JDBC drivers do not support this mode. I couldn't find an official statement from JTDS, but there is an open ticket for Microsoft drivers.
In order to configure Extended Protection mode, go to SQL Server Configuration Manager, select properties on SQL Server Network Configuration -> Protocols for %your instance% and change Extended Protection option.

I/O Error: SSO Failed: SSPI Not Initialized

I am using pentaho data integration 4.1 (Kettle) to build an ETL system. My customer requires connecting to database (MS SQL Server) using window authentication, I knew that Kettle supported it . However when I run my Kettle job, it throws the exception
"I/O Error: SSO Failed: SSPI Not Initialized".
From an article on a forum, I copy library sqljdbc_auth.dll into jre/bin folder. The result is quite good, I can use window authentication to connect to SQL server. But this function is not stable, I mean sometimes it works well, sometimes it throws exception
"I/O Error: SSO Failed: SSPI Not Initialized".
Please tell me how to fix this error.
Thank you.
To connect to SQL Server 2008, I had to install the 'Microsoft JDBC Driver 4.0 for SQL Server' and then add the path to sqljdbc_auth.dll to Spoon.bat in %PENTAHO_DI_JAVA_OPTIONS%. Like this:
set OPT=%PENTAHO_DI_JAVA_OPTIONS% "-Djava.library.path=%LIBSPATH%;C:\PROGRA~1\MICROS~1.0FO\sqljdbc_4.0\enu\auth\x86;C:\PROGRA~1\IBM\SQLLIB\BIN" "-DKETTLE_HOME=%KETTLE_HOME%" "-DKETTLE_REPOSITORY=%KETTLE_REPOSITORY%" "-DKETTLE_USER=%KETTLE_USER%" "-DKETTLE_PASSWORD=%KETTLE_PASSWORD%" "-DKETTLE_PLUGIN_PACKAGES=%KETTLE_PLUGIN_PACKAGES%" "-DKETTLE_LOG_SIZE_LIMIT=%KETTLE_LOG_SIZE_LIMIT%"
Ugly, but that's Java under Windows for you. Works quite reliably now though.
Are you using the JTDS driver? Try that combined with the ntlmauth.dll - that works great for us when running PDI on Windows Server 2003 connecting to various remote sqlserver databases.
We place the DLL in this folder:
libswt\win64
I've had the same issue while using JDBC 1.2.2 with MSSQL 2008. It turns out that there is a bug in the driver, making it randomly crash if you initialize it with more than one connection.
If we used only one initial connection to the DB this error never presented itself.
The issue is fixed in a later versions of JDBC. We currently use 1.3.0 and I/O Error: SSO Failed: SSPI Not Initialized never comes up.

MS SQL driver issue with Struts 2 tomcat 7

I am developing web application using Tomcat 7 and connecting to a MSSQL 2008 DB.
While executing a DB operation from any Java console based application, it succeeds. Same code fails to execute while performing same operations from web application with the message "No suitable drivers found". We are using sqljdbc4
URL private String url = "jdbc:sqlserver://10.100.41.232;databaseName=iptvdb;";
Not able to understand the this strange behaviour. Any workarounds?
Also tried with : port 1433 but it's still not working.
That error means it cant find the JDBC driver on your classpath. Do you have the JDBC driver? You need to have the MySQL JDBC drivers. If you dont have it, it can be downloaded from the MySQL website.
If you do have the driver or have downloaded it, make sure it is in the correct place. It needs to be placed on your classpath. This usually means one of two places
With your Struts application under the WEB-INF/lib folder
With the application server. For tomcat this is usually in $CATALINA_HOME/lib

Resources