Results 1 to 1 of 1

Thread: Best practice for erase-credentials and custom User Details?

  1. #1
    Join Date
    Jul 2012
    Posts
    3

    Default Best practice for erase-credentials and custom User Details?

    I implemented what someone described on (stackoverflow):
    I am using my own implementation of the UserDetailsService interface to load a User object from the Database and place it as UserDetail into my SecurityContext. The User object is then a detached Hibernate object.

    When I want to access lazy load relations of the authenticated User I need to get it from the SecurityContext and attach it again to the Hibernate session by loading through its ID or merge.

    The problem is
    : Merging the User for initializing lazy-loaded items using just <authentication-manager alias="authenticationManager"> results in Hibernate updating the user password to null (as eraseCredentials() was called after login).

    What is the Best practice approach to deal with this problem? What would you do? Some alternatives are
    1. disable erasing password
    2. remove the user.setPassword(null); from eraseCredentials() in custom UserDetails
    3. change the User Entity to not contain the password (maybe use some Authentication Entity instead which contains the password and references the User)
    4. do not store the User in User Details but just some value to identify him
    5. use always some special JPQL query to retrieve lazy-loaded items or update the user
    Last edited by Ninca7; Sep 5th, 2012 at 04:41 AM.

Tags for this Thread

Posting Permissions

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