Results 1 to 2 of 2

Thread: getting the id of a user who is logged in?

  1. #1
    Join Date
    Dec 2004
    Posts
    19

    Default getting the id of a user who is logged in?

    I was just wondering what the best way to go about doing this is?
    solutions as I see it

    1) once a user logs in, get the matching id (from a user table for example) and store it in the users session

    2) everytime a page loads, have a controller grab the current user's username from the UsernamePasswordAuthenticationToken in the Authentication object, and then retrieve the ID everytime needed (seems a little wasteful)

    comments? thoughts? help?

    Thank you.

    ..jay @ Pixelknowledge.com

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Your AuthenticationDao can return any UserDetails it likes, so if a domain-specific user object is needed, people generally return that and simply implement UserDetails. This subsequently becomes available via the ContextHolder, avoiding the need for relying classes to look it up again.

    If your concern is about performance of each web request causing the "re-authentication" via DaoAuthenticationProvider, this is addressed by the UserCache interface. The AuthenticationDao is only queried when the UserCache returns null. The basic UserCache implementation, EhCacheBasedUserCache, is suitable for most applications (it even supports eviction, so your services layer that accepts modifications to your user can fire a userCache.removeUserFromCache(UserDetails) and ensure the next web request contains the current details).

Similar Threads

  1. Problem with HibernateInterceptor
    By prane in forum Data
    Replies: 5
    Last Post: Oct 16th, 2007, 08:01 AM
  2. LDAPPasswordAuthenticationDao problem
    By benoit_m35 in forum Security
    Replies: 15
    Last Post: Jan 11th, 2006, 07:04 AM
  3. Replies: 3
    Last Post: Sep 22nd, 2005, 10:14 AM
  4. Replies: 1
    Last Post: Mar 22nd, 2005, 07:34 AM
  5. Refresh Roles for Logged In User?
    By sethladd in forum Security
    Replies: 5
    Last Post: Feb 18th, 2005, 02:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •