@Test
public void testAuthenticate() throws Exception {

  assertNull("User alread exists in DB", userDAO.findLdapUserByName("allowedUser"));
  users.createUser("allowedUser", "password", UserType.LDAP, true, false);
  UserEntity ldapUser = userDAO.findLdapUserByName("allowedUser");
  Authentication authentication = new UsernamePasswordAuthenticationToken("allowedUser", "password");
  AmbariAuthentication result = (AmbariAuthentication) authenticationProvider.authenticate(authentication);
  assertTrue(result.isAuthenticated());
  assertEquals(ldapUser.getUserId(), result.getUserId());
  result = (AmbariAuthentication) authenticationProvider.authenticate(authentication);
  assertTrue(result.isAuthenticated());
  assertEquals(ldapUser.getUserId(), result.getUserId());
}