Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7693873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:11:23+00:00 2026-05-31T21:11:23+00:00

I use jsf2.0 and java ee6 on a JBoss AS 7 i have a

  • 0

I use jsf2.0 and java ee6 on a JBoss AS 7

i have a LoginController.java looking like this:

@ManagedBean(name = "loginController")
@SessionScoped
public class LoginController implements Serializable{

    private static final long serialVersionUID = 1119172305268193508L;

    @Inject
    private UserProvider userProvider;

    @PostConstruct
    public void initNewUser() {
        user = new User();
    }

    private User user;

    private String accountName;

    private String password;

    public String ownLogin() throws Exception {

        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance()
                .getExternalContext().getRequest();


        if (accountName != null) {
            try {


                if (exists(accountName)) {

                    user = userProvider.findUserByAccountName(accountName);

                    if (verifyPassword(user, password)) {

                        userProvider.saveChangedUser(user);


                        // OWASP SAYS: after login, destroy the session make a new one 
                        // a so called handover
                        // Destroy the session
                        FacesContext facesContext = FacesContext.getCurrentInstance();

                        HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
                        if(session != null){
                            session.invalidate();
                        }
                        // create new session after logout
                        session = (HttpSession) facesContext.getExternalContext().getSession(true);
                    setLogin(true);
            }                   
    }

/* some getters and setters */

}

The OWASP says, for security reason that after a login the sessions should be deleted (see: V3.7)

i do this in my code at this point:

FacesContext facesContext = FacesContext.getCurrentInstance();

                            HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
                            if(session != null){
                                session.invalidate();
                            }
                            // create new session after logout
                            session = (HttpSession) facesContext.getExternalContext().getSession(true);

First, I delete the old session, then I make a new session.
After this, I set the login true…

Of course, after running through the whole code, the user is not logged in, because the LoginController was managed in the old session scope – and in the new session scope there is a new LoginController in the scope without the loged in user…

Is there any way, to add a new LoginController to the new session after creation?

Or what is the common way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:11:24+00:00Added an answer on May 31, 2026 at 9:11 pm

    When you invalidate the session, all of its attributes will be trashed by end of response. You’re however setting the login status on a session scoped bean instance which lives in the old session only.

    You basically need to manually recreate the session scoped bean and put it in the new session after the invalidate.

    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    externalContext.invalidateSession();
    LoginController loginController = new LoginController();
    loginController.setUser(user);
    externalContext.getSessionMap().put("loginController", loginController);
    

    (look ma, no ugly javax.servlet imports anymore!)

    By the way, when you go this way, you could also just make your LoginController a view scoped bean and deal with User in the session only.

    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    externalContext.invalidateSession();
    externalContext.getSessionMap().put("user", user);
    

    (it’ll be available by #{user} throughout the EL context, also in managed properties; it does not necessarily need to be a JSF managed bean)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java EE 6 application in which I'd like to use velocity
I have a client who wants to use JSF2 and they like that XHTML
I have a pretty complex JSF page (we use JSF2 with facelet) in which
I am new to CDI and want to use this for a JSF2 application.
I have a strange effect on my JSF2/richfaces 4 project. I use a viewscoped
Is it possible to use tiles in JSF2.0? I am planning for migration of
use this website a lot but first time posting. My program creates a number
use Rack::Static, :urls => ['/stylesheets', '/images'], :root => 'public' run proc { |env| [200,
I'm trying to use RichFaces on a working JSF2 application. I incorporated the RichFaces
I am new to Java Web Application. I am practicing with JSF2. Is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.