@Test public void authenticate() { Instant now = Instant.now(); service.setClock(Clock.fixed(now, ZoneOffset.UTC)); assertFalse(service.authenticate("notexist", "pwd123").isPresent()); service.createViaEmail("myname", "foo@gmail.com", "pwd123", lc); AccountAuth auth = service.authenticate("myName", "pwd123").get(); assertEquals("myname", auth.getUsername()); assertTrue(AccountAccessToken.tryDecode(auth.getAccessToken(), accountSecret).isPresent()); assertTrue(Instant.ofEpochMilli(auth.getExpireTime()).isAfter(now.plus(Duration.ofDays(7)))); assertEquals(now.toEpochMilli(), auth.getGenerateTime()); assertFalse(service.authenticate("myname", "wrong pass").isPresent()); }
@Override public Optional<AccountAuth> authenticate(String username, String password) { return accountDao.findByUsername(username) .filter(account -> passwordEncoder.matches(password, account.getPasswordHash())) .map(this::createAccountAuth); }
AccountServiceImpl implements AccountService { @Override public Optional<AccountAuth> authenticate(String username, String password) { return accountDao.findByUsername(username) .filter(account -> passwordEncoder.matches(password, account.getPasswordHash())) .map(this::createAccountAuth); } }
AccountServiceImpl implements AccountService { @Override public Optional<AccountAuth> authenticate(String username, String password) { return accountDao.findByUsername(username) .filter(account -> passwordEncoder.matches(password, account.getPasswordHash())) .map(this::createAccountAuth); }  }
AccountServiceImpl implements AccountService { @Override public Optional<AccountAuth> authenticate(String username, String password) { return accountDao.findByUsername(username) .filter(account -> passwordEncoder.matches(password, account.getPasswordHash())) .map(this::createAccountAuth); }  @Override Account createViaEmail(String username, String email, String password, Locale locale); @Override Optional<Account> findMe(Authorization authorization); @Override Optional<AccountAuth> authenticate(String username, String password); @Override Optional<AccountAccessToken> strongVerifyAccessToken(String rawAccessToken); @Override AccountAuth extendsAccessToken(AccountAccessToken accessToken); @Override boolean isUsernameAvailable(String username); @Override boolean isEmailAvailable(String email); @Override void updateAuthorities(Authorization authorization, EnumSet<Authority> authorities); @Override boolean activate(String inputOnceToken); @Override void resendActivation(Authorization authorization, Locale locale); @Override void sendResetPassword(String username, String email, Locale locale); @Override Optional<AccountOnceToken> findValidResetPasswordToken(String inputOnceToken); @Override void updatePasswordWithOnceToken(String accountOnceToken, String password, Locale locale); @Override AccountAuth updateNewPassword(Authorization authorization,
      String oldPassword,
      String newPassword,
      Locale locale); @Override Optional<AccountAccessToken> tryDecodeAccessToken(String rawAccountAccessToken); @Override AccountStats loadAccountStats(String username); @Override Account loadAccount(String username); @Override String updateDescription(Authorization authorization, String description); @Override String loadEditableDescription(Authorization authorization); @Override void complaintEmail(List<String> emails); @Override void muteEmail(List<String> emails); @Override AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization); @Override Optional<Account> oauthDirectAuthorize(String inputOnceToken); }
AccountServiceImpl implements AccountService { @Override public Optional<AccountAuth> authenticate(String username, String password) { return accountDao.findByUsername(username) .filter(account -> passwordEncoder.matches(password, account.getPasswordHash())) .map(this::createAccountAuth); }  @Override Account createViaEmail(String username, String email, String password, Locale locale); @Override Optional<Account> findMe(Authorization authorization); @Override Optional<AccountAuth> authenticate(String username, String password); @Override Optional<AccountAccessToken> strongVerifyAccessToken(String rawAccessToken); @Override AccountAuth extendsAccessToken(AccountAccessToken accessToken); @Override boolean isUsernameAvailable(String username); @Override boolean isEmailAvailable(String email); @Override void updateAuthorities(Authorization authorization, EnumSet<Authority> authorities); @Override boolean activate(String inputOnceToken); @Override void resendActivation(Authorization authorization, Locale locale); @Override void sendResetPassword(String username, String email, Locale locale); @Override Optional<AccountOnceToken> findValidResetPasswordToken(String inputOnceToken); @Override void updatePasswordWithOnceToken(String accountOnceToken, String password, Locale locale); @Override AccountAuth updateNewPassword(Authorization authorization,
      String oldPassword,
      String newPassword,
      Locale locale); @Override Optional<AccountAccessToken> tryDecodeAccessToken(String rawAccountAccessToken); @Override AccountStats loadAccountStats(String username); @Override Account loadAccount(String username); @Override String updateDescription(Authorization authorization, String description); @Override String loadEditableDescription(Authorization authorization); @Override void complaintEmail(List<String> emails); @Override void muteEmail(List<String> emails); @Override AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization); @Override Optional<Account> oauthDirectAuthorize(String inputOnceToken);  }