I'm writing a small web application in Java and my idea is to use database users as application users. Oracle recommends this approach in this document in case you never heard of it. Basically, the user will authenticate with their database credentials and I will forward these credentials to the dbms for the actual athentication process.
My problem is that every time I need to open a connection for the user I will need their credentials. I have come up with two ideas, but neither seems fully okay to me:
- Store the jdbc connection object in the user session so I don't need to open a new one every time the user has to execute a query. This has its obvious downsides and here is a good discussion on the subject.
- Store the user credentials in the session. This way I could use connection pooling but storing a password in session is a security risk. Either way, this seems better than option 1, and I could encrypt the password to make the whole thing a bit "less insecure".
Are there other options I'm not thinking of? If not, which one of these seems the best?