File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes How to use SQL database for J2EE web logins Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to use SQL database for J2EE web logins" Watch "How to use SQL database for J2EE web logins" New topic
Author

How to use SQL database for J2EE web logins

P.Jamieson
Greenhorn

Joined: Apr 30, 2003
Posts: 21
I want to be able to authenticate users based on a username and password in a SQL server database. Presently, I have setup users by using the realmtool from the J2EE server. I would rather use the database entries. Could you please tell me how to do this? Can it be done from the deployment tool?
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
In Security tab,choose Form Based authentication, instead of Basic authentication.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by surasak lee:
In Security tab,choose Form Based authentication, instead of Basic authentication.

I have not used the j2ee server ( reference implementation).
I had a question though. So it does allow me to specify the database as the repository against which it needs to authenticate with Form based authentication?
I mean can i switch between LDAP, Database and flat file as possible repositories for form based authentication?
P.Jamieson
Greenhorn

Joined: Apr 30, 2003
Posts: 21
If I set this for FORM-BASED authentication, what else do I need to do in order to authenticate to a SQL database? I need to authenticate to this database as I will be adding / deleting users (dynamic).
[ November 20, 2003: Message edited by: P.Jamieson ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Take a look at this article on form-based security in J2EE web applications. Basically, you need three things:
- a pair of HTML/JSP pages (login.jsp, login-error.jsp)
- a restricted part of the web application (so that the container will force the user to login)
- a security realm configured to use the database (vendor-specific)


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
P.Jamieson
Greenhorn

Joined: Apr 30, 2003
Posts: 21
Thanks, I have looked at this previously. The example that they use is for Tomcat users. I am using the J2EE web server (hence container). Looking at your points, could you please explain further how I can map a realm name to my database? Also do I have to edit any other files like they explain for Tomcat (i.e. server.xml)? I have already setup tables for users, user_roles and roles in my database.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
All I can say is read the J2EE tutorial. This page looked like the closest match for what you want to do. I haven't used the reference implementation in ages (and probably didn't specify any realms) so I'm really not able to help with specifics on that particular server.
P.Jamieson
Greenhorn

Joined: Apr 30, 2003
Posts: 21
Thanks for your reply. I have gone through the tutorial and it only the basics. The only part that I need is to know how to create my own realm that is configured to use a database.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
In that case, go through your particular application server's documentation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use SQL database for J2EE web logins