File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Bind User to session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Bind User to session " Watch "Bind User to session " New topic

Bind User to session

Dalibor Ninkovic

Joined: Oct 19, 2010
Posts: 2
I use form based authentication, and I want to bind User object to session. I don't know where I can create and set User as attribute if my form is directly passed to j_security_check? Should I use listener for that?

Are there any other sollutions for authentication? For example can I make my own form, pass it to my servlet, and make authentication somehow there? In that case should I change web.xml (login-config)?

David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Once the user has logged in, their username should be available on the request as getUserPrincipal
Dalibor Ninkovic

Joined: Oct 19, 2010
Posts: 2
this helps only with one part of my problem, but thanks anyway. I need only once, right after authentication, to create User object and bind it. I can't in every servlet write same code for binding User into session. Maybe something like this stackoverflow example
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I haven't followed that link, but as soon as you think "I will have to do this for every servlet" you should start coding a servlet filter.
I agree. Here's the link:
subject: Bind User to session
It's not a secret anymore!