@Test
public void testAuthenticationUnsuccessful() throws Exception {

  expect(mockAuthPropsConfig.isAuthExternalEnabled()).andReturn(true);
  expect(mockAuthPropsConfig.getExternalAuthLoginUrl()).andReturn("http://server.com?userName=$USERNAME");
  expect(mockExternalServerClient.sendGETRequest("http://server.com?userName=principal", String.class, "principal", "credentials"))
  .andReturn("{\"permission_name\": \"NOT.AMBARI.ADMINISTRATOR\" }");
  
  replay(mockAuthPropsConfig, mockExternalServerClient);
  
  Authentication authentication = new TestingAuthenticationToken("principal", "credentials");
  try {
    provider.authenticate(authentication);
    assertTrue("Should have thrown BadCredentialsException", false);
  } catch (BadCredentialsException e) {
    assertEquals("Bad credentials", e.getMessage());
  }
  
  verify(mockAuthPropsConfig, mockExternalServerClient);
}