Search code examples
javaspringspring-bootoauthuserdetailsservice

How to correctly implement the UserDetailsService without having an username?


I am creating an oauth service in spring-boot and want to use user information from a MariaDB for authentication. When implementing UserDetailsService I have to override the function loadUserByUsername. The problem is that my user model does not have a field username, instead of this I want to load the users using their mail address. So my question: How do I correctly implement the UserDetailsService without having an username?


Solution

  • Then the mail address is the user name.

    It is just a text value that uniquely identify the user with the domain. It can be a:

    • login name (domain: application)
    • email address (domain: global)
    • SSN (domain: US resident)
    • student id (domain: school)
    • employees id (domain: company)
    • gamer id (domain: game site)
    • or whatever you want it to be

    as long as it is unique, so that loadUserByUsername can find exactly one record.