@Test
public void testGetUserDetailPrincipalWithLoginAlias() throws Exception {

  // Given
  UserDetails userDetails = new User("loginAlias", "password", Collections.<GrantedAuthority>emptyList());
  Authentication authentication = new TestingAuthenticationToken(userDetails, userDetails.getPassword());
  expect(servletRequestAttributes.getAttribute(eq("loginAlias"), eq(RequestAttributes.SCOPE_SESSION)))
    .andReturn("user").atLeastOnce();
  replayAll();
  Authentication ambariAuthentication = new AmbariAuthentication(authentication, DEFAULT_USER_ID);
  // When
  Object principal = ambariAuthentication.getPrincipal();
  // Then
  verify();
  UserDetails expectedUserDetails = new User("user", "password", Collections.<GrantedAuthority>emptyList()); // user detail with login alias resolved
  assertEquals(expectedUserDetails, principal);
}