Results 1 to 5 of 5

Thread: About UserDetailsService Query database doubt

  1. #1
    Join Date
    May 2011
    Posts
    2

    Default About UserDetailsService Query database doubt

    org.springframework.security.core.userdetails.User DetailsService.loadUserByUsername

    Need to query the database when the log to generate UserDetails
    There is only one parameter username
    If the wrong username password correctly, then in order to generate UserDetails also to query about the database.
    This query is redundant, I do not understand why this design.
    UserDetails generated after authentication password is not better?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    And how would you check the password? You still need to do a query, next to that you might want to use the (faulty or null) UserDetails to do some audit logging. If you do not have this that would be impossible. If the username is wrong there would be no UserDetails and there would be nothing to check... Still you would need to execute a query anyway.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2011
    Posts
    2

    Default

    Authorities need to query to create UserDetails
    Collection<GrantedAuthority> also need to obtain a series of queries

    1. method : loadUserByUsername
    In this method, I can not get the input password
    why not provide the password parameter?

    2.
    If input the password is wrong, but input the username is correct ;(how to return empty authorities?)


    (my English grammar is poor, sorry)

  4. #4
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    Quote Originally Posted by relucent View Post
    1. method : loadUserByUsername
    In this method, I can not get the input password
    why not provide the password parameter?
    Please check this FAQ.
    Spring - by Pivotal
    twitter @tekul

  5. #5

    Post How to get Password/credentials

    If you really need Password you can extend AbstractUserDetailsAuthenticationProvider and implement retrieveUser method.

    Code:
    @Override
     protected UserDetails retrieveUser(String username,
                    UsernamePasswordAuthenticationToken authentication)
                    throws AuthenticationException {
    
          String password = authentication.getCredentials().toString();	  
     }

Posting Permissions

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