-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Passing user settings with hibernate and struts
PostPosted: Thu Jul 03, 2008 4:26 pm 
Newbie

Joined: Wed Jun 18, 2008 2:10 pm
Posts: 2
I am currently redesigning a web application that requires user authentication and has column level security on reporting pages (user can or can't see certain columns of a table).

I have implemented a basic DAOFactory and am using an interceptor much like the one on http://www.hibernate.org/43.html

Lets say the follwing Action validates a user against the database and returns his/her "session" information (security settings, profile info, etc).
Code:
public class LoginAction extends Action
{
    @Override
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
    {
        UserDAO dao = new UserDAO();
        User u = dao.getUserById("402884af1a97a4ec011a97a511560001");
        request.setAttribute("user", u);
        return new ActionRedirect(mapping.findForward("success"));
    }
}


This problem that i'm having is this is only good for the forward page (in this case index.jsp. My question is, how do I make the user info "persist" across pages for the lifetime of the user (until he closes the webbrowser). I thought to set it in request.getSession() but then i would have to update that anytime a user made changes to their info and saved to the database (hibernate). Am I completely missing it? Is there another way?

Thanks for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 8:44 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, I think the typical approach is to put it in the HttpSession.

Just look at what the big players do, like Sun and IBM and Oracle - they put a token or identifier in your session, which is often linked to a cookie or a URL encoded id. Then, that id is used to grab any information about the user when it is needed.

To avoid session bloat, it's best to put just an identifier in the Session, and then pull out what data you need from the database or LDAP system when it's needed. That's what the big boys do. But then again, ease of development must be weighed against performance. If it's easier to stuff everything in the session and there won't be too big of a performance hit, then do it!

-Cameron McKenzie

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 4:30 pm 
Newbie

Joined: Wed Jun 18, 2008 2:10 pm
Posts: 2
Thanks for the reply!

I ended up just saving User (with only the attributes that i need on every page) in the HttpSession. If i need more for a certain page, I can then extend User to something more bloated...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 10:17 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Indeed!

And you know, there's nothing wrong with using the id of the User to hit the database for some extra information when you need it. That's what the big vendors do!

-Cameron McKenzie

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.