@Test @DisplayName("user@example.comでユーザーを検索できる") public void loadUserByUsernameTest1() { AccountDetails accountDetails = (AccountDetails) accountDetailsService.loadUserByUsername("user@example.com"); Account account = accountDetails.getAccount(); assertNotNull(account); List<String> authorities = account.getAuthorities(); assertEquals(1, authorities.size()); assertAll( () -> assertEquals(Integer.valueOf(1), account.getId()), () -> assertEquals("user", account.getName()), () -> assertEquals("user@example.com", account.getEmail()), () -> assertTrue(passwordEncoder.matches("user", account.getPassword())), () -> assertTrue(accountDetails.isAccountNonExpired()), () -> assertTrue(accountDetails.isAccountNonLocked()), () -> assertTrue(accountDetails.isCredentialsNonExpired()), () -> assertTrue(accountDetails.isEnabled()) ); }
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Optional<Account> accountOptional = accountRepository.findByEmail(username); Account account = accountOptional.orElseThrow(() -> new UsernameNotFoundException("user not found")); AccountDetails accountDetails = new AccountDetails(account); return accountDetails; }
AccountDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Optional<Account> accountOptional = accountRepository.findByEmail(username); Account account = accountOptional.orElseThrow(() -> new UsernameNotFoundException("user not found")); AccountDetails accountDetails = new AccountDetails(account); return accountDetails; } }
AccountDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Optional<Account> accountOptional = accountRepository.findByEmail(username); Account account = accountOptional.orElseThrow(() -> new UsernameNotFoundException("user not found")); AccountDetails accountDetails = new AccountDetails(account); return accountDetails; } AccountDetailsService(AccountRepository accountRepository); }
AccountDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Optional<Account> accountOptional = accountRepository.findByEmail(username); Account account = accountOptional.orElseThrow(() -> new UsernameNotFoundException("user not found")); AccountDetails accountDetails = new AccountDetails(account); return accountDetails; } AccountDetailsService(AccountRepository accountRepository); @Override UserDetails loadUserByUsername(String username); }
AccountDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Optional<Account> accountOptional = accountRepository.findByEmail(username); Account account = accountOptional.orElseThrow(() -> new UsernameNotFoundException("user not found")); AccountDetails accountDetails = new AccountDetails(account); return accountDetails; } AccountDetailsService(AccountRepository accountRepository); @Override UserDetails loadUserByUsername(String username);  }