class AuthenticationServiceImpl implements AuthenticationService {

  @Override
  public String authenticate(String username, String password) {
    User user = userRepository.findByUsernameAndPassword(username, password);

    if (user == null) {
      throw new UnauthorizedAccessException("No user matches username " + username + " and password");
    }

    return tokenStore.generate(username);
  }

    AuthenticationServiceImpl(
      TokenStore tokenStore,
      UserRepository userRepository);

}