File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes How to authenticate user after registration? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to authenticate user after registration?" Watch "How to authenticate user after registration?" New topic

How to authenticate user after registration?

Volodymyr Lysenko
Ranch Hand

Joined: Mar 29, 2012
Posts: 511


I have method that persists new user to database. In the same method(after user is persisted and transaction is committed) I call method:

And it gives exception:

I know that HttpServletResponse is reset due to authentication failure. Authentication fails and returns false!

Can anybody tell me how to authenticate user correctly just after registration?

Thank you!

True person is moral, false is right!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

Actually, I'm not quite sure how that method is supposed to work. To authenticate, you need credentials, and there appears that there's an assumption that the ServletResponse object contains those credentials somewhere.

Instead of using this method, try the HttpServletRequest.login() method, instead.

I am assuming that your Glassfish server is a version advanced enough to support Servlet 3.0, since if it isn't, none of the above will work.

As a practical exercise - and to support older servlet implementations - I recommend NOT doing an internal login after registration, but rather to redirect to a secured URL, which will trigger a login. Remember, the actual login form has no URL, so you need to set up a user page, which can be a simple "welcome new user" page.

The justification for doing things that way is that it tests whether the user's credentials are what he/she thinks they are, and does a memory reinforcement on them.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: How to authenticate user after registration?
jQuery in Action, 3rd edition