LocalResourceOwnerAuthenticator implements ResourceOwnerAuthenticator { @Override public AuthenticatedPrincipal authenticate(String username, String password) { ResourceOwner user = resourceOwnerRepository.findByUsername(username); if (user == null) { return null; } if (!user.checkPassword(password)) { return null; } return new AuthenticatedPrincipal(username); }  @Override AuthenticatedPrincipal authenticate(String username, String password);  }
@Test public void testAuthenticateBadUser() { AuthenticatedPrincipal principal = this.authenticator.authenticate("foo", PASSWORD); assertNull(principal); }
@Test public void testAuthenticateBadPassword() { AuthenticatedPrincipal principal = this.authenticator.authenticate(this.resourceOwner.getUsername(), "bad"); assertNull(principal); }
@Test public void testAuthenticate() { AuthenticatedPrincipal principal = this.authenticator.authenticate(this.resourceOwner.getUsername(), PASSWORD); assertNotNull(principal); assertEquals("Principal does not have expected name", this.resourceOwner.getUsername(), principal.getName()); }