Heroku - FATAL: password authentication failed for user <> - java

First of all, I created PostgreSQL DB in Heroku. I manually created my DB/schema/tables through pgAdmin remote access. I know I succeeded since it updated my row limit.
Now, I am deploying a Spring Boot application.
No DB props/credentials are found in my application.properties file since I am supposed to do this in Heroku Config Vars. For example, my DB username is janxgspmlpjgbn
Project builds successfully, however, in the logs I see that it has this exception.
2016-09-28 16:12:31.184 [ERROR] org.apache.juli.logging.DirectJDKLog.log:181 - Unable to create initial connections of pool.
2016-09-28T16:12:31.185772+00:00 app[web.1]: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "u24453"
Question
Why does it fail for the user u24453 (by the way this user changes every time I redeploy) when in my Config Var, I typed the user janxgspmlpjgbn?
Edit
Here's how my Config Vars look right now:

u24453 is probably the OS user name (the one Heroku creates for your app as it runs on Ubuntu Linux).
I believe the Postgres Driver will use the OS username as your DB username by default (if a username is not provided). Thus, I suspect the DB username is not getting into the configuration properly.
In your application.yml you should have this:
spring:
datasource:
url: ${JDBC_DATABASE_URL}
username: ${JDBC_DATABASE_USERNAME}
password: ${JDBC_DATABASE_PASSWORD}
For more info see Connecting to Relational Databases on Heroku with Java

Related

AWS secret manager Password Rotation Without Restarting Spring boot application

Requirement
Remove DB credentials from Java Code(property files) to AWS SM.
Implement autorotation of DB credentials.
Problem Statement
Though we are able to retrieve DB credentials from AWS SM from our application, but we are facing below issues during auto rotation of passwords:
How Java Code will identify that DB passwords are rotated by AWS SM
All the instances of application should be updated with new DB credentials after automatic password rotation from AWS SM.
Proposed Solution
Solution 1
Whenever passwords are rotated, java application won’t be able to
connect to DB.
At that time, we will get SQL Connection exception (Connection lost
exception) in our application.
Java Application will catch the exception & then add a mechanism to
retrieve the DB secrets again from AWS SM.
Set up new Db connection with the updated credentials.
Step 3 & 4 would be done for all the instances of the application
Solution 2
We can call refresh method and will set up new DB connection
automatically & avoid SQL Connection exception .
Is there any way without any db connection issues? we can rotate db password using aws SM
Yes, there is an AWS Secrets Manager JDBC Library which is basically a wrapper to common JDBC drivers with support to AWS Secrets.
This wrapper tries to connect to the database. If an authentication exception is caught, it will refresh the secrets to provide a valid connection.
Here are the two steps to configure your spring boot application.
1 - Add the dependency to your pom.xml
<dependency>
<groupId>com.amazonaws.secretsmanager</groupId>
<artifactId>aws-secretsmanager-jdbc</artifactId>
<version>1.0.7</version>
</dependency>
2 - Setup the database connection on your application.yaml
spring:
datasource:
url: jdbc-secretsmanager:mysql://database-host:3306/rotate_db
username: secret/rotation
driver-class-name: com.amazonaws.secretsmanager.sql.AWSSecretsManagerMySQLDriver
The username is actually the secret name created at AWS Secrets.
Make sure to use the right URL, in this example it is a URL for MySQL.

Connection keycloak with MySQL

I was try to doing different connections with keycloak and MySQL, and always i get the next error:
Operation ("add") failed - address: ([("subsystem" => "microprofile-metrics-smallrye")]): java.lang.NullPointerException
I read differents articles about this problem but anyone don't give me a concrete answer, I try with mariadb and the problem is the same and once i used the integrate gui that have keycloack on the url: http://127.0.0.1:9990/ but nothing changed, the connection take some minutes and create some of tables but finished with the last error
In this post https://keycloak.discourse.group/t/wildfly-nullpointerexception/747, the user says that each time keycloak is deployed, it generates a new random password for the database.
Therefore, while the database password remained the same, keycloak always tried to use its own newly generated password to connect to the DB.
That person's solution was to set the DB password explicitly in the keycloak config file (values.yml).

Connect to remote H2 Database in intellj idea

I have an application running on a server and I'm using H2 database for that,
This my database URL:
jdbc:h2:./cafeDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=7080
And I want to connect to this database using Intellj idea's database tools, this is my configuration:
But when I try to connect, It keeps asking me the DB's username and password, and even when I put the correct information and submit it says:
The specified database user/password combination is rejected: [28000][28000] Wrong user name or password [28000-200]
Am I doing something wrong?

"Ping Connection Pool failed for MySQL. Communications link failure due to underlying exception" Glassfish 4

I followed this tutorial here:
Creating and configuring a MySQL DataSource in GlassFish Application Server
In step 10, The info I've provided as follow (assuming my database name is Jsf_demo):
DatabaseName: jsf_demo
Password: thehung1724 (this is my MySQL password)
URL: jdbc:mysql://localhost:3306/jsf_demo. Where jsf_demo is your database name.
Url: jdbc:mysql://localhost:3306/jsf_demo. Where jsf_demo is your database name.
ServerName: HUNG-PC (I saw in MySQL)
User: sa
After that, when I click Ping, i got error:
I already copied mysql-connector.jar file to lib folder.
Hope any suggestion to help me solve this problem.
Have you restarted your GlassFish, because it's required to get new changes applied.
FYI: here is a working tutorial regarding GlassFish connection pool, check that.
Edit: I suppose that few properties URL and URl can cause issue you are experiencing.

Connecting to a MSSQL server using LDAP on Ubuntu Linux

I'm trying to connect to a MS SQL Server, using a linux client. I've tried both SQuirreL and DBeaver, but having no luck in either case. I've tried a few different drivers.
The connection string I am given looks something like this:
jdbc:oracle:thin:#ldap://<server>:<port>/<database>,cn=OracleContext,dc=<specific_dc>,dc=<specifc_dc>,dc=<specific_dc>
This seems to be an invalid URL, and I've tried various combinations of things (like using jdbc:sqlserver:// ... protocol, etc. It doesn't seem to like the #ldap in the connection string, and I've replaced the commas with semicolons. But, I'm new to connecting to SQL Server, much less using LDAP.
Any thoughts/help?
Thanks!
For those who are using DBeaver the way to connect to the SQL Server Database with an AD user is using the jTDS driver.
I am using DBeaver 6.0 in Debian 9. The user is an AD user.
In order to connect to the SQL Server from Linux Debian using DBeaver
1.- Select SQL Server jTDS driver
2.- Enter the connection information
3.- Go to Driver Properties tab and add the domain, user, password
Just as a note, in some post I found that they needed to change the property USENTLMV2 to TRUE but it worked for me either by putting the USERTLNMV2 in true or false.
A problem that I found was that when I was trying to connect to the database using my user and password the next error was thrown:
This error was thrown because of my user was about to expire. I tried with another AD user and it could connect.
cts:
datasource:
url: jdbc:jtds:sqlserver://dbserver:1433;database=DB;domain=yourdomain.com;useNTLMv2=true
driver-class-name: net.sourceforge.jtds.jdbc.Driver
username: username
password: password
hikari:
connection-test-query: SELECT 1
maximumPoolSize: 2
minimumIdle: 1

Categories