class InMemoryUserDetailsService implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) {

        // Hard coding the users. All passwords must be encoded.
        final List<AppUser> users = Arrays.asList(
            new AppUser(1, "user", passwordEncoder.encode("user")),
            new AppUser(2, "expire", passwordEncoder.encode("expire"))
        );

        return users.stream()
            .filter(f -> f.getUsername().equals(username))
            .map(appUser ->
                // The "User" class is provided by Spring and represents a model class for user to be returned by UserDetailsService
                // And used by auth manager to verify and check user authentication.
                new User(appUser.getUsername(), appUser.getPassword(), AuthorityUtils.NO_AUTHORITIES)
            )
            .findFirst()
            .orElseThrow(() -> new UsernameNotFoundException("Username: " + username + " not found."));
    }

    @Autowired public  InMemoryUserDetailsService(BCryptPasswordEncoder passwordEncoder);

}