Connect to MSSQL from Spring boot application using windows authentication - sql-server

I am currently using the below properties to connect to a remotely Mssql server from Java spring boot application:
spring.datasource.url=jdbc:sqlserver://ip\\domain;databaseName=name
spring.datasource.username=abc
spring.datasource.password=def
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
The application runs from both windows and unix servers. I need now to start using the windows authentication instead of the db credentials. This is already configured and supported from MSSQL side. From Java spring boot this is not working. I tried to add to the url: integratedSecurity=true it said it cannot find a dll. I added sqljdbc_auth.dll to java jre bin folder and it didnt work.

I'm working on MS SQL Server 2016, Hibernate 5.3.7.Final and Spring bot 2.2.0. For me, adding this line to properties worked: (without jtds!)
spring.datasource.url=jdbc:servername;databasename=your_db_name;integratedSecurity=true
You may also need these properties:
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
And if you encounter a problem with "no sqljdbc_auth in java.library.path".
You may refer to this answer no sqljdbc_auth.

Try use jtds driver, and in apllication properties use:
app.datasource.youraplication.jdbcUrl=jdbc:jtds:sqlserver://yourBdHost/yourSchemaBd;domain=yourDomain

Download the drivers from:
https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-2017
Add the jar to your project Right Click on project - > Build Path -> Configure Build Path - > Libraries -> Add External JARs
Add "integratedSecurity=true" to your connection string and remove username and password

Related

How do you package a Java SQL Server application that uses integrated security with Eclipse?

I'm new to Java. I'd like to build a CRUD application with SQL Server as the database. It will be implemented on an Active Directory domain and I'd like to use integrated security. How can I package the application so that the driver including the authentication library "mssql-jdbc_auth-9.2.0.x64.dll" be included and used in the installed application.
I created a test application where I included a Java Build Path\Classpath entry of: "C:\Program Files\Microsoft JDBC DRIVER 9.2 for SQL Server\sqljdbc_9.2\enu\mssql-jdbc-9.2.0.jre15.jar" for the driver.
It runs in Eclipse with integrated security if I put a copy of the authentication library "mssql-jdbc_auth-9.2.0.x64.dll" from the driver in either of the following directories:
C:\Program Files\Java\jdk-15.0.2\bin
C:\Windows\System32
C:\Program Files\SQL1-Test\runtime\bin of installed application
Or use:
VM run configuration arguments: -Djava.library.path="C:\Program Files\Microsoft JDBC DRIVER 9.2 for SQL Server\sqljdbc_9.2\enu\auth\x64" in the project.
When I try to export to a jar file for packaging with the above VM arguments applied it says "VM arguments will not be part of the runnable JAR".
The installed application will run with integrated security if the the authentication library "mssql-jdbc_auth-9.2.0.x64.dll" is in any of the above directories.
How can the I ensure that the authentication library "mssql-jdbc_auth-9.2.0.x64.dll" will be functionally included in the installed application.
Has anyone created such an application or have pointers on how to do this.
Thanks.

Jhipster and Postgres connection

I'm trying to run the project in Jhipster based on this tutorial by the creator himself :https://www.youtube.com/watch?v=d1MEM8PdAzQ but it can't connect to Postgres
See errors below:
Caused by: org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided.
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:473)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:203)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:146)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:35)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:47)
at org.postgresql.jdbc42.AbstractJdbc42Connection.<init>(AbstractJdbc42Connection.java:21)
at org.postgresql.jdbc42.Jdbc42Connection.<init>(Jdbc42Connection.java:28)
at org.postgresql.Driver.makeConnection(Driver.java:415)
at org.postgresql.Driver.connect(Driver.java:282)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:101)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:316)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:518)
How do I connect Jhipster with postgreSQL? I am a newbie on jhipster
JHipster creates 3 configuration files: -
application.yml - main Spring Boot configuration file.
application-dev.yml
application-prod.yml
The application.yml file contains common properties, the other 2 hold specific properties to development and production environments.
If you look at application-dev.yml you'll see something like the following: -
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/myapp
username: myapp
password:
However, you still have to create your PostgreSQL database - the easiest way is via the pgAdmin tool but you can also create it via command line tools - a quick google will help you there!
If you don't want to work with docker compose file Version 3 in docker swarm mode, where it is best practice to use docker secrets, then you can create an .application.env-file and link it in your docker-compose.yml (Version 2) with 'env_file:'
$ cat .application.env
SPRING_PROFILES_ACTIVE=prod,swagger
SPRING_DATASOURCE_URL=jdbc:postgresql://postgresql:5432/database_name
SPRING_DATASOURCE_USER=database_user
SPRING_DATASOURCE_PASSWORD=database_password
JHIPSTER_SLEEP=10
[...]
At least I use it this way to keep the credentials away from my jhipster-projects, which are on Github, where I also want to put the *.yml-files.

Configuring a Postgresql connection with Play 2 and Slick-Play

I'm learning how to build an application using Scala and the Play 2 Framemork. I`ve created a new project using the activator tool, based on "play-scala-intro" current template.
The template have a sample app using the Play-Slick 1.0 for managing dependencies and is configured with a H2 DB, that worked without problems.
When I tried to change to a Postgres DB, I'm running in trouble. I get an error 500, telling me:
"Cannot connect to database [default]".
In the stack trace, the exception is:
"Configured Slick driver org.postgresql.Driver is not an instance of
requested profile slick.profile.BasicProfile"
So... What I already did:
I added to my build.sbt file the dependency:
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41"
In my configuration file (application.conf), the DB connection is configured as:
slick.dbs.default.driver=org.postgresql.Driver
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/hello_play"
slick.dbs.default.db.user="postgres" slick.dbs.default.db.password=""
PS: I've tried with slick.dbs.default.driver="org.postgresql.Driver" too...
PS2: My db password is empty. I'm connecting with PgAdmin without problems
slick.dbs.default.driver must be a slick driver, not a JDBC driver. Your db config should look something like this:
slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/hello_play"
slick.dbs.default.db.user="postgres"
slick.dbs.default.db.password=""

Grails MS SQLServer 2008 jdbc driver causes problems in tomcat

What is the official way to use the microsoft jdbc driver for mssql in a grails application?
The general opinion that I found through googling is that I only have to drop the jar in the lib directory of the grails app. This works if I do a grails clean and grails compile --refresh-dependencies. But when I deploy on a real server I have two problems.
When redeploying there is this a warning in the logs.
24.05.2013 16:03:03 com.microsoft.sqlserver.jdbc.AuthenticationJNI
WARNUNG: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
I'm not sure if its something to care about since its a warning. But I would like to have my logs clean and I have the dll in the lib directory of the application just as google is saying. Additionally on redeployment there are several messages like this that might relate to the first one:
24.05.2013 16:03:02 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SCHWERWIEGEND: A web application created a ThreadLocal with key of type [org.codehaus.groovy.runtime.GroovyCategorySupport.MyThreadLocal] (value [org.codehaus.groovy.runtime.GroovyCategorySupport$MyThreadLocal#76fe8d1b]) and a value of type [null] (value [null]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
And the last thing is that my coworker said, that she thinks the driver should not be installed on a per application basis but directly into tomcat. I actually don't know how to do this, but if I did it, this would cause a problem on the development machine since I don't know how to get grails run-app going without the driver in the applications lib directory.
You can still place the library in the lib folder of your project and just exclude this from the war generation.
You don't need to exclude the jar everytime you build your project, just follow this post tip.
In your Tomcat server the jar will be placed in the shared lib folder instead of each web application.
If after that you still get the warning about sqljdbc_auth.dll you will need to locate this file and add the folder in the Tomcat classpath (or copy to Tomcat lib folder).

Starting up tomcat-6.0.20 from eclipse-3.5.0 (galileo) leads to the 404 error

Console dogs me. Can anybody help?
The sad story starts like this. My OS is ubuntu-9.04. I installed tomcat-6.0.20 by extracting it from .tar.gz package and put it under the /usr/share/tomcat-6.020 directory.
Then I started tomcat from console, and everything seemed to be fine. localhost answered with the $CATALINA_HOME/webapps/ROOT/index.html page.
The next step was to put my tomcat in the eclipse's servers list. So, I went to Preferences > Server > Runtime Environment > Add > Apache Tomcat v6.0 (here I also browsed to my tomcat and changed JVM from JRE to JDK). Finally, I added my server to the Servers list.
So, having everything configured, I started my tomcat from the eclipse, opened a browser and asked for localhost. 404 all over sudden. Despite the fact that the eclipse's console has shown no errors.
Has anybody encountered the same problem?
I fixed the "Could not load server configuration" problem by deleting the current server configuration from the Servers View and adding it again.
Open your Tomcat settings (double click or F3 on your Tomcat instance in 'Servers' view in Eclipse):
Make sure configuration path is valid and configuration is valid
Click on modules tab and make sure your app is deployed.
I'm with Carlisg. I had this error in Eclipse 3.6 with Tomcat 5.5: "Could not load server configuration at /Servers/Tomcat v5.5 server. The configuration maybe corrupt or incomplete." After playing around with every setting for 20 minutes and getting the same error, I just deleted the server, re-added it and it worked in about 90 seconds with no changes.
yes emanemos is right, I tried it today and got it working instantly. Create a new project in eclipse, I created a Dynamic web project. Create a new server, choose your apache version as the server type. Then create your pages and resources in this project space. I created index.html in Webcontent and pointed to http://localhost:8080/trial/ and I can see my index.html. (trial is the name of my project).
In windows vista 32 I fixed like this, In 'serverlocation' selected Use Tomcat installation(takes control of tomcat installation) and for deploy path I added my tomcat webapp dir.'C:\apache-tocat-6.0.26-windows-x86\apache-tomcat-6.0.26\webapps'. With default configuration path /Servers/Tomcat v6.0 Server at localhost-config, it just works fine.
I had the same problem and solved it following these steps:
On the Server View, right click on the server (Tomcat 6.0 Server at Localhost)
in the menu options click "Open", this opens a menu with all the configurations for the server.
On tab "Server Locations" you must select the option "Use Tomcat Installation (takes control of tomcat installation)".
Do not forget to check the Deploy path.
I think there is a problem with eclipse configuration over Tomcat and it must use the tomcat installation configuration.

Resources