开发者

jsf auto-login according to cookie

开发者 https://www.devze.com 2023-03-11 03:29 出处:网络
I\'m having a problem in achieving an auto-login feature for my JSF application which is being proted from a JSP & servlet-based architecture.

I'm having a problem in achieving an auto-login feature for my JSF application which is being proted from a JSP & servlet-based architecture.

I used LoginBean backing the jsf pa开发者_Go百科ge with a constructor method to check if the cookie containing the user crendtials exists, and if it does to automatically open a session and redirect the user to the main page.

The auto-login never takes place and the user always remains in front of the login form. What should I do to make it work?


Here is an option that should work. You can do something like this once you've ascertained that they are valid:

final ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();

try {
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();

    if (!response.isCommitted()) {
        externalContext.redirect("loggedin.xhtml");
    }
} catch (IOException ex) {
    // log etc.
}
0

精彩评论

暂无评论...
验证码 换一张
取 消