Simple JSF Login page with Users in a DB table

For some reason one common request we see on OTN, especially from people who just start their JDev/ADF route from Oracle Forms background, is to create a login screen that uses a database table with username/password to validate users.

It might be that this is the way people managed users in their Forms application.

Now in reality this is not the way they'll probably end up doing authentication in their ADF application - after all ADF and Java EE has a complete security framework for this.
But never the less many people want to try it that way.

So I quickly created a simple sample using basic JSF page flow a login page and a login button on it that just uses JDBC to query for the existence of a username in the employees table.
You can download the sample from here
zipped workspace
Check out the GetUser.java file for the code I use and modify your DB connection and query as needed and then run the getUser.jspx file.

Enjoy.

Comments:

Hi Shay; How to mange our huge users if not using DBTable? I want using ADF Security without DBTable but how can i mange my application users like Show all, create, edit, delete, change privligis etc at application runtime? i use DB to esay do buti dont know how to do that using ADF Security only withoutDB) at runtime? please help Big Thank to you

Posted by Jdeveloper on November 16, 2008 at 06:49 PM PST #

Hi shay, You said "especially from people who just start their JDev/ADF route from Oracle Forms background, is to create a login screen that uses a database table with username/password to validate users" I am also a forms person, but what is the ADF way of user varification and role checking..Thanks, L

Posted by Lalitha Ketineni on December 12, 2008 at 05:02 AM PST #

ADF has a complete security framework which relies on Java EE authentication. Frank does a good job showing how it works in his code corner in a set of online demos: http://www.oracle.com/technology/products/jdev/tips/fnimphius/index.html

Posted by Shay on December 12, 2008 at 05:10 AM PST #

Hello Shay ! I am new to ADF and have been struggling for making a login application for a while. In my application there is also a model project so I assume I had better query the database in an application module under the Model projet rather than from the backing bean. Do you have a demo where you perform it. I could not figure out how to call the aplication module method from the backing bean and make the necessary bindings. Thanks in advance.

Posted by Gorkem Turan on August 18, 2009 at 05:36 PM PDT #

Hay, Shay thanks for replying about login screen in jsf-adf.I already done this in my backing-bean. How i record the users logout time in db. Plz help me. Is there a way in jsf or in elsewhere. Thanks once again

Posted by Rashid -user12217029 on December 13, 2009 at 01:55 PM PST #

Rashid, You can just add another method to your backing bean that does an insert or an update to a table with the current time - and call this method from a logout button on your page - just like you called the login action.

Posted by shay on December 14, 2009 at 01:53 AM PST #

private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) { String alert = "Are you sure you want to exit, karasama ?"; String title = "Program exit"; int ans = JOptionPane.showConfirmDialog(this, alert, title, JOptionPane.YES_NO_OPTION); if (ans == JOptionPane.YES_OPTION) { System.exit(0); } // TODO add your handling code here: } private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) { login(); } private void login() { // Put your logic here String login = txtUser.getText(); String password = new String(txtPassword.getPassword()); if (login.equals("test")&&password.equals("test")) { setVisible(false); } else { String alert = "Invalid login"; String title = "Access authentication"; JOptionPane.showMessageDialog(this, alert, title, JOptionPane.ERROR_MESSAGE); } } private void txtPasswordActionPerformed(java.awt.event.ActionEvent evt) { btnLogin.requestFocus(); } private void txtUserActionPerformed(java.awt.event.ActionEvent evt) { txtPassword.requestFocus(); }

Posted by sama on February 23, 2010 at 12:47 AM PST #

Please give me the detail regarding EJB3.0 & JPA login form field , How to validate by backed data base & front end javaScript using jdeveloper 11 g

Posted by javed on October 04, 2010 at 10:44 PM PDT #

Javed, I'm not sure what you are looking for - as I pointed out this is not the right way to do security for an application - you should use the built in ADF security features. You can probably just replace my JDBC call with a call to a JPA named query that does a query against a table in the database.

Posted by shay.shmeltzer on October 05, 2010 at 02:05 AM PDT #

thanks for the wonderful example shay. I am new to ADF and was trying for some time to create the login page

Posted by guest on January 26, 2011 at 05:15 PM PST #

hii Shay..thx four your post & preview. that's very useful for me i'm newbie and jdev, and i'wanna implement security in adf (my project) with username and password management, my question is how to make roles for user (integrated roles + user/pass from db)? thx regards agungdmt

Posted by agungdmt on June 05, 2011 at 04:54 PM PDT #

Agungdmt, OPSS - which ADF Security relies on - has support for DB-Based security store. see: http://www.art2dec.com/documentation/docs/fmw11g1114documentation/core.1111/e10043/cfgauthr.htm#CHDHAIBJ

Posted by Shay on June 06, 2011 at 02:56 AM PDT #

Hi Shay,
I am building an online inventory system and i want to know how to integrate email and sms service in ADF for reporting.
And about ur ADF Security, in my project there will be different users with different privilege levels. So can i use ADF Security in this application and i was thinking to do this job by fetching data from database? I need some hints and help.

Thanks

Posted by SudeepShakya on October 19, 2011 at 12:05 AM PDT #

SudeepShakya
For SMS you can find Webservices that provide this functionality on xmethods.net and call them from ADF, for Email you can write code with the JavaMail API and call that from ADF.
And yes ADF security supports users and roles and you should be using it to secure your application.

Posted by guest on October 19, 2011 at 07:16 AM PDT #

Thanks a lot.

Posted by SudeepShakya on October 19, 2011 at 03:42 PM PDT #

I tried a sample application of ADF Security available on Cue cards and i got some idea about it. And i want to ask something that is, how to add and modify user accounts from within the application(or fusion web applcation) and save the account details in database, other than from the jDeveloper.

Posted by SudeepShakya on October 20, 2011 at 03:58 AM PDT #

ADF delegates the user maintenance to the WebLogic security layer (OPSS).
If you want to use users kept in a database repository then WLS security has a database adaptor that does this.
You can then just build an ADF UI that works with those tables that contain the user/roles.
Otherwise you can use the APIs provided by WebLogic security to create users.
You can read more about OPSS here:
http://download.oracle.com/docs/cd/E21764_01/core.1111/e10043/underjps.htm#CIHFHJCC

Posted by shay on October 20, 2011 at 05:00 AM PDT #

Hi Shay, I am new to ADF env as well as Oracle forms. But I am assigned a job on evaluating our Company's existing application in Oracle forms 11 to Web based application. For that I am trying out different technologies. And now I came to Oracle ADF.
Please suggest me which is the best technology of migration from Oracle forms to Web based application.
If your answer is Oracle ADF, then my next set of questions wud be on how to develop simple appln in oracle ADF with databse conn.
Awaiting for ur reply.. thanks !

Posted by Aparna on November 30, 2011 at 05:04 PM PST #

Aparna, the easiest way to migrate your Oracle Forms application to the Web is
to use the latest version of Oracle Forms 11g - which is Web enabled.

If you are looking to migrate from Oracle Forms to another technology then we
believe that ADF is the right way to go and it will give you the best
productivity on a standard based environment.
See this seminar for more details:
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/Forms_Redevelopmen
t_ADF/Forms_Redevelopment_ADF.html
A basic ADF tutorial that shows an application connected to a database is here:

http://download.oracle.com/docs/cd/E18941_01/tutorials/jdtut_11r2_55/jdtut_11r2_
55_1.html

Posted by Shay on December 01, 2011 at 03:04 AM PST #

Hi Shay,
I want to go to a new window for the "home page" without browser back button etc. after login validation.
And also close the login window at the same time.
Here is the code I used after the login validation.

ExtendedRenderKitService erks =Service.getRenderKitService(FacesContext.getCurrentInstance(),ExtendedRenderKitService.class);
StringBuilder script = new StringBuilder();
script.append(" params = 'width='+screen.availWidth-10;\n" +
" params += ', height='+screen.availHeight-50;\n" +
" params += ', top=0, left=0'\n" +
" params += ', fullscreen=yes';\n" +
" params += ', scrollbars=1';\n" +
" params += ', resizable=1';\n" +
" params += ', status=1';\n" +
"window.close();\n" +
" newwin=window.open('home.jspx','xxxxxxxxx', params);\n" +
" if (window.focus) {newwin.focus()}");
erks.addScript(FacesContext.getCurrentInstance(), script.toString());

This successfully opens a new window. I want to close the current login window at the same time.
Please help me with this.

Regards !
Sameera

Posted by guest on May 11, 2012 at 05:00 AM PDT #

Sameera, Since you chose to use Javascript to do your navigation you'll probably need to find a Javascript that can close the current window, although I'm not sure this is allowed because of security concerns.
Maybe a better approach is to use JSF navigation from your login page to the next page - this will have the next page replace your login page.

Posted by shay on May 11, 2012 at 11:27 AM PDT #

Thanks for sharing this

Posted by Shaheer Badar on August 09, 2012 at 11:38 PM PDT #

I am creating a Login page. My user's username and password is in database table. I want to use the existing database connection I made during making ADF-BC .??
When we make database connection during ADF-BC, I want to use that connection in my doLogiin() method. How can i do that??

Posted by ankit on September 28, 2012 at 11:50 AM PDT #

Ankit, I'm not sure what you are trying to do makes sense. After all I'm guessing that your aim is to only allow to connect to your AM if the user/pass is correct.
In any case, if you want to reuse the connection that an ADF BC creates to the DB during a JSF application your can do this:
http://docs.oracle.com/cd/E16162_01/web.1112/e16182/bcadvgen.htm#BABEIFAI
However, if your AM has a method that checks that the login is valid, then just expose it as a service method and use it on your login page.
Something like: https://blogs.oracle.com/shay/entry/am_service_method_-_simple_dem

Posted by Shay on September 28, 2012 at 03:48 PM PDT #

my best regards to shay
my jdev r2

could you help to build custom login page that connected in database table that checks username and password
any demo or video or sample project that is will appreciated

Posted by haider on December 18, 2013 at 02:32 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

me
I'm a Director of Product Management for the Oracle Java Development Tools.
Follow me:
Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today