sfa-siard / SiardCmd

SIARD Suite - SiardCmd
Other
9 stars 5 forks source link

SiardFromDb on MySQL user with broad privileges results in NullPointerException #14

Open karenhanson opened 4 years ago

karenhanson commented 4 years ago

I was testing SiardFromDb with MySQL for a project and found that using a DB user that has been granted full privileges to all databases causes the process to exit with a NullPointerException. I figured out how to work around the problem, but thought I should document it as an issue.

Steps to recreate: I restored a single database on a new MySQL install. For expediency I created a user like this:

CREATE USER 'all'@'localhost' IDENTIFIED BY 'all';
GRANT ALL PRIVILEGES ON *.* to 'all'@'localhost';

I then ran the SiardFromDb command like this:

java -cp ./lib/siardcmd.jar ch.admin.bar.siard2.cmd.SiardFromDb -j=jdbc:mysql://localhost:3306/testdb -u=all -p=all -s=testdb.siard -o

The process printed the Meta Data section which showed a list of tables in "testdb" then it continued and listed the system tables as well e.g. "mysql"."db". At the end of the list it printed a NullPointerException and exited without completing. The error did not include a stack trace.

To work around the issue, I created a new user like this, limiting to just the one database:

CREATE USER 'testdb-only'@'localhost' IDENTIFIED BY 'testdb-only';
GRANT ALL PRIVILEGES ON testdb.* TO 'testdb-only'@'localhost';

I then ran a command like this:

java -cp ./lib/siardcmd.jar ch.admin.bar.siard2.cmd.SiardFromDb -j=jdbc:mysql://localhost:3306/testdb -u=testdb-only -p=testdb-only -s=testdb.siard -o

This completed the export without an error. While trying to figure out a work around, I also created a simple database with one table, and changed the JDBC URL to point to that database, but it still retrieved data from the first database. It seems like the database selection in the JDBC URL was being ignored and it was retrieving everything visible to the user rather than just the one database.

Hope I'm logging this in the correct project - I suspect the issue might be in one of the underlying projects. I was going to try to debug, but I don't have my machine configured for Ant. Happy to provide any additional context.

sdbuehlmann commented 10 months ago

Hi @karenhanson, thank you for your detailed and clear report. Apologies for the extended response time (over 3 years!). We will investigate and get back to you. Appreciate your patience.