Results 1 to 8 of 8

Thread: Confused about UserDetails

  1. #1
    Join Date
    Dec 2006
    Posts
    311

    Default Confused about UserDetails

    So I have the inMemory security working fine. Now I want to authenticate through users stored in the database. Am I correct in that I need to use the UserDetails interface?

    Is the basic idea that you query your dB based on the user name? If it exists do you return the User object?

    Any help to get me back on track is appreciated. Thanks!

  2. #2
    Join Date
    Jul 2006
    Posts
    8

    Default

    The easiest way to do it is to create your own User class and have it implement the UserDetails interface. Then your DAO implements UserDetailsService which requires you to implement the loadUserByUsername method. This method should return your User object.

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    You do need to implement a UserDetailsService to load users by username. You don't have to start from stratch however as the JdbcDaoImpl might be of use to you. You can simply inject in the query required for your schema. If you do want to create your own UserDetailsService however, you can either return the existing User object type, or create your own by implementing the UserDetails interface.
    http://www.acegisecurity.org/multipr...lsService.html
    http://www.acegisecurity.org/multipr...erDetails.html
    http://www.acegisecurity.org/multipr...ails/User.html

  4. #4
    Join Date
    Dec 2006
    Posts
    311

    Default

    Thanks,

    I found something on the forum that told me how to do it. Basically I set up the hibernate query to return my user object then passed the password to the Acegi user object that is returned by UserDetails loadUserByUsername which I assume verifies the login attemp. It seems to be working like a charm.

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Fantasic, glad you've got it working. Out of interest what was the thread you found to get up and running?

  6. #6

    Default

    I'd also be interested in knowing how to do this programmatically. I have this working in my login scenario through:

    protected final UserDetails retrieveUser(String username,
    UsernamePasswordAuthenticationToken authentication)
    throws AuthenticationException

    but i'd also like to be able to programmatically (in a different flow) add the UserDetails to the security context...

    EDIT: never mind, realized i need to implement AbstractAuthenticationToken...
    Last edited by danieljsanders; Feb 20th, 2007 at 08:18 PM.

  7. #7
    Join Date
    Dec 2006
    Posts
    311

    Default

    Quote Originally Posted by karldmoore View Post
    Fantasic, glad you've got it working. Out of interest what was the thread you found to get up and running?






    Actually it was one of your responses when you linked someone to:

    http://www.acegisecurity.org/multipr...bcDaoImpl.html


    So thanks again!

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by TerpInMD View Post
    Actually it was one of your responses when you linked someone to:
    http://www.acegisecurity.org/multipr...bcDaoImpl.html
    Not a problem..... again . Glad it was some use to someone!

Posting Permissions

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