UserDetailsService approach

Another approach to fetch use and role information is using the UserDetailsService interface. It is an abstract way to fetch authentication and authorization details. It has one method—loadUserByUsername() that will return user details based on username. You can override it and write your own logic to retrieve the user details.

Spring provides a class called DaoAuthenticationProvider that basically uses the UserDetailsService implementation to fetch user details during the authentication process. The flexibility in this approach means we can define a custom method to fetch user details. We will define a method in the JPA repository for the User entity. The JPA is a standard way of interacting with a relational ...

Get Spring 5.0 Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.