@Test
 public void testWindowsAuthenticationProvider() {
   assertTrue(_provider.isAllowGuestLogin());
   assertTrue(_provider.getAuthProvider() instanceof MockWindowsAuthProvider);
   assertEquals(PrincipalFormat.sid, _provider.getPrincipalFormat());
   assertEquals(PrincipalFormat.both, _provider.getRoleFormat());
 }
 @Test
 public void testGuestIsDisabled() {
   try {
     MockWindowsIdentity mockIdentity = new MockWindowsIdentity("Guest", new ArrayList<String>());
     _provider.setAllowGuestLogin(false);
     WindowsPrincipal principal = new WindowsPrincipal(mockIdentity);
     UsernamePasswordAuthenticationToken authentication =
         new UsernamePasswordAuthenticationToken(principal, "password");
     _provider.authenticate(authentication);
     fail("expected AuthenticationServiceException");
   } catch (AuthenticationServiceException e) {
     assertTrue(e.getCause() instanceof GuestLoginDisabledAuthenticationException);
   }
 }
  @Test
  public void testAuthenticateWithCustomGrantedAuthorityFactory() {
    _provider.setDefaultGrantedAuthority(null);
    _provider.setGrantedAuthorityFactory(new FqnGrantedAuthorityFactory(null, false));

    MockWindowsIdentity mockIdentity =
        new MockWindowsIdentity(WindowsAccountImpl.getCurrentUsername(), new ArrayList<String>());
    WindowsPrincipal principal = new WindowsPrincipal(mockIdentity);
    UsernamePasswordAuthenticationToken authentication =
        new UsernamePasswordAuthenticationToken(principal, "password");

    Authentication authenticated = _provider.authenticate(authentication);
    assertNotNull(authenticated);
    assertTrue(authenticated.isAuthenticated());
    Collection<? extends GrantedAuthority> authorities = authenticated.getAuthorities();
    Iterator<? extends GrantedAuthority> authoritiesIterator = authorities.iterator();
    assertEquals(2, authorities.size());
    assertEquals("Users", authoritiesIterator.next().getAuthority());
    assertEquals("Everyone", authoritiesIterator.next().getAuthority());
    assertTrue(authenticated.getPrincipal() instanceof WindowsPrincipal);
  }
 @Test
 public void testAuthenticate() {
   MockWindowsIdentity mockIdentity =
       new MockWindowsIdentity(WindowsAccountImpl.getCurrentUsername(), new ArrayList<String>());
   WindowsPrincipal principal = new WindowsPrincipal(mockIdentity);
   UsernamePasswordAuthenticationToken authentication =
       new UsernamePasswordAuthenticationToken(principal, "password");
   Authentication authenticated = _provider.authenticate(authentication);
   assertNotNull(authenticated);
   assertTrue(authenticated.isAuthenticated());
   Collection<? extends GrantedAuthority> authorities = authenticated.getAuthorities();
   Iterator<? extends GrantedAuthority> authoritiesIterator = authorities.iterator();
   assertEquals(3, authorities.size());
   assertEquals("ROLE_USER", authoritiesIterator.next().getAuthority());
   assertEquals("ROLE_USERS", authoritiesIterator.next().getAuthority());
   assertEquals("ROLE_EVERYONE", authoritiesIterator.next().getAuthority());
   assertTrue(authenticated.getPrincipal() instanceof WindowsPrincipal);
 }
 @Test
 public void testSupports() {
   assertFalse(_provider.supports(this.getClass()));
   assertTrue(_provider.supports(UsernamePasswordAuthenticationToken.class));
 }