• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to authenticate user after registration?

 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

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!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18100
51
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic