SR 3-10444088391 : [ADF12.1.3]ADF如何实现登陆界面上的“记住我”功能

Adding "remember me" functionality to Oracle ADF login

   

The following example based on Jdeveloper 11g R2 (11.1.2.3)

There are many ways to implement login page in Oracle ADF. One can create custom login logic or use build in security mechanism. This is covered in many blogs and also in official Oracle documentation and I am not going to touch it in this post.

  I do want to explain how to add a functionality for "remember me", so if user already logged in and checked "remember me" option, next time he logs into the application he will not be asked to enter the credentials again

I started by creating some login form with "remember" check box

Definition of the check box button

 

When I press the login button I check that the check box is checked and if it checked I save the credentials in the cookies

I created some other  dummy page that I expect to see if user logged in with Cookies

Here my adfc-config.xml file

"AfterLogin" page contains only text "some other page"

Now I want my cookies to be checked when user enters the login page ("LoginTest" page in my application)

I will do it with JavaScript that will check the cookies after the page is loaded

Note!!! I tried to do it with all other methods like "afterPhase" or by using "router" in the Task-Flow. It didn't work

When the page is loaded eventually I call "goToDashBoard" method in my backing bean

public void goToDashBoard(ClientEvent clientEvent) {
   checkCookies();
}

   

public String checkCookies() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, Object> cookies = externalContext.getRequestCookieMap();
    Cookie user= (Cookie)cookies.get("nam.user.cookie");
    Cookie pass= (Cookie)cookies.get("nam.pass.cookie");
    Cookie domain = (Cookie)cookies.get("nam.domain.cookie");
    if (user!=null &&

         pass!=null &&

         domain!=null &&  

         user.getValue()!=null &&

         pass.getValue()!=null &&

         domain.getValue()!=null)

      {
        this._username=user.getValue();
        this._password =  pass.getValue();
        this._domain = domain.getValue();
        NavigationHandler  nvHndlr = FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
        nvHndlr.handleNavigation(FacesContext.getCurrentInstance(), null, "AfterLogin");

     }

}

All I do here is reading the information from Cookies and if credentials are found to be stored in the Cookies I programmatically execute "AfterLogin" control case (see the print screen of adfc-config.xml)

   

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值