ARTIFACTORY: How to overcome "org.postgresql.util.PSQLException: The hostname xxx.xxx.xxx.xxx could not be verified by hostnameverifier PgjdbcHostnameVerifier" exception while connecting the external PostgreSQL database to Artifactory?

AuthorFullName__c
Yuvarajan Johnpaul
articleNumber
000005219
FirstPublishedDate
2022-03-28T08:36:44Z
lastModifiedDate
2022-03-28

ARTIFACTORY: How to overcome "org.postgresql.util.PSQLException: The hostname xxx.xxx.xxx.xxx could not be verified by hostnameverifier PgjdbcHostnameVerifier" exception while connecting the external PostgreSQL database to Artifactory?

Why is this happening?

As a security practice, the latest releases of the PostgreSQL databases use TLS encryption by default. At times, if the database is being accessed via the IP addresses, having failed to verify the secure connection established between Artifactory and Database, the server returns the below error.

YYYY-MM-DDT10:43:31.115Z [jfrt ] [ERROR] [8019426551caae4f] [c.z.h.p.HikariPool:593] [ocalhost-startStop-2] - HikariCP Main - Exception during pool initialization.
[...]
org.postgresql.util.PSQLException: The hostname xxx.xxx.xxx.xxx could not be verified by hostnameverifier PgjdbcHostnameVerifier.
How this can be resolved?

- Obtain the certificate of the Database server to be a trusted Artifactory instance (add it to the Artifactory's JVM).

- Configure the DNS of the Database to the JDBC connection string in Artifactory.

url: "jdbc:postgresql://<DATABASE_URL>/<ARTIFACTORY_DATABASE_NAME>"
Exceptional cases:

Let's say the services are in a closed network due to which the database is not having a DNS to be configured, the TLS verification can be skipped by amending the following attributes to the Artifactory Database connection string.

url: "jdbc:postgresql://<DATABASE_URL>/<ARTIFACTORY_DATABASE_NAME>"?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory&sslmode=allow


The hostname verification would be disabled after amending these attributes and the database doesn't verify the trust against the server [Artifactory].

Please note, when TLS encryption is intended by the Database, it is advised to have a secure connection established against the server by configuring the DNS for the database connection as well as using the appropriate certificates in both the client and the server.