Groovy & SQL authentication
I have a couple of Groovy Datasources running SQL queries and I would like to write in the lines for the script to use Windows auth or SQL auth but I'm not sure how. I have it working using SQL auth but in some instances Windows Auth is going to be used. I'm looking at some of the other core SQL datasources and how they work but I'm having a hard time picking out the lines in the scripts that they use for this. It's my understanding that they use the outputs from some of the core SQL property sources. I'd like to leverage that as well but don't know what I need.
Here's the initial script I have but it's not working this way. Do any of you have an example I could look at or see an issue in what I've shown below?
import org.xbill.DNS.*;
import groovy.sql.Sql;
def returnCode = 0;
def sql = null;
try {
dbname = hostProps.get("databasexyz")
//user = hostProps.get("jdbc.mssql.user");
//pass = hostProps.get("jdbc.mssql.pass");
hostname = hostProps.get('system.hostname');
//Check for Integrated Security and then authenticate that way if it's available
if(auto.integrated_security == "true"){
SQLUrl = "jdbc:sqlserver://${hostname};integratedSecurity=true;applicationIntent=ReadOnly;logintimeout=5";
}else
SQLUrl = "jdbc:sqlserver://${hostname}:1433;user=${user};password=${pass}";
sql = Sql.newInstance(SQLUrl)
// Loop through every row returned by the query
sql.eachRow( 'SELECT * from blah blah blah