X

Shay Shmeltzer's Oracle Development Tools Tips

  • November 6, 2008

Simple JSF Login page with Users in a DB table

Shay Shmeltzer
Director of Product Management - Oracle

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.

 

Join the discussion

Comments ( 28 )
  • Jdeveloper Monday, November 17, 2008
    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
  • Lalitha Ketineni Friday, December 12, 2008
    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
  • Shay Friday, December 12, 2008
    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
  • Gorkem Turan Wednesday, August 19, 2009
    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.
  • Rashid -user12217029 Sunday, December 13, 2009
    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
  • shay Monday, December 14, 2009
    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.
  • sama Tuesday, February 23, 2010
    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();
    }
  • javed Tuesday, October 5, 2010
    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
  • shay.shmeltzer Tuesday, October 5, 2010
    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.
  • guest Thursday, January 27, 2011
    thanks for the wonderful example shay.
    I am new to ADF and was trying for some time to create the login page
  • agungdmt Sunday, June 5, 2011
    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
  • Shay Monday, June 6, 2011
    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
  • SudeepShakya Wednesday, October 19, 2011

    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


  • guest Wednesday, October 19, 2011

    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.


  • SudeepShakya Wednesday, October 19, 2011

    Thanks a lot.


  • SudeepShakya Thursday, October 20, 2011

    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.


  • shay Thursday, October 20, 2011

    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


  • Aparna Thursday, December 1, 2011

    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 !


  • Shay Thursday, December 1, 2011

    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


  • guest Friday, May 11, 2012

    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


  • shay Friday, May 11, 2012

    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.


  • Shaheer Badar Friday, August 10, 2012

    Thanks for sharing this


  • ankit Friday, September 28, 2012

    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??


  • Shay Friday, September 28, 2012

    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


  • haider Wednesday, December 18, 2013

    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


  • guest Thursday, December 8, 2016

    Than you so much for the beautiful illustration.

    It was very clear and simple.

    don't get me wrong, I am saying applying those tasks were simple, I am referring to how you managed to make it appear doable and in a very easy way.

    I do have a question though?

    Can I immediately design another loginform without calling any packages that help in terms of connecting with my Oracle database or establishing a connection is sufficient?

    I hope my question is clear sir.

    please send me a reply back when you can.

    Again, Thank you so much for the useful lesson.


  • khaled Wednesday, June 14, 2017
    Thanks Shay I have learned from you a lot in MAF,
    I wish you make such an example in it from DB through rest connection.
    BTW the link is not running any more.
  • Shay Wednesday, June 14, 2017
    Khaled, thanks for letting me know about the broken link.
    The file can now be found here:
    https://drive.google.com/open?id=0B8y-pxAka2jdTnZ4bUhlODJDckU
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.