@Test
public void testAuthenticationSuccessful() 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\": \"AMBARI.ADMINISTRATOR\" }");
  
  replay(mockAuthPropsConfig, mockExternalServerClient);
  
  Authentication authentication = new TestingAuthenticationToken("principal", "credentials");
  Authentication authenticationResult = provider.authenticate(authentication);
  
  assertEquals("principal", authenticationResult.getName());
  assertEquals("credentials", authenticationResult.getCredentials());
  assertEquals(1, authenticationResult.getAuthorities().size());
  assertEquals(new SimpleGrantedAuthority("ROLE_USER"), authenticationResult.getAuthorities().iterator().next());
  
  verify(mockAuthPropsConfig, mockExternalServerClient);
}