ArtaeumUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { String lowercaseUsername = username.toLowerCase(Locale.ENGLISH); return this.userRepository.findOneWithAuthoritiesByEmail(lowercaseUsername) .map(this::createSpringSecurityUser) .orElseGet(() -> this.userRepository.findOneWithAuthoritiesByLogin(lowercaseUsername) .map(this::createSpringSecurityUser) .orElseThrow(() -> new UsernameNotFoundException(String.format("User '%s' not found", lowercaseUsername)))); } ArtaeumUserDetailsService(UserRepository userRepository); @Override UserDetails loadUserByUsername(String username);  }
@Test public void whenLoadExistingUser() { UserRegister user = new UserRegister(); user.setEmail("test@email.com"); user.setLogin("testlogin"); user.setFirstName("First"); user.setLastName("Last"); user.setPassword("password"); user.setLangKey("en"); this.userService.register(user); User editUser = this.userService.getByLogin(user.getLogin()).get(); editUser.setActivated(true); this.userRepository.save(editUser); String userId = this.userService.getByLogin(user.getLogin()).get().getId(); assertEquals(this.artaeumUserDetailsService.loadUserByUsername("testlogin").getUsername(), userId); assertEquals(this.artaeumUserDetailsService.loadUserByUsername("test@email.com").getUsername(), userId); }