How to do it...

Instead of hardcoding the user details inside the security model, we will implement a service layer that will programmatically generate a username and password for the application:

  1. Let us create the UserService interface, as follows that will generate hardcoded data for the UserDetails:
public interface UserService { 
   
  public String getUserCredentials(String username); 
  public Set<String> getuserRoles(String username); 
} 
  1. Save this file in our org.secured.mvc.service since this is just an application-based native service.
  2. Then, implement the interface through UserServiceImpl as follows:
@Service("userService") public class UserServiceImpl implements UserService{ @Override public String getUserCredentials(String username) ...

Get Spring 5.0 Cookbook 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.