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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.