wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes JPA and dynamic user authentication with the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA and dynamic user authentication with the database" Watch "JPA and dynamic user authentication with the database" New topic
Author

JPA and dynamic user authentication with the database

adam smith ii
Greenhorn

Joined: Feb 04, 2010
Posts: 20
Is it possible to use JPA and dynamic based user authentication with the database? I would like to capture the users credentials in a form and authenticate them with the database and have JPA use that connection. I am not interested in Realms, because it sound likes I would need to set up additional tables. If the user is an authorized database user, that is all that is required for the application. I don't want to expose a user-id and password in a "configuration" xml file.

Also, I have three database environments (with the same schema), and would like to be able to specify which database server to use at run time.

Concepts required to solve this problem, steps and an example would be appreciated.

Application is JSF 2.0 currently using container managed persistence via EclipseLink.
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
You can pass connection/JPA properties such as user/password when acquiring an EntityManagerFactory or an EntityManager.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Auditing_and_Security

and,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Auditing

For passing the server, you could pass a different database URL in the properties when acquiring an EntityManagerFactory.

Not that using a different database login per user can affect your connection pool usage, so you may not be able to pool connections, unless you use something like Oracle proxy authentication.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
adam smith ii
Greenhorn

Joined: Feb 04, 2010
Posts: 20
James,
I tried passing the data source in the properties map to the constructor for the EntityManager / EntityManagerFactory, and believe I achieved partial success for one entity. I believe I stumbled because the JPA split my single database table into two entities, presumably because of a two column key and I did not know how to address that issue. Data retrieval worked, but data update failed.

I will study the references you provided, many thanks.

In the mean time I cloned the project and replaced JPA with application controlled database connection and SQL statement coding.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA and dynamic user authentication with the database
 
Similar Threads
Retrieving submitted password
Database newbie question about logging in
Jdbc, j_security, and other issues
How to add a JPA project to Web Project?
web app authentication: users from oracle database.