we need to use AD authentication when connecting to Azure SQL DB.
Usually the JDBC URL would look like:
jdbc:sqlserver://servername.database.windows.net:1433;database=dbname-sql-db-dev;encrypt=true;trustServerCertificate=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;authentication=ActiveDirectoryPassword;user=user@domain.com;password=password
How to do that with JMIX for all DBs, including the main DB.
and one more test I did:
using the same Java version, IDEA, implementations, gradle… works fine.
Only in JMIX it does not work.
Here is the sample code und below the build.gradle
package org.example;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
public class Main {
public static void main(String args) {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName(“servername.database.windows.net”); // Replace with your server name
ds.setDatabaseName(“dbname-db-dev”); // Replace with your database
ds.setUser(“user@domain.com”); // Replace with your user name
ds.setPassword(“password”); // Replace with your password
ds.setAuthentication(“ActiveDirectoryPassword”);
one more interesting information:
I added an entity for the additional datastore which needs the ActiveDirectoryPassword Authentification manually and also create a simple entity browser screen.
When I run the application, it works fine.
@krivopustov
Which means,
there is an issue or bug in the JMIX plugin for testing the additional datastore
and also for generating the model.
I assume you need to add libraries required for database connection in Jmix Studio. Go to Preferences > Languages & Frameworks > Jmix > Database Drivers settings page, select Microsoft SQL Server, add paths to the required jars to the Additional DB Drivers list.
I also tried that and added all libraries which I listed in the build.gradle…
but that did not help…
The studio plugin cannot authenticate using ActiveDirectoryPassword,
because ‘failed to load msal4j library…’
Like I wrote, a additional datastore can connect on runtime,
but in the studio it does not work.
Which means, I can also not create or update the main DB.
got one step further:
I added all the libs, but when opening the settings again,
no setting was kept.
So I run the IDEA with Adminstrator rights… now the added libraries got used.
But, I still get an error message when trying to test the connection:
Unable to connect to database. Cause:
java.util.concurrent.ExecutionException: java.lang.RuntimeException: com/nimbusds/jose/util/Base64URL. Check Data Store connection parameters.
got it…
just copied the .jar files into
C:\Users\username\AppData\Roaming\JetBrains\IdeaIC2022.3\plugins\cuba-studio\lib
but except the slf4j-api-1.7.28.jar because that one is collidating with another version already in use in IDEA.
one more information if someone is having similar issues:
After getting JMIX and Cuba app running fine with Azure SQL activedirectorypassword authentification,
I got the next issue:
We also need to authenticate the user against the Active Directory Ldap and for that I need to add
the AD Ldap server certificate to the truststore we are using.
But, if you go that way and then point to the truststore in the setenv.bat/sh (catalina_opts=…) you might
face the problem, that you can then authenticate against the AD Ldap, but the connection to the
Azure SQL does not work any more.
I tried hundreds of settings in the JDBC URL and also different ways to load the truststore…
nothing worked… I could only authenticate or I could use the Azure SQL, but not both in one app.
In the end I found a solution, which is pretty simple when you know it
I added all needed certifications into the cacerts file of the Java JDK/VM itself and took out the
settings from sentenv.bat.
Then it directly worked fine, login using AD security and using Azure SQL with ‘activedirectorypassword authentication’ in one app…