Bring the current user to the database level

I have a classic 3-tier build of web applications with MySQL and Tomcat.

I want to store the creator id of each database record for all tables in the creator_id column, or just register it somewhere. The current user is stored in the http session object. Change all requests and pass the creator id parameter is not acceptable.

Is it possible to solve the problem with triggers, change table commands, etc.? What's the best way to do this?

PS. Hacks are acceptable and welcome.

0


a source to share


2 answers


The database cannot know which site user is submitting the request, all it knows is the database user . And if it is a web application, it is probably the same database user all the time, no matter who logged into the website.



The short answer is no, you have to go with your "inappropriate" option if you don't want to create a database user for every site user and have the site open a database connection using those of the same "general" user. But that may end up causing more problems than it solves.

+2


a source


Based on what you say in your question, your Application Logical User ID is different from your Database Connection ID. IF this is the case, how can the database know what the logical application user ID is? if you don't pass it, there is no way to know who is doing what. You say that it is unacceptable to modify all requests to pass this. However, you only need to change the saved data where you want to write this "creator_id" value. You will also need to modify these tables. Hopefully you have a table containing all these users and you can FK into a new column in this table.



0


a source







All Articles